Index: main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java	(revision 30690)
+++ main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfigXMLReadWrite.java	(revision 30691)
@@ -397,8 +397,8 @@
 	}
 
-    	//This processes <sort> and <facet> subelements of <search> for a solr collection
-    // Note that GLI at present does not allow the user to set or modify the solr-specific elements 
-    // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such
-    // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
+  //This processes <sort> (lucene), or <sort> and <facet> (solr) subelements of <search> also <defaultSort>
+  // Note that GLI at present does not allow the user to set or modify these.
+  // This function, and its inverse convertSolrFacetsAndSorts, are only here to preserve such elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
+  // it just copies them into storage.
 	static private void doSolrFacetsAndSorts(Document to, Node searchNode)
 	{
@@ -410,70 +410,14 @@
 
 		NodeList sort_children = ((Element) searchNode).getElementsByTagName(StaticStrings.SORT_LOW_STR);//<sort>
+		
 		int num_nodes = sort_children.getLength();
 
-		for (int i = 0; i < num_nodes; i++)
-		{
-
-			Element sort_element = to.createElement(StaticStrings.SORT_ELEMENT);//<Sort>
-			Element e = (Element) sort_children.item(i);
-			String sort_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-			String sort_str_display = sort_str;//for creating collectionmetadata for this sort element
-
-			// Handling 'sort' element
-			sort_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, sort_str);
-			
-			Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort>
-
-			if(displayItem != null) {
-
-			    String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-			    String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);	    
-			    String value_str = XMLTools.getNodeText(displayItem);
-
-			    String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
-			    String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
-
-			    Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>!
-			    displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
-				if (name_str != null && !name_str.equals(""))
-				{
-					displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
-				}
-
-			        if (lang_str != null && !lang_str.equals(""))
-				{
-					displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
-				}
-				if (value_str != null && !value_str.equals(""))
-				{
-				    //XMLTools.setNodeText(displayItem_element, value_str);
-				    displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str);
-				}
-
-				if (!key_str.equals(""))
-				{
-				    displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
-				}
-				if (!dictionary_str.equals(""))
-				{
-				    displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary_str);
-				}
-
-				sort_element.appendChild(displayItem_element);
-
-			}
-
-			solr_element.appendChild(sort_element);
-
-			sort_element = null;
-
-			// Handling 'displayItem' element of this 'sort' element
-			// 'e' is the parent 'sort' element of 'displayItem' element
-			///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, sort_str_display);
-			///appendArrayList(toElement, collectionmetadata_list);
-
-		} // for loop on sort elements ends
-
+		for (int i = 0; i < num_nodes; i++) {
+		  solr_element.appendChild(to.importNode((Element) sort_children.item(i), true));
+		}
+		Element sort_def = (Element)XMLTools.getChildByTagName(searchNode, StaticStrings.SORT_DEFAULT_ELEMENT);
+		if (sort_def != null) {
+		  solr_element.appendChild(to.importNode(sort_def, true));
+		}
 
 		NodeList facet_children = ((Element) searchNode).getElementsByTagName(StaticStrings.FACET_LOW_STR);//facet
@@ -482,67 +426,11 @@
 		for (int i = 0; i < num_nodes; i++)
 		{
-
-			Element facet_element = to.createElement(StaticStrings.FACET_ELEMENT);//<Facet>
-			Element e = (Element) facet_children.item(i);
-			String facet_str = e.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-			String facet_str_display = facet_str;//for creating collectionmetadata for this facet
-
-			// Handling 'facet' element
-			facet_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, facet_str);
-			
-			Element displayItem = (Element) XMLTools.getChildByTagName(e, StaticStrings.DISPLAYITEM_STR); // gets the first <displayItem> child of <sort>
-
-			if(displayItem != null) {
-			    String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-			    String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);
-			    String value_str = XMLTools.getNodeText(displayItem);
-			    
-			    String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);
-			    String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
-
-			    Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_ELEMENT); // <DisplayItem> not <displayItem>!
-			    displayItem_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
-			    
-				if (name_str != null && !name_str.equals(""))
-				{
-					displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
-				}
-
-			        if (lang_str != null && !lang_str.equals(""))
-				{
-					displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
-				}
-				if (value_str != null && !value_str.equals(""))
-				{
-				    //XMLTools.setNodeText(displayItem_element, value_str);
-				    displayItem_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, value_str);
-				}
-
-				if (!key_str.equals(""))
-				{
-				    displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
-				}
-				if (!dictionary_str.equals(""))
-				{
-				    displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, dictionary_str);
-				}
-				facet_element.appendChild(displayItem_element);
-
-			}
-			solr_element.appendChild(facet_element);
-
-			facet_element = null;
-
-			// Handling 'displayItem' element of this 'facet' element
-			// 'e' is the parent 'facet' element of 'displayItem' element
-			///ArrayList collectionmetadata_list = doDisplayItemList(to, e, StaticStrings.NAME_ATTRIBUTE, facet_str_display);
-			///appendArrayList(toElement, collectionmetadata_list);
-
-		} // for loop on facet elements ends
+		  solr_element.appendChild(to.importNode((Element) facet_children.item(i), true));
+		}
 
 		// finished processing sort and facet elements
 		toElement.appendChild(solr_element);
 
+	
 	}
 
@@ -2336,10 +2224,12 @@
 	}
 
-    	//convert <facet> and <sort> elements and their displayItem subelements, 
+    	//convert <facet> and <sort> and <defaultSort> elements 
         //which go in 'search' element in collectionConfig.xml
 	//parameter 'to' is the document to be saved as collectionConfig.xml
 	//parameter 'from' is the internal xml structure
+  // for lucene and solr collections
+  // just a straight copy at present
     // Note that GLI at present does not allow the user to set or modify the solr-specific elements 
-    // <sort> and <facet>. This function, and its inverse convertSolrFacetsAndSorts, is only here to preserve such
+    // <sort> and <facet>. This function, and its inverse doSolrFacetsAndSorts, is only here to preserve such
     // elements if they already exist in the collectionConfig.xml. At present they need to be manually added there.
 	static private void convertSolrFacetsAndSorts(Document from, Document to)
@@ -2349,133 +2239,33 @@
 		Element search = (Element) XMLTools.getChildByTagName(to.getDocumentElement(), StaticStrings.SEARCH_STR);
 
-		//There are two sets of <Solr> elements, find the one which is assigned 'true'
+		//There are two sets of <Solr> elements, find the one which is assigned 'true'   ---  is this true???
 		Element solr = XMLTools.getNamedElement(source, StaticStrings.SOLR_ELEMENT, StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
 		if (solr == null)
 		{
-			return;
-		}
-		NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_ELEMENT); //<Sort>
+		  return;
+		}
+		NodeList sort_elements = solr.getElementsByTagName(StaticStrings.SORT_LOW_STR);
 		int sort_elements_length = sort_elements.getLength();
-		NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_ELEMENT); //<Facet>
+
+		for (int j = 0; j < sort_elements_length; j++)
+		{
+		  Element sort_ele = (Element) sort_elements.item(j);
+		  search.appendChild(to.importNode(sort_ele, true));
+		}
+		Element sort_def = (Element)XMLTools.getChildByTagName(solr, StaticStrings.SORT_DEFAULT_ELEMENT);
+		if (sort_def != null) {
+		  search.appendChild(to.importNode(sort_def, true));
+		}
+		NodeList facet_elements = solr.getElementsByTagName(StaticStrings.FACET_LOW_STR); 
 		int facet_elements_length = facet_elements.getLength();
-
-		for (int j = 0; j < sort_elements_length; j++)
-		{
-			Element sort_element = (Element) sort_elements.item(j);
-			if (sort_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR))
-			{
-				continue;
-			}
-
-			Element sort_ele = to.createElement(StaticStrings.SORT_LOW_STR);//<sort>
-			String name_attr = sort_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-			/*if (name_attr.startsWith(StaticStrings.EXTRACTED_NAMESPACE) && name_attr.indexOf(StaticStrings.NS_SEP, StaticStrings.EXTRACTED_NAMESPACE.length()) == -1)
-			    {
-				name_attr = name_str.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
-			    }
-			*/
-			sort_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr);
-
-			// Now constructing 'displayItem' element for this 'sort_ele' element
-			Element displayItem = (Element) XMLTools.getChildByTagName(sort_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Sort>
-
-			if(displayItem != null) {
-			    if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) {
-				Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem>
-				
-				String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-				String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);	
-				String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE);
-
-				String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);	
-				String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
-
-				if (name_str != null && !name_str.equals(""))
-				    {
-					displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
-				    }
-				
-				if (lang_str != null && !lang_str.equals(""))
-				    {
-					displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
-				    }
-				if (value_str != null && !value_str.equals(""))
-				    {
-					XMLTools.setNodeText(displayItem_element, value_str);
-				    }
-
-				if(!key_str.equals("")) {
-				    displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
-				}
-				if(!dictionary_str.equals("")) {
-				    displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, key_str);
-				}
-
-				sort_ele.appendChild(displayItem_element);
-			    }
-			}
-
-			search.appendChild(sort_ele);
-
-		} //for loop on sort_elements ends
-
 		for (int j = 0; j < facet_elements_length; j++)
-		{
-			Element facet_element = (Element) facet_elements.item(j);
-			if (facet_element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR))
-			{
-				continue;
-			}
-
-			Element facet_ele = to.createElement(StaticStrings.FACET_LOW_STR);//<facet>
-			String name_attr = facet_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-
-			facet_ele.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_attr);
-
-			// Now constructing 'displayItem' element for this 'facet_ele' element
-			Element displayItem = (Element) XMLTools.getChildByTagName(facet_element, StaticStrings.DISPLAYITEM_ELEMENT); // gets the first <DisplayItem> (not <displayItem>!) child of <Facet>
-			
-			if(displayItem != null) {
-			    if (displayItem.hasAttribute(StaticStrings.ASSIGNED_ATTRIBUTE) && displayItem.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR)) {
-				Element displayItem_element = to.createElement(StaticStrings.DISPLAYITEM_STR);//<displayItem>
-
-				String name_str = displayItem.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-				
-				String lang_str = displayItem.getAttribute(StaticStrings.LANG_ATTRIBUTE);
-				String value_str = displayItem.getAttribute(StaticStrings.VALUE_ATTRIBUTE);
-
-				String key_str = displayItem.getAttribute(StaticStrings.KEY_ATTRIBUTE);	
-				String dictionary_str = displayItem.getAttribute(StaticStrings.DICTIONARY_ATTRIBUTE);
-
-				if (lang_str != null && !lang_str.equals(""))
-				    {
-					displayItem_element.setAttribute(StaticStrings.LANG_ATTRIBUTE, lang_str);
-				    }
-				if (name_str != null && !name_str.equals(""))
-				    {
-					displayItem_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name_str);
-				    }
-				if (value_str != null && !value_str.equals(""))
-				{
-				    XMLTools.setNodeText(displayItem_element, value_str);				    
-				}
-
-				if(!key_str.equals("")) {
-				    displayItem_element.setAttribute(StaticStrings.KEY_ATTRIBUTE, key_str);
-				}
-				if(!dictionary_str.equals("")) {
-				    displayItem_element.setAttribute(StaticStrings.DICTIONARY_ATTRIBUTE, key_str);
-				}
-				facet_ele.appendChild(displayItem_element);
-			    }
-			}
-
-			search.appendChild(facet_ele);
-
-		} //for loop on facet_elements ends
-
-	}
+		  {
+		    Element facet_ele = (Element) facet_elements.item(j);
+		    search.appendChild(to.importNode(facet_ele, true));
+		  }
+
+	
+	}
+
 
 	// Convert levels for mgpp/lucene. This method is called by converIndex() when mgpp indexer is detected.
