Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java	(revision 30049)
@@ -871,8 +871,16 @@
 		Element query_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
 		GSXML.addParametersToList(query_param_list, service_params);
+		GSXML.addParameterToList(query_param_list, "hldocOID", (String) params.get(GSParams.DOCUMENT));
 		mr_query_request.appendChild(query_param_list);
 
 		// do the query
 		Element mr_query_response = (Element) this.mr.process(mr_query_message);
+				
+		String pathNode = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.NODE_CONTENT_ELEM);
+		Element highlighted_Node = (Element) GSXML.getNodeByPath(mr_query_response, pathNode);
+		if (highlighted_Node != null)
+		{
+			return highlighted_Node;
+		}
 
 		String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.TERM_ELEM + GSXML.LIST_MODIFIER);
@@ -1210,5 +1218,4 @@
 			content_element.appendChild(doc.createTextNode(remaining_text));
 		}
-
 		return content_element;
 	}
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 30049)
@@ -157,4 +157,5 @@
 		Element query_response = (Element) GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
 		Element query_result_metadata_list = (Element) GSXML.getChildByTagName(query_response, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
+		
 		if (query_result_metadata_list == null)
 		{
@@ -260,4 +261,6 @@
 		Element mr_metadata_response = (Element) this.mr.process(mr_metadata_message);
 
+		Element query_result_snippet_list = (Element) GSXML.getChildByTagName(query_response, GSXML.HL_SNIPPET_ELEM + GSXML.LIST_MODIFIER);
+		
 		// check for errors
 		processErrorElements(mr_metadata_response, page_response);
@@ -266,10 +269,11 @@
 
 		Element query_result_document_list = (Element) GSXML.getChildByTagName(metadata_response, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
-
+				
 		if (query_result_document_list != null)
 		{
 			page_response.appendChild(doc.importNode(query_result_document_list, true));
-		}
-
+			page_response.appendChild(doc.importNode(query_result_snippet_list,true));
+		}
+		
 		//logger.debug("Query page:\n" + this.converter.getPrettyString(page_response));
 		//append site metadata
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 30049)
@@ -22,4 +22,6 @@
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
@@ -27,5 +29,4 @@
 import org.greenstone.gsdl3.util.GSXML;
 import org.greenstone.gsdl3.util.XMLConverter;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -92,4 +93,8 @@
 	protected boolean advanced_form_search = false;
 	protected boolean raw_search = false;
+	//Parameters to get full field with highlighted terms
+	protected String hldocOID = null;
+	//index Field for highlighting
+	protected String indexField = null;
 
 	static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.AbstractGS2FieldSearch.class.getName());
@@ -591,4 +596,5 @@
 	protected Element processAnyQuery(Element request, int query_type)
 	{
+				
 		String service_name = null;
 		String empty_query_test_param = null;
@@ -633,6 +639,9 @@
 
 		// Process the request parameters
+		
 		HashMap<String, Serializable> params = GSXML.extractParams(param_list, false);
-
+		//Save as variable to make it accessable from GS2SolrSearch
+		hldocOID = (String) params.get("hldocOID");
+		//System.out.println("@@@@@Extracted hldocOID is " + hldocOID);
 		// Make sure a query has been specified
 		String query = (String) params.get(empty_query_test_param);
@@ -644,9 +653,11 @@
 		// If a field hasn't been specified, use the default - for textQuery
 		String field = (String) params.get(INDEX_PARAM);
+		//Save as variable to make it accessable from GS2SolrSearch
+		
 		if (field == null)
 		{
 			field = default_index;
 		}
-
+		indexField = field;
 		// set up the appropriate query system
 		if (!setUpQueryer(params))
@@ -668,8 +679,18 @@
 			break;
 		}
-
+		
 		// run the query
 		Object query_result = runQuery(query);
-
+		
+		// We want highlighted text to be returned right now!
+		if (hldocOID != null && does_full_field_highlighting)
+		{
+			Element nodeContentElement = result_doc.createElement(GSXML.NODE_CONTENT_ELEM);
+			nodeContentElement.setTextContent((String) query_result);
+			result.appendChild(nodeContentElement);
+			return result;
+		}
+		
+			
 		// build up the response
 
@@ -704,5 +725,10 @@
 		}
 		
-
+		Map<String, Map<String, List<String>>> hlResults = null;
+		if (does_highlight_snippets)
+		{
+			hlResults = getHighlightSnippets(query_result);
+		}
+		
 		// add a metadata item to specify what actual query was done - eg if stuff was stripped out etc. and then we can use the query later, cos we don't know which parameter was the query
 		GSXML.addMetadata(metadata_list, "query", query);
@@ -711,8 +737,28 @@
 			Element document_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
 			result.appendChild(document_list);
+			Element snippet_list = result_doc.createElement(GSXML.HL_SNIPPET_ELEM + GSXML.LIST_MODIFIER);
+			result.appendChild(snippet_list);
 			for (int d = 0; d < docs.length; d++)
 			{
 				String doc_id = internalNum2OID(docs[d]);
 				Element doc_node = createDocNode(result_doc, doc_id, doc_ranks[d]);
+				if (hlResults != null && hlResults.get(docs[d]) != null && hlResults.get(docs[d]).get(indexField) != null) {
+					for (String snippet : hlResults.get(docs[d]).get(indexField)){
+						//remove html tags
+						snippet = snippet.replaceAll("\\<.*?>", "");
+						//remove truncated tags
+						snippet = snippet.replaceAll(".*>", "");
+						snippet = snippet.replaceAll("\\<.*", "");
+						//remove unwanted symbols at start of line
+						snippet = snippet.replaceAll("^[ .,Â»):;-â]+", "");
+						//highlighting tags transformation
+						snippet = snippet.replaceAll("&lt;", "<");
+						snippet = snippet.replaceAll("&gt;", ">");
+						Element snippet_node = result_doc.createElement(GSXML.HL_SNIPPET_ELEM);
+						snippet_node.setAttribute(GSXML.NODE_ID_ATT, doc_id);
+						snippet_node.setTextContent(snippet);
+						snippet_list.appendChild(snippet_node);
+					}
+				}
 				document_list.appendChild(doc_node);
 			}
@@ -756,4 +802,5 @@
 		}
 
+		
 		return result;
 
@@ -778,4 +825,7 @@
 	/** get the list of facets */
 	abstract protected ArrayList<FacetWrapper> getFacets(Object query_result);
+	
+	/** get the map of highlighting snippets */
+	abstract protected Map<String, Map<String, List<String>>> getHighlightSnippets(Object query_result);
 
 	/** add in term info if available */
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 30049)
@@ -66,4 +66,7 @@
 	/** does this service support faceting search results */
 	protected boolean does_faceting = false;
+	/** does this service support highlighting snippets results */
+	protected boolean does_highlight_snippets = false;
+	protected boolean does_full_field_highlighting = false;
 	/**
 	 * the default document type - use if all documents are the same type
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2LuceneSearch.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2LuceneSearch.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2LuceneSearch.java	(revision 30049)
@@ -21,7 +21,9 @@
 // Greenstone classes
 import java.io.File;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -35,5 +37,4 @@
 import org.greenstone.gsdl3.util.GSXML;
 import org.greenstone.gsdl3.util.XMLConverter;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -307,3 +308,11 @@
     return gs3_sort;
   }
+
+@Override
+protected Map<String, Map<String, List<String>>> getHighlightSnippets(
+		Object query_result) {
+	// TODO Auto-generated method stub
+	return null;
 }
+
+}
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 30049)
@@ -24,4 +24,5 @@
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -33,10 +34,8 @@
 import org.greenstone.gsdl3.util.GSXML;
 import org.greenstone.gsdl3.util.XMLConverter;
-
 import org.greenstone.mgpp.MGPPDocInfo;
 import org.greenstone.mgpp.MGPPQueryResult;
 import org.greenstone.mgpp.MGPPSearchWrapper;
 import org.greenstone.mgpp.MGPPTermInfo;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -358,3 +357,10 @@
 		return null;
 	}
+
+	@Override
+	protected Map<String, Map<String, List<String>>> getHighlightSnippets(
+			Object query_result) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java	(revision 30043)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java	(revision 30049)
@@ -168,4 +168,5 @@
 	public static final String NODE_ID_ATT = "nodeID";
 	public static final String HREF_ID_ATT = "hrefId"; // for ids that need translating
+	public static final String HL_SNIPPET_ELEM = "highlightSnippet";
 	public static final String ID_MOD_ATT = "idMod"; // might hold .rt etc for hrefIds
 	public static final String NODE_OID = "oid";
