Index: greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java
===================================================================
--- greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java	(revision 14378)
+++ greenstone3/trunk/src/java/org/greenstone/gsdl3/service/GS2MGSearch.java	(revision 14428)
@@ -25,5 +25,5 @@
 // XML classes
 import org.w3c.dom.Document;
-import org.w3c.dom.Element; 
+import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
@@ -45,174 +45,172 @@
  */
 
-public class GS2MGSearch 
-    extends AbstractGS2Search 
-{
-
-    protected MGWrapper mg_src = null;
-
-    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2MGSearch.class.getName());
-
-
+public class GS2MGSearch
+extends AbstractGS2Search {
+    
+//    protected MGSearchWrapper mg_src = null;
+    protected MGSearchWrapper mg_src = null;
+    
+    static Logger logger = Logger.getLogger (org.greenstone.gsdl3.service.GS2MGSearch.class.getName ());
+    
+    
     /** constructor */
-    public GS2MGSearch()
-    {
-	this.mg_src = new MGWrapper();
-	
-    }
-    public void cleanUp() {
-	super.cleanUp();
-	this.mg_src.unloadIndexData();
-    }
-
+    public GS2MGSearch () {
+//        this.mg_src = new MGSearchWrapper ();
+        this.mg_src = new MGSearchWrapper ();
+        
+    }
+    public void cleanUp () {
+        super.cleanUp ();
+        this.mg_src.unloadIndexData ();
+    }
+    
     /** configure this service */
-    public boolean configure(Element info, Element extra_info)
-    {
-	if (!super.configure(info, extra_info)){
-	    return false;
-	}
-
-	this.mg_src.setMaxNumeric(this.maxnumeric);             
-        	
-	return true;
-    }
-    
-
-
+    public boolean configure (Element info, Element extra_info) {
+        if (!super.configure (info, extra_info)){
+            return false;
+        }
+        
+        this.mg_src.setMaxNumeric (this.maxnumeric);
+        
+        return true;
+    }
+    
+    
+    
     /** do the actual query */
-    protected Element processTextQuery(Element request) 
-    {
-
-	// Create a new (empty) result message
-	Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
-	result.setAttribute(GSXML.FROM_ATT, TEXT_QUERY_SERVICE);
-	result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
-
-	// Get the parameters of the request
-	Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
-	if (param_list == null) {
-	    logger.error("TextQuery request had no paramList.");
-	    return result;  // Return the empty result
-	}
-
-	// Process the request parameters
-	HashMap params = GSXML.extractParams(param_list, false);
-	
-	// Make sure a query has been specified
-	String query = (String) params.get(QUERY_PARAM);
-	if (query == null || query.equals("")) {
-	    return result;  // Return the empty result
-	}
-
-	// If an index hasn't been specified, use the default
-	String index = (String) params.get(INDEX_PARAM); 
-	if (index == null) {
-	    index = this.default_index;
-	}
-
-	// If a subcollection index has been specified, use it
-	String indexSub = (String) params.get(INDEX_SUBCOLLECTION_PARAM); 
-	if (indexSub != null) {
-	    index += indexSub;
-	}
-	else{
-	    if (!this.default_index_subcollection.equals("")){
-		index += this.default_index_subcollection;
-	    }
-	}
-
-	// If a subcollection index has been specified, use it
-	String indexLang = (String) params.get(INDEX_LANGUAGE_PARAM); 
-	if (indexLang != null) {
-	    index += indexLang;
-	}
-	else{
-	    if (!this.default_index_language.equals("")){
-		index += this.default_index_language; 
-	    }
-	}
-   
-	// The location of the MG index and text files
-	String basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +  File.separatorChar;  // Needed for MG
-	String textdir = GSFile.collectionTextPath(this.index_stem);
-	String indexpath = GSFile.collectionIndexPath(this.index_stem, index);
-	this.mg_src.setIndex(indexpath);
-	System.err.println("index path = "+indexpath);
-	// set the mg query parameters to the values the user has specified
-	setStandardQueryParams(params);
-	this.mg_src.runQuery(basedir, textdir, query);
-	MGQueryResult mqr = this.mg_src.getQueryResult();
-	if (mqr.isClear()) {
-	    // something has gone wrong
-	    GSXML.addError(this.doc, result, "Couldn't query the mg database", GSXML.ERROR_TYPE_SYSTEM);
-	    return result;
-	}
-	long totalDocs = mqr.getTotalDocs();
-
-	// Get the docnums out, and convert to HASH ids
-	Vector docs = mqr.getDocs();
-	if (docs.size() == 0) {
-	    logger.error("No results found...\n");
-	}
-
-	// Create a metadata list to store information about the query results
-	Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 
-	result.appendChild(metadata_list);
-
-	// Add a metadata element specifying the number of matching documents
-	// because teh total number is just the number returned, use numDocsReturned, not numDocsMatched
-	GSXML.addMetadata(this.doc, metadata_list, "numDocsReturned", ""+totalDocs);
-	// 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(this.doc, metadata_list, "query", query);
-
-	if (docs.size() > 0) {
-	    // Create a document list to store the matching documents, and add them
-	    Element document_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
-	    result.appendChild(document_list);
-	    for (int d = 0; d < docs.size(); d++) {
-		long docnum = ((MGDocInfo) docs.elementAt(d)).num_;
-		float rank = ((MGDocInfo) docs.elementAt(d)).rank_;
-		String doc_id = internalNum2OID(docnum);
-		Element doc_node = createDocNode(doc_id, Float.toString(rank));
-		document_list.appendChild(doc_node);
-	    }
-	}
-	
-	// Create a term list to store the term information, and add it
-	Element term_list = this.doc.createElement(GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
-	result.appendChild(term_list);
-	Vector terms = mqr.getTerms();
-	for (int t = 0; t < terms.size(); t++) {
-	    MGTermInfo term_info = (MGTermInfo) terms.get(t);
-
-	    String term = term_info.term_;
-	    int stem_method = term_info.stem_method_;
-	    Vector equiv_terms = term_info.equiv_terms_;
-
-	    Element term_elem = this.doc.createElement(GSXML.TERM_ELEM);
-	    term_elem.setAttribute(GSXML.NAME_ATT, term);
-	    term_elem.setAttribute(STEM_ATT, "" + stem_method);
-
-	    Element equiv_term_list = this.doc.createElement(EQUIV_TERM_ELEM+GSXML.LIST_MODIFIER);
-	    term_elem.appendChild(equiv_term_list);
-
-	    long total_term_freq = 0;
-	    for (int et = 0; et < equiv_terms.size(); et++) {
-		MGEquivTermInfo equiv_term_info = (MGEquivTermInfo) equiv_terms.get(et);
-
-		Element equiv_term_elem = this.doc.createElement(GSXML.TERM_ELEM);
-		equiv_term_elem.setAttribute(GSXML.NAME_ATT, equiv_term_info.term_);
-		equiv_term_elem.setAttribute(NUM_DOCS_MATCH_ATT, "" + equiv_term_info.match_docs_);
-		equiv_term_elem.setAttribute(FREQ_ATT, "" + equiv_term_info.term_freq_);
-		equiv_term_list.appendChild(equiv_term_elem);
-
-		total_term_freq += equiv_term_info.term_freq_;
-	    }
-
-	    term_elem.setAttribute(FREQ_ATT, "" + total_term_freq);
-	    term_list.appendChild(term_elem);
-	}
-	return result;
-    }
-
+    protected Element processTextQuery (Element request) {
+        
+        // Create a new (empty) result message ('doc' is in ServiceRack.java)
+        Element result = this.doc.createElement (GSXML.RESPONSE_ELEM);
+        result.setAttribute (GSXML.FROM_ATT, TEXT_QUERY_SERVICE);
+        result.setAttribute (GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
+        
+        // Get the parameters of the request
+        Element param_list = (Element) GSXML.getChildByTagName (request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+        if (param_list == null) {
+            logger.error ("TextQuery request had no paramList.");
+            return result;  // Return the empty result
+        }
+        
+        // Process the request parameters
+        HashMap params = GSXML.extractParams (param_list, false);
+        
+        // Make sure a query has been specified
+        String query = (String) params.get (QUERY_PARAM);
+        if (query == null || query.equals ("")) {
+            return result;  // Return the empty result
+        }
+        
+        // If an index hasn't been specified, use the default
+        String index = (String) params.get (INDEX_PARAM);
+        if (index == null) {
+            index = this.default_index;
+        }
+        
+        // If a subcollection index has been specified, use it
+        String indexSub = (String) params.get (INDEX_SUBCOLLECTION_PARAM);
+        if (indexSub != null) {
+            index += indexSub;
+        }
+        else{
+            if (!this.default_index_subcollection.equals ("")){
+                index += this.default_index_subcollection;
+            }
+        }
+        
+        // If a subcollection index has been specified, use it
+        String indexLang = (String) params.get (INDEX_LANGUAGE_PARAM);
+        if (indexLang != null) {
+            index += indexLang;
+        }
+        else{
+            if (!this.default_index_language.equals ("")){
+                index += this.default_index_language;
+            }
+        }
+        
+        // The location of the MG index and text files
+        String basedir = GSFile.collectionBaseDir (this.site_home, this.cluster_name) +  File.separatorChar;  // Needed for MG
+        String textdir = GSFile.collectionTextPath (this.index_stem);
+        String indexpath = GSFile.collectionIndexPath (this.index_stem, index);
+        this.mg_src.setIndex (indexpath);
+        System.err.println ("index path = "+indexpath);
+        // set the mg query parameters to the values the user has specified
+        setStandardQueryParams (params);
+        this.mg_src.runQuery (basedir, textdir, query);
+        MGQueryResult mqr = this.mg_src.getQueryResult ();
+        if (mqr.isClear ()) {
+            // something has gone wrong
+            GSXML.addError (this.doc, result, "Couldn't query the mg database", GSXML.ERROR_TYPE_SYSTEM);
+            return result;
+        }
+        long totalDocs = mqr.getTotalDocs ();
+        
+        // Get the docnums out, and convert to HASH ids
+        Vector docs = mqr.getDocs ();
+        if (docs.size () == 0) {
+            logger.error ("No results found...\n");
+        }
+        
+        // Create a metadata list to store information about the query results
+        Element metadata_list = this.doc.createElement (GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
+        result.appendChild (metadata_list);
+        
+        // Add a metadata element specifying the number of matching documents
+        // because teh total number is just the number returned, use numDocsReturned, not numDocsMatched
+        GSXML.addMetadata (this.doc, metadata_list, "numDocsReturned", ""+totalDocs);
+        // 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 (this.doc, metadata_list, "query", query);
+        
+        if (docs.size () > 0) {
+            // Create a document list to store the matching documents, and add them
+            Element document_list = this.doc.createElement (GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
+            result.appendChild (document_list);
+            for (int d = 0; d < docs.size (); d++) {
+                long docnum = ((MGDocInfo) docs.elementAt (d)).num_;
+                float rank = ((MGDocInfo) docs.elementAt (d)).rank_;
+                String doc_id = internalNum2OID (docnum);
+                Element doc_node = createDocNode (doc_id, Float.toString (rank));
+                document_list.appendChild (doc_node);
+            }
+        }
+        
+        // Create a term list to store the term information, and add it
+        Element term_list = this.doc.createElement (GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
+        result.appendChild (term_list);
+        Vector terms = mqr.getTerms ();
+        for (int t = 0; t < terms.size (); t++) {
+            MGTermInfo term_info = (MGTermInfo) terms.get (t);
+            
+            String term = term_info.term_;
+            int stem_method = term_info.stem_method_;
+            Vector equiv_terms = term_info.equiv_terms_;
+            
+            Element term_elem = this.doc.createElement (GSXML.TERM_ELEM);
+            term_elem.setAttribute (GSXML.NAME_ATT, term);
+            term_elem.setAttribute (STEM_ATT, "" + stem_method);
+            
+            Element equiv_term_list = this.doc.createElement (EQUIV_TERM_ELEM+GSXML.LIST_MODIFIER);
+            term_elem.appendChild (equiv_term_list);
+            
+            long total_term_freq = 0;
+            for (int et = 0; et < equiv_terms.size (); et++) {
+                MGEquivTermInfo equiv_term_info = (MGEquivTermInfo) equiv_terms.get (et);
+                
+                Element equiv_term_elem = this.doc.createElement (GSXML.TERM_ELEM);
+                equiv_term_elem.setAttribute (GSXML.NAME_ATT, equiv_term_info.term_);
+                equiv_term_elem.setAttribute (NUM_DOCS_MATCH_ATT, "" + equiv_term_info.match_docs_);
+                equiv_term_elem.setAttribute (FREQ_ATT, "" + equiv_term_info.term_freq_);
+                equiv_term_list.appendChild (equiv_term_elem);
+                
+                total_term_freq += equiv_term_info.term_freq_;
+            }
+            
+            term_elem.setAttribute (FREQ_ATT, "" + total_term_freq);
+            term_list.appendChild (term_elem);
+        }
+        return result;
+    }
+    
     // should probably use a list rather than map
     protected boolean setStandardQueryParams(HashMap params)
@@ -247,6 +245,6 @@
 	return true;
     }
-
-
+    
+    
 }
 
