Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 28181)
@@ -94,4 +94,10 @@
 	public AbstractGS2FieldSearch()
 	{
+	  super();
+	  paramDefaults.put(RANK_PARAM, RANK_PARAM_RANK);
+	  paramDefaults.put(FIELD_COMBINE_PARAM, FIELD_COMBINE_PARAM_AND);
+	  // paramDefaults.put(FIELD_CASE_PARAM, BOOLEAN_PARAM_ON);
+	  // paramDefaults.put(FIELD_STEM_PARAM, BOOLEAN_PARAM_OFF);
+	  // paramDefaults.put(FIELD_ACCENT_PARAM, BOOLEAN_PARAM_ON);
 	}
 
@@ -108,5 +114,5 @@
 			return false;
 		}
-
+		
 		// Get the default level out of <defaultLevel> (buildConfig.xml)
 		Element def = (Element) GSXML.getChildByTagName(info, DEFAULT_LEVEL_ELEM);
@@ -260,4 +266,37 @@
 	}
 
+  // if field case/stem/accent defaults are not specified explicitly, we should use case/stem/accent defaults
+  protected void getSearchParamDefaults(Element search_elem) {
+    
+    boolean found_f_stem = false;
+    boolean found_f_case = false;
+    boolean found_f_accent = false;
+    NodeList param_defaults_list = GSXML.getChildrenByTagName(search_elem, GSXML.PARAM_DEFAULT_ELEM);
+    for (int i=0; i<param_defaults_list.getLength(); i++) {
+      Element paramdef = (Element)param_defaults_list.item(i);
+      String name = paramdef.getAttribute(GSXML.NAME_ATT);
+      String val = paramdef.getAttribute(GSXML.VALUE_ATT);
+      if (!name.equals("") && !val.equals("")) {
+	paramDefaults.put(name, val);
+	if (name.equals(FIELD_STEM_PARAM)) {
+	  found_f_stem = true;
+	} else if (name.equals(FIELD_CASE_PARAM)) {
+	  found_f_case = true;
+	} else if (name.equals(FIELD_ACCENT_PARAM)) {
+	  found_f_accent = true;
+	} 
+	if (!found_f_stem) {
+	  paramDefaults.put (FIELD_STEM_PARAM, paramDefaults.get(STEM_PARAM));
+	}
+	if (!found_f_case) {
+	  paramDefaults.put (FIELD_CASE_PARAM, paramDefaults.get(CASE_PARAM));
+	}
+	if (!found_f_accent) {
+	  paramDefaults.put (FIELD_ACCENT_PARAM, paramDefaults.get(ACCENT_PARAM));
+	}
+
+      }
+    }
+  }
 	protected Element getServiceDescription(String service_id, String lang, String subset)
 	{
@@ -393,4 +432,5 @@
 	{
 		Element param = null;
+		String param_default = paramDefaults.get(name);
 		if (name.equals(LEVEL_PARAM))
 		{
@@ -416,5 +456,5 @@
 			String[] vals1_texts = { getTextString("param." + RANK_PARAM + "." + RANK_PARAM_RANK, lang), getTextString("param." + RANK_PARAM + "." + RANK_PARAM_NONE, lang) };
 
-			param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param." + RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, RANK_PARAM_RANK, vals1, vals1_texts);
+			param = GSXML.createParameterDescription(this.doc, RANK_PARAM, getTextString("param." + RANK_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals1, vals1_texts);
 
 		}
@@ -428,5 +468,5 @@
 			String[] bool_ops = { "0", "1" };
 			String[] bool_texts = { getTextString("param.boolean.off", lang, "AbstractTextSearch"), getTextString("param.boolean.on", lang, "AbstractTextSearch") };
-			param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_BOOLEAN, BOOLEAN_PARAM_ON, bool_ops, bool_texts);
+			param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_BOOLEAN, param_default, bool_ops, bool_texts);
 
 		}
@@ -454,5 +494,5 @@
 			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.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, FIELD_COMBINE_PARAM_AND, vals, val_texts);
+			param = GSXML.createParameterDescription(this.doc, FIELD_COMBINE_PARAM, "", GSXML.PARAM_TYPE_ENUM_SINGLE, param_default, vals, val_texts);
 			param.setAttribute(GSXML.PARAM_IGNORE_POS_ATT, "0");
 		}
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2TextSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2TextSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2TextSearch.java	(revision 28181)
@@ -56,8 +56,4 @@
 	protected boolean does_accent = false;
 
-  // default values for stem indexes
-  protected String case_default = BOOLEAN_PARAM_ON;
-  protected String accent_default = BOOLEAN_PARAM_ON;
-  protected String stem_default = BOOLEAN_PARAM_OFF;
 	// maxnumeric - 
 	protected int maxnumeric = 4;
@@ -186,25 +182,4 @@
 			Document owner = info.getOwnerDocument();
 			Element config_search = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
-
-			// work out what the default values for the stemming options are
-			if (does_case || does_accent || does_stem) {
-			  // only bother looking for this is we have some of these set
-			  NodeList index_options = config_search.getElementsByTagName(GSXML.INDEX_OPTION_ELEM);
-			  for (int i = 0; i < index_options.getLength(); i++) {
-			    Element ind = (Element) index_options.item(i);
-			    String name = ind.getAttribute(GSXML.NAME_ATT);
-			    String def_val = ind.getAttribute(GSXML.DEFAULT_ATT);
-
-			    if (!def_val.equals("")) {
-			      if (name.equals("stem")) {
-				stem_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
-			      } else if (name.equals("casefold")) {
-				case_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
-			      } else if (name.equals("accentfold")) {
-				accent_default = (def_val.equals("on")? BOOLEAN_PARAM_ON: BOOLEAN_PARAM_OFF);
-			      }
-			    }
-			  }
-			}
 
 			// so far we have index and indexSubcollection specific display elements, and global format elements 
@@ -354,13 +329,13 @@
 		if (this.does_case)
 		{
-			createParameter(CASE_PARAM, param_list, lang, case_default);
+		  createParameter(CASE_PARAM, param_list, lang);//, case_default);
 		}
 		if (this.does_stem)
 		{
-			createParameter(STEM_PARAM, param_list, lang, stem_default);
+		  createParameter(STEM_PARAM, param_list, lang);//, stem_default);
 		}
 		if (this.does_accent)
 		{
-			createParameter(ACCENT_PARAM, param_list, lang, accent_default);
+		  createParameter(ACCENT_PARAM, param_list, lang);//, accent_default);
 		}
 		createParameter(MATCH_PARAM, param_list, lang);
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 28181)
@@ -21,4 +21,5 @@
 // Greenstone classes
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import org.apache.log4j.Logger;
@@ -74,10 +75,12 @@
 	protected String default_index = "";
 
-	protected String default_max_docs = "100";
-
-	protected String default_hits_per_page = "10";
+  protected HashMap<String, String> paramDefaults = null;
 
 	public AbstractSearch()
 	{
+	  paramDefaults = new HashMap<String, String>();
+	  paramDefaults.put(MAXDOCS_PARAM, "100");
+	  paramDefaults.put(HITS_PER_PAGE_PARAM, "10");
+	  paramDefaults.put(START_PAGE_PARAM, "1");
 	}
 
@@ -108,4 +111,9 @@
 		this.short_service_info.appendChild(tq_service);
 
+		// load up any search param defaults
+		Element search_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
+		if (search_elem != null) {
+		  getSearchParamDefaults(search_elem);
+		}
 		// add some format info to service map if there is any 
 		// => lookin extra info first look in buildConfig
@@ -115,15 +123,6 @@
 		if (format == null)
 		{
-			String path = GSPath.appendLink(GSXML.SEARCH_ELEM, GSXML.FORMAT_ELEM);
-
-			// Note by xiao: instead of retrieving the first 'format'
-			//   element inside the 'search' element, we are trying to
-			//   find the real format element which has at least one
-			//   'gsf:template' child element. (extra_info is
-			//   collectionConfig.xml)
-
-			//format = (Element) GSXML.getNodeByPath(extra_info, path);
-
-			Element search_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
+		  // try to find a format element inside <search> that contains a gsf:template. Note what if we have only xsl:templates??
+			
 			NodeList format_elems = null;
 			if (search_elem != null)
@@ -169,4 +168,16 @@
 	}
 
+  protected void getSearchParamDefaults(Element search_elem) {
+
+    NodeList param_defaults_list = GSXML.getChildrenByTagName(search_elem, GSXML.PARAM_DEFAULT_ELEM);
+    for (int i=0; i<param_defaults_list.getLength(); i++) {
+      Element paramdef = (Element)param_defaults_list.item(i);
+      String name = paramdef.getAttribute(GSXML.NAME_ATT);
+      String val = paramdef.getAttribute(GSXML.VALUE_ATT);
+      if (!name.equals("") && !val.equals("")) {
+	paramDefaults.put(name, val);
+      }
+    }
+  }
 	/**
 	 * returns a basic description for QUERY_SERVICE. If a subclass provides
@@ -273,5 +284,8 @@
 		Element param = null;
 		String param_default = default_value;
-
+		if (default_value == null) {
+		  // have we got a stored up default? will be null if not there
+		  param_default = paramDefaults.get(name);
+		}
 		if (name.equals(QUERY_PARAM) || name.equals(RAW_PARAM))
 		{
@@ -301,9 +315,4 @@
 		else if (name.equals(MAXDOCS_PARAM))
 		{
-			if (param_default == null)
-			{
-				param_default = this.default_max_docs;
-			}
-
 			param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_INTEGER, param_default, null, null);
 			param_list.appendChild(param);
@@ -312,9 +321,4 @@
 		else if (name.equals(HITS_PER_PAGE_PARAM))
 		{
-			if (param_default == null)
-			{
-				param_default = this.default_hits_per_page;
-			}
-
 			param = GSXML.createParameterDescription(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_INTEGER, param_default, null, null);
 			param_list.appendChild(param);
@@ -323,9 +327,4 @@
 		else if (name.equals(START_PAGE_PARAM))
 		{
-			if (param_default == null)
-			{
-				param_default = "1";
-			}
-
 			// start page - set to 1 for the search page
 			param = GSXML.createParameterDescription(this.doc, START_PAGE_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, param_default, null, null);
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractTextSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractTextSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractTextSearch.java	(revision 28181)
@@ -60,6 +60,11 @@
 	public AbstractTextSearch()
 	{
+	  super();
 		// the search service
 		QUERY_SERVICE = "TextQuery";
+		paramDefaults.put(CASE_PARAM, BOOLEAN_PARAM_ON);
+		paramDefaults.put(STEM_PARAM, BOOLEAN_PARAM_OFF);
+		paramDefaults.put(ACCENT_PARAM, BOOLEAN_PARAM_ON);
+		paramDefaults.put(MATCH_PARAM, MATCH_PARAM_SOME);
 	}
 
@@ -87,4 +92,8 @@
 		Element param = null;
 		String param_default = default_value;
+		if (default_value == null) {
+		  // have we got a stored up default? will be null if not there
+		  param_default = paramDefaults.get(name);
+		}
 
 		if (super.createParameterChain(name, param_list, lang, default_value))
@@ -94,5 +103,5 @@
 		}
 		// otherwise look to see if it is a text specific parameter
-		else if (name.equals(INDEX_SUBCOLLECTION_PARAM))
+		if (name.equals(INDEX_SUBCOLLECTION_PARAM))
 		{
 			Element index_sub_list = (Element) GSXML.getChildByTagName(this.config_info, INDEX_SUBCOLLECTION_ELEM + GSXML.LIST_MODIFIER);
@@ -137,7 +146,4 @@
 		}
 	else if (name.equals(CASE_PARAM) || name.equals(STEM_PARAM) || name.equals(ACCENT_PARAM)) {
-	  if (param_default == null) {
-	    param_default = BOOLEAN_PARAM_OFF;
-	  }
 	    String[] bool_ops = {"0", "1"};
 	    String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)}; 
@@ -146,7 +152,4 @@
 	    return true;
 	} else if (name.equals(MATCH_PARAM)) {
-	  if (param_default == null) {
-	    param_default = MATCH_PARAM_SOME;
-	  }
 	  
 	    String[] vals = {MATCH_PARAM_SOME, MATCH_PARAM_ALL };
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 28181)
@@ -102,11 +102,11 @@
 		// we have case folding on by default
 		if (this.does_case) {
-		  mgpp_src.setCase(case_default.equals(BOOLEAN_PARAM_ON) ? true : false);
+		  mgpp_src.setCase(paramDefaults.get(CASE_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
 		}
 		if (this.does_stem) {
-		  mgpp_src.setStem(stem_default.equals(BOOLEAN_PARAM_ON) ? true : false);
+		  mgpp_src.setStem(paramDefaults.get(STEM_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
 		}
 		if (this.does_accent) {
-		  mgpp_src.setAccentFold(accent_default.equals(BOOLEAN_PARAM_ON) ? true : false);
+		  mgpp_src.setAccentFold(paramDefaults.get(ACCENT_PARAM).equals(BOOLEAN_PARAM_ON) ? true : false);
 		}
 		// set up the query params
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 28181)
@@ -37,5 +37,7 @@
   extends GS2MGPPSearch {
    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
-  
+						
+  protected String default_max_docs = "-1";
+  protected String default_hits_per_page = "30";
     /** constructor */
     public GoogleNgramMGPPSearch(){
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java	(revision 28180)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/SharedSoleneGS2FieldSearch.java	(revision 28181)
@@ -46,6 +46,8 @@
 	protected SharedSoleneQuery solene_src = null;
 
+  
 	public SharedSoleneGS2FieldSearch()
 	{
+	  super();
 		// Lucene/Solr uses double operators, not single
 		AND_OPERATOR = "&&";
@@ -54,4 +56,5 @@
 		does_paging = true;
 		does_chunking = true;
+		paramDefaults.put(SORT_ORDER_PARAM, SORT_ORDER_DESCENDING);
 	}
 
@@ -67,5 +70,5 @@
 		Element config_search = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
 		Document owner = info.getOwnerDocument();
-		// get out the sort fields
+		// find the sort fields in serviceRack xml, and add in the deisplayItems if any
 		NodeList sort_nodes = info.getElementsByTagName(SORT_ELEM);
 
@@ -115,4 +118,5 @@
 	{
 		Element param = null;
+		String param_default = paramDefaults.get(name);
 		if (name.equals(RANK_PARAM))
 		{
@@ -120,13 +124,18 @@
 			ArrayList<String> fields = new ArrayList<String>();
 			ArrayList<String> field_names = new ArrayList<String>();
-			if (getSortData(fields, field_names, lang)) {
-
-			  param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
+			if (!getSortData(fields, field_names, lang)) {
+			  fields.add(RANK_PARAM_RANK);
+			  fields.add(RANK_PARAM_NONE);
+			  field_names.add(getTextString("param." + RANK_PARAM + "." + RANK_PARAM_RANK, lang));
+			  field_names.add(getTextString("param." + RANK_PARAM + "." + RANK_PARAM_NONE, lang));
 			}
+			
+			param = GSXML.createParameterDescription2(this.doc, name, getTextString("param." + name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, fields.get(0), fields, field_names);
+			
 		} else if (name.equals(SORT_ORDER_PARAM)) {
 	    String[] vals = { SORT_ORDER_ASCENDING, SORT_ORDER_DESCENDING };
 	    String[] vals_texts = { getTextString("param." + SORT_ORDER_PARAM + "." + SORT_ORDER_ASCENDING, lang), getTextString("param." + SORT_ORDER_PARAM + "." + SORT_ORDER_DESCENDING, lang) };
 
-	    param = GSXML.createParameterDescription(this.doc, SORT_ORDER_PARAM, getTextString("param." + SORT_ORDER_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, SORT_ORDER_ASCENDING, vals, vals_texts);
+	    param = GSXML.createParameterDescription(this.doc, SORT_ORDER_PARAM, getTextString("param." + SORT_ORDER_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, SORT_ORDER_DESCENDING, vals, vals_texts);
 	  }
 
