Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGPPGDBMServices.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGPPGDBMServices.java	(revision 3584)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/service/MGPPGDBMServices.java	(revision 3605)
@@ -51,4 +51,5 @@
     private static final String TEXT_QUERY_SERVICE = "TextQuery";
     private static final String FIELD_QUERY_SERVICE = "FieldQuery";
+    private static final String ADVANCED_FIELD_QUERY_SERVICE = "AdvancedFieldQuery";
     private static final String RESOURCE_RETRIEVE_SERVICE = "ResourceRetrieve";
     private static final String METADATA_RETRIEVE_SERVICE = "MetadataRetrieve";
@@ -68,4 +69,16 @@
     private static final String BOOLEAN_PARAM_ON = "1";
     private static final String BOOLEAN_PARAM_OFF = "0";
+    private static final String QUERY_PARAM = "query";
+    private static final String SIMPLE_FIELD_PARAM = "simpleField";
+    private static final String ADVANCED_FIELD_PARAM = "complexField";
+    // more params for field query
+    private static final String FIELD_QUERY_PARAM = "fqv";
+    private static final String FIELD_STEM_PARAM = "fqs";
+    private static final String FIELD_CASE_PARAM = "fqc";
+    private static final String FIELD_FIELD_PARAM = "fqf";
+    private static final String FIELD_COMBINE_PARAM = "fqk";
+    private static final String FIELD_COMBINE_PARAM_AND = "0";
+    private static final String FIELD_COMBINE_PARAM_OR = "1";
+    private static final String FIELD_COMBINE_PARAM_NOT = "2";
     
     // elements used in the config file that are specific to this class
@@ -130,4 +143,9 @@
 	e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
 	e.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE);
+	short_service_info_.appendChild(e);
+
+	e = doc_.createElement(GSXML.SERVICE_ELEM);
+	e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
+	e.setAttribute(GSXML.NAME_ATT, ADVANCED_FIELD_QUERY_SERVICE);
 	short_service_info_.appendChild(e);
 
@@ -157,6 +175,17 @@
 	e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
 	e.setAttribute(GSXML.NAME_ATT, FIELD_QUERY_SERVICE);
+	Element param_list1 = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	createFieldQueryParamList(param_list1, false, null);
+	e.appendChild(param_list1);
 	service_info_map_.put(FIELD_QUERY_SERVICE, e);
 	
+	e = doc_.createElement(GSXML.SERVICE_ELEM);
+	e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
+	e.setAttribute(GSXML.NAME_ATT, ADVANCED_FIELD_QUERY_SERVICE);
+	Element param_list2 = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	createAdvancedFieldQueryParamList(param_list2, false, null);
+	e.appendChild(param_list2);
+	service_info_map_.put(ADVANCED_FIELD_QUERY_SERVICE, e);
+
 	e = doc_.createElement(GSXML.SERVICE_ELEM);
 	e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
@@ -268,7 +297,286 @@
 	}
 	param_list.appendChild(param);
+
+	// for now add the query itself as a param
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, QUERY_PARAM, getTextString("param."+QUERY_PARAM, lang), null, null);
+	} else {
+	    param = GSXML.createParameter(doc_, QUERY_PARAM, GSXML.PARAM_TYPE_STRING, null, null);
+	}
+	param_list.appendChild(param);
+	
 	return true;
     }
-
+    /** this creates all teh params and appends them to param_list.
+     * if display=true it creates the text strings version
+     * otherwise it creates the description version
+     */
+    protected boolean createFieldQueryParamList(Element param_list, boolean display, String lang) {
+	Element param;
+
+	// first do index and level params
+
+	// the index info - read from config file
+//  	Element index_list = (Element)GSXML.getChildByTagName(config_info_, INDEX_ELEM+GSXML.LIST_MODIFIER);
+//  	NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM);
+//  	int len = indexes.getLength();
+//  	if (len > 1) {
+//  	    // add level param to list
+//  	    String [] inds  = new String[len];
+//  	    for (int i=0; i<len; i++) {
+//  		inds[i] = ((Element)indexes.item(i)).getAttribute(GSXML.NAME_ATT);
+//  	    }
+//  	    if (display) {
+//  		// use the same index names for now - should get these out of the config info
+//  		param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, inds);
+//  	    } else {
+//  		param = GSXML.createParameter(doc_, INDEX_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_index_, inds);
+//  	    }
+//  	    param_list.appendChild(param);
+//  	} // else dont need to add it
+
+	// the level info - read from config file
+	Element level_list = (Element)GSXML.getChildByTagName(config_info_, LEVEL_ELEM+GSXML.LIST_MODIFIER);
+	NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
+	int len = levels.getLength();
+	if (len > 1) {
+	    // add level param to list
+	    String [] levs  = new String[len];
+	    for (int i=0; i<len; i++) {
+		levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT);
+	    }
+	    if (display) {
+		param =  GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, levs);
+	    } else {
+		param = GSXML.createParameter(doc_, LEVEL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_level_, levs);
+	    }
+	    param_list.appendChild(param);
+	} // else dont need to add it
+	
+	// enum params
+	String []vals = {MATCH_PARAM_ALL, MATCH_PARAM_SOME};
+	if (display) {
+	    String []val_texts = {getTextString("param."+MATCH_PARAM+"."+MATCH_PARAM_ALL, lang),getTextString("param."+MATCH_PARAM+"."+MATCH_PARAM_SOME, lang)}; 
+
+	    param = GSXML.createParameterDisplay(doc_, MATCH_PARAM, getTextString("param."+MATCH_PARAM, lang), vals, val_texts);
+	} else {
+	    param = GSXML.createParameter(doc_, MATCH_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, MATCH_PARAM_ALL, vals);
+	}	
+	param_list.appendChild(param);
+	String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE };
+	if (display) {
+	    String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang),
+				  getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)};
+	
+	    param = GSXML.createParameterDisplay(doc_, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), vals1, vals1_texts);
+	} else {
+	    param = GSXML.createParameter(doc_, RANK_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1 );
+	}
+	param_list.appendChild(param);
+
+	// boolean params
+	if (display) {
+	    String[] bool_ops = {"0", "1"};
+	    String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)}; 
+	    param = GSXML.createParameterDisplay(doc_, FIELD_CASE_PARAM, getTextString("param."+FIELD_CASE_PARAM, lang),  bool_ops, bool_texts);
+	    param_list.appendChild(param);
+	    param = GSXML.createParameterDisplay(doc_, FIELD_STEM_PARAM, getTextString("param."+FIELD_STEM_PARAM, lang),  bool_ops, bool_texts);
+	    param_list.appendChild(param);
+
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_CASE_PARAM, GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, null);
+	    param_list.appendChild(param);
+	    param = GSXML.createParameter(doc_, FIELD_STEM_PARAM, GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, null);
+	    param_list.appendChild(param);
+	}
+
+	// Integer params
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, MAXDOCS_PARAM, getTextString("param."+MAXDOCS_PARAM, lang), null, null);
+	} else {
+	    param = GSXML.createParameter(doc_, MAXDOCS_PARAM, GSXML.PARAM_TYPE_INTEGER, "10", null);
+	}
+	param_list.appendChild(param);
+
+	// create a multi param for the fields etc
+	// text box, stem, case, field
+
+	Element multiparam = null;;
+
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, SIMPLE_FIELD_PARAM, "",  null, null);
+	    param_list.appendChild(param);
+	} else {
+	    multiparam = GSXML.createParameter(doc_, SIMPLE_FIELD_PARAM, GSXML.PARAM_TYPE_MULTI, null, null);
+	    multiparam.setAttribute("occurs", "4");
+	    param_list.appendChild(multiparam);
+	}
+	// the components
+	// the text box
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, FIELD_QUERY_PARAM, getTextString("param."+FIELD_QUERY_PARAM, lang), null, null);
+	    param_list.appendChild(param);
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_QUERY_PARAM, GSXML.PARAM_TYPE_STRING, null, null);
+	    multiparam.appendChild(param);
+	    
+	}
+	
+	// the field list - should be read from config file
+	String [] vals2 = {"TX", "SU", "TI"};
+	String [] vals2_texts = {"TextOnly", "Subject", "Title"};
+	
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), vals2, vals2_texts);
+	    param_list.appendChild(param); 
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", vals2 );
+	    multiparam.appendChild(param);
+	}
+	
+	return true;
+    }
+
+    protected boolean createAdvancedFieldQueryParamList(Element param_list, boolean display, String lang) {
+	Element param;
+
+	// first do index and level params
+
+	// the index info - read from config file
+//  	Element index_list = (Element)GSXML.getChildByTagName(config_info_, INDEX_ELEM+GSXML.LIST_MODIFIER);
+//  	NodeList indexes = index_list.getElementsByTagName(INDEX_ELEM);
+//  	int len = indexes.getLength();
+//  	if (len > 1) {
+//  	    // add level param to list
+//  	    String [] inds  = new String[len];
+//  	    for (int i=0; i<len; i++) {
+//  		inds[i] = ((Element)indexes.item(i)).getAttribute(GSXML.NAME_ATT);
+//  	    }
+//  	    if (display) {
+//  		// use the same index names for now - should get these out of the config info
+//  		param = GSXML.createParameterDisplay(doc_, INDEX_PARAM, getTextString("param."+INDEX_PARAM, lang), inds, inds);
+//  	    } else {
+//  		param = GSXML.createParameter(doc_, INDEX_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_index_, inds);
+//  	    }
+//  	    param_list.appendChild(param);
+//  	} // else dont need to add it
+
+	// the level info - read from config file
+	Element level_list = (Element)GSXML.getChildByTagName(config_info_, LEVEL_ELEM+GSXML.LIST_MODIFIER);
+	NodeList levels = level_list.getElementsByTagName(LEVEL_ELEM);
+	int len = levels.getLength();
+	if (len > 1) {
+	    // add level param to list
+	    String [] levs  = new String[len];
+	    for (int i=0; i<len; i++) {
+		levs[i] = ((Element)levels.item(i)).getAttribute(GSXML.NAME_ATT);
+	    }
+	    if (display) {
+		param =  GSXML.createParameterDisplay(doc_, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), levs, levs);
+	    } else {
+		param = GSXML.createParameter(doc_, LEVEL_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, default_level_, levs);
+	    }
+	    param_list.appendChild(param);
+	} // else dont need to add it
+	
+//  	// enum params
+//  	String []vals = {MATCH_PARAM_ALL, MATCH_PARAM_SOME};
+//  	if (display) {
+//  	    String []val_texts = {getTextString("param."+MATCH_PARAM+"."+MATCH_PARAM_ALL, lang),getTextString("param."+MATCH_PARAM+"."+MATCH_PARAM_SOME, lang)}; 
+
+//  	    param = GSXML.createParameterDisplay(doc_, MATCH_PARAM, getTextString("param."+MATCH_PARAM, lang), vals, val_texts);
+//  	} else {
+//  	    param = GSXML.createParameter(doc_, MATCH_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, MATCH_PARAM_ALL, vals);
+//  	}	
+//  	param_list.appendChild(param);
+
+	String [] vals1 = {RANK_PARAM_RANK, RANK_PARAM_NONE };
+	if (display) {
+	    String [] vals1_texts = { getTextString("param."+RANK_PARAM+"."+RANK_PARAM_RANK, lang),
+				  getTextString("param."+RANK_PARAM+"."+RANK_PARAM_NONE, lang)};
+	
+	    param = GSXML.createParameterDisplay(doc_, RANK_PARAM, getTextString("param."+RANK_PARAM, lang), vals1, vals1_texts);
+	} else {
+	    param = GSXML.createParameter(doc_, RANK_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1 );
+	}
+	param_list.appendChild(param);
+
+	// Integer params
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, MAXDOCS_PARAM, getTextString("param."+MAXDOCS_PARAM, lang), null, null);
+	} else {
+	    param = GSXML.createParameter(doc_, MAXDOCS_PARAM, GSXML.PARAM_TYPE_INTEGER, "10", null);
+	}
+	param_list.appendChild(param);
+
+	// create a multi param for the fields etc
+	// text box, stem, case, field
+
+	Element multiparam = null;
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, ADVANCED_FIELD_PARAM, "",  null, null);
+	    param_list.appendChild(param);
+	} else {
+	    multiparam = GSXML.createParameter(doc_, ADVANCED_FIELD_PARAM, GSXML.PARAM_TYPE_MULTI, null, null);
+	    multiparam.setAttribute("occurs", "4");
+	    param_list.appendChild(multiparam);
+	}
+	
+	// the components
+
+	//the combiners
+	
+	String []vals = {FIELD_COMBINE_PARAM_AND, FIELD_COMBINE_PARAM_OR, FIELD_COMBINE_PARAM_NOT};
+	if (display) {
+	    String []val_texts = {getTextString("param."+FIELD_COMBINE_PARAM+"."+FIELD_COMBINE_PARAM_AND, lang), getTextString("param."+FIELD_COMBINE_PARAM+"."+FIELD_COMBINE_PARAM_OR, lang), getTextString("param."+FIELD_COMBINE_PARAM+"."+FIELD_COMBINE_PARAM_NOT, lang)}; 
+
+	    param = GSXML.createParameterDisplay(doc_, FIELD_COMBINE_PARAM, "", vals, val_texts);
+	    param_list.appendChild(param);
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_COMBINE_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals);
+	    param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
+	    multiparam.appendChild(param);
+	}	
+
+	// the text box
+	if (display) {
+	    param = GSXML.createParameterDisplay(doc_, FIELD_QUERY_PARAM, getTextString("param."+FIELD_QUERY_PARAM, lang), null, null);
+	    param_list.appendChild(param);
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_QUERY_PARAM, GSXML.PARAM_TYPE_STRING, null, null);
+	    multiparam.appendChild(param);
+	    
+	}
+	
+	// boolean params
+	if (display) {
+	    String[] bool_ops = {"0", "1"};
+	    String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)}; 
+	    param = GSXML.createParameterDisplay(doc_, FIELD_CASE_PARAM, getTextString("param."+FIELD_CASE_PARAM, lang),  bool_ops, bool_texts);
+	    param_list.appendChild(param);
+	    param = GSXML.createParameterDisplay(doc_, FIELD_STEM_PARAM, getTextString("param."+FIELD_STEM_PARAM, lang),  bool_ops, bool_texts);
+	    param_list.appendChild(param);
+
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_CASE_PARAM, GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, null);
+	    multiparam.appendChild(param);
+	    param = GSXML.createParameter(doc_, FIELD_STEM_PARAM, GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, null);
+	    multiparam.appendChild(param);
+	}
+
+	// the field list
+	String [] vals2 = {"TX", "SU", "TI"};
+	String [] vals2_texts = {"TextOnly", "Subject", "Title"};
+
+	if (display) {
+	     param = GSXML.createParameterDisplay(doc_, FIELD_FIELD_PARAM, getTextString("param."+FIELD_FIELD_PARAM, lang), vals2, vals2_texts);
+	    param_list.appendChild(param); 
+	} else {
+	    param = GSXML.createParameter(doc_, FIELD_FIELD_PARAM, GSXML.PARAM_TYPE_ENUM_SINGLE, "", vals2 );
+	    multiparam.appendChild(param);
+	}
+	
+	return true;
+    }
     /** creates a display element containing all the text strings needed to display the service page, in the language specified */
     protected Element createServiceDisplay(String service, String lang) {
@@ -282,4 +590,14 @@
 	    createTextQueryParamList(display, true, lang);
 	}
+	// now need to add in the params
+	if (service.equals(FIELD_QUERY_SERVICE)) {
+	    
+	    createFieldQueryParamList(display, true, lang);
+	}
+	// now need to add in the params
+	if (service.equals(ADVANCED_FIELD_QUERY_SERVICE)) {
+	    
+	    createAdvancedFieldQueryParamList(display, true, lang);
+	}
 	return display;
 	
@@ -295,5 +613,7 @@
 	    return processTextQuery(request);
 	} else if(name.equals(FIELD_QUERY_SERVICE)) {
-	    return processFieldQuery(request);
+	    return processFieldQuery(request, "simple");
+	} else if(name.equals(ADVANCED_FIELD_QUERY_SERVICE)) {
+	    return processFieldQuery(request, "advanced");
 	} else if (name.equals(RESOURCE_RETRIEVE_SERVICE)) {
 	    return processResourceRetrieve(request);
@@ -317,5 +637,5 @@
 	
 	// get param list and content
-	Element param_elem=null;
+	/*Element param_elem=null;
 	Element content_elem=null;
 	Node n = request.getFirstChild();
@@ -334,5 +654,13 @@
 	    return result; // empty result
 	}
-
+	*/
+
+	// get param list
+	Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	if (param_list==null) {
+	    System.err.println("MGPPGDBMServices, TextQuery Error: no param list in request!");
+	    return result; // empty result
+	}
+	/*
 	// get the query string
 	String query = GSXML.getNodeText(content_elem);
@@ -341,6 +669,12 @@
 	    return result;
 	}
-
-	HashMap params = GSXML.extractParams(param_elem);
+	*/
+	HashMap params = GSXML.extractParams(param_list);
+	String query = (String)params.get(QUERY_PARAM);
+	if (query == null) {
+	    // nothing to query
+	    return result;
+	}
+	
 	String index = (String)params.get(INDEX_PARAM); 
 	if (index==null) { // if its not present, use the default index
@@ -354,5 +688,5 @@
 
 	mgpp_src_.loadIndexData(basedir, indexdir);
-	setQueryParams(params);
+	setStandardQueryParams(params);
 	
 	mgpp_src_.runQuery(query);
@@ -381,15 +715,72 @@
 
     /** process a fielded query */
-    protected Element processFieldQuery(Element request) {
+    protected Element processFieldQuery(Element request, String type) {
+	
+	System.out.println("processing Field Query...");
 	Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
 	String from = GSPath.appendLink(cluster_name_, FIELD_QUERY_SERVICE);
 	result.setAttribute(GSXML.FROM_ATT, from);
 	result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
-
-	
-	// dummy result
-	Text t = null;
-	t = doc_.createTextNode(FIELD_QUERY_SERVICE+" result... ");
-	result.appendChild(t);
+	
+	// get param list
+	Element param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	if (param_list==null) {
+	    System.err.println("MGPPGDBMServices, FieldQuery Error: no param list in request!");
+	    return result; // empty result
+	}
+
+	HashMap params = GSXML.extractAllParams(param_list);
+	printHash(params);
+
+	//check one of the params to see if it is present
+	String test_param = (String)params.get(FIELD_QUERY_PARAM);
+	if (test_param == null) { // no query
+	    return result;
+	}
+
+	
+	/*	String index = (String)params.get(INDEX_PARAM); 
+	if (index==null) { // if its not present, use the default index
+	    index=default_index_;
+	    }*/
+	// for now we are using the default index
+	String index = default_index_;
+	
+	// now set up the mgpp stuff
+	String basedir = GSFile.collectionBaseDir(site_home_, 
+						  cluster_name_);
+	String indexdir = GSFile.collectionIndexPath(cluster_name_, index);
+	
+	mgpp_src_.loadIndexData(basedir, indexdir);
+	setStandardQueryParams(params);
+	
+	String query="";
+	if (type.equals("simple")) {
+	    query = parseFieldQueryParams(params);
+	} else if (type.equals("advanced")) {
+	    query = parseAdvancedFieldQueryParams(params);
+	}
+	System.out.println("query="+query);
+	mgpp_src_.runQuery(query);
+	MGPPQueryResult mqr= mgpp_src_.getQueryResult();
+	
+	// get the docnums out, and convert to HASH ids
+	Vector docs = mqr.getDocs();
+	if (docs.size()==0) {
+	    // no docs found
+	    return result;
+	}
+	// create a resourceList element
+	Element c = doc_.createElement(GSXML.CONTENT_ELEM);
+	result.appendChild(c);
+	Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
+	c.appendChild(resource_list);
+	// add each resource
+	for (int d=0; d<docs.size(); d++) {
+	    long docnum = ((MGPPDocInfo)docs.elementAt(d)).num_;
+	    String id = gdbm_src_.docnum2Oid(docnum);
+	    Node no = GSXML.createResourceElement(doc_, id);
+	    resource_list.appendChild(no);
+	}
 	return result;
     }
@@ -528,5 +919,5 @@
 
     // should probably use a list rather than map
-    protected boolean setQueryParams(HashMap params) {
+    protected boolean setStandardQueryParams(HashMap params) {
 
 	// set the default ones
@@ -566,6 +957,117 @@
     }
 
-
-}  
+    protected String parseFieldQueryParams(HashMap params) {
+
+	StringBuffer final_query = new StringBuffer(256);
+	String text_line = (String)params.get(FIELD_QUERY_PARAM);
+	String[] texts = text_line.split(",", -1);
+	String field_line = (String)params.get(FIELD_FIELD_PARAM);
+	String[] fields = field_line.split(",", -1);
+	String combine="&";
+	String match = (String)params.get(MATCH_PARAM);
+	if (match.equals(MATCH_PARAM_SOME)) {
+	    combine = "|";
+	}
+	
+	for (int i=0; i<texts.length; i++) {
+
+	    String q = texts[i].trim();
+	    if (!q.equals("")) {
+		addQueryElem(final_query, q, fields[i], combine);
+	    }
+	}
+
+	System.out.println("final query = "+final_query.toString());
+	return final_query.toString();
+    }
+    
+    protected String parseAdvancedFieldQueryParams(HashMap params) {
+
+	StringBuffer final_query = new StringBuffer(256);
+	String text_line = (String)params.get(FIELD_QUERY_PARAM);
+	String[] texts = text_line.split(",", -1);
+	String field_line = (String)params.get(FIELD_FIELD_PARAM);
+	String[] fields = field_line.split(",", -1);
+	String case_line = (String)params.get(FIELD_CASE_PARAM);
+	String[] cases = case_line.split(",", -1);
+	String stem_line = (String)params.get(FIELD_STEM_PARAM);
+	String[] stems = stem_line.split(",", -1);
+	String  combine_line = (String)params.get(FIELD_COMBINE_PARAM);
+	String [] combines = combine_line.split(",", -1);
+	String combine = "&";
+	for (int i=0; i<texts.length; i++) {
+	    if (i==0) {
+		combine = "";
+	    } else {
+		String x = combines[i-1]; // assume first one is missing
+		if (x.equals(FIELD_COMBINE_PARAM_AND)) {
+		    combine = "&";
+		} else if (x.equals(FIELD_COMBINE_PARAM_OR)) {
+		    combine = "|";
+		} else if (x.equals(FIELD_COMBINE_PARAM_NOT)) {
+		    combine = "!";
+		} 
+		
+	    }
+
+	    String q = texts[i].trim();
+	    if (!q.equals("")) {
+		q = addStemAndCase(q, stems[i], cases[i]);
+		addQueryElem(final_query, q, fields[i], combine);
+	    }
+	}
+
+	System.out.println("final query = "+final_query.toString());
+	return final_query.toString();
+    }
+
+    protected void addQueryElem(StringBuffer s, String q, String f, String c) {
+
+	String combine="";
+	if (s.length()>0) {
+	    combine = " "+c+" ";
+	}
+	if (f!="") {
+	    s.append(combine+"["+q+"]:"+f);
+	} else {
+	    s.append(combine+q);
+	}
+    }
+    protected String addStemAndCase(String q, String c, String s) {
+	String mods = "#";
+	if (c=="1") {
+	    mods += "c";
+	}
+	if (s=="1") {
+	    mods += "s";
+	}
+	if (mods.equals("#")) {
+	    return q;
+	}
+	StringBuffer temp = new StringBuffer();
+	String [] terms = q.split(" ");
+	for (int i=0; i<terms.length; i++) {
+	    String t = terms[i].trim();
+	    
+	    if (!t.equals("") && !t.equals("TX")) {
+		temp.append(" "+t+mods);
+	    }
+	}
+	return temp.toString();
+    }
+
+    protected void printHash(HashMap map) {
+	System.out.println("Map entries are :");
+	Set entries = map.entrySet();
+	Iterator i = entries.iterator();
+	while (i.hasNext()) {
+	    Map.Entry m = (Map.Entry)i.next();
+	    String name = (String)m.getKey();
+	    String value = (String)m.getValue();
+	    System.out.println(name+"="+value);
+	}  
+    }
+
+}
  
 
