Index: main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.cpp	(revision 27064)
+++ main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.cpp	(revision 27064)
@@ -0,0 +1,110 @@
+/**********************************************************************
+ *
+ * fieldedqueryfilter.cpp -- 
+ * Copyright (C) 1999  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+#include "fieldedqueryfilter.h"
+
+fieldedqueryfilterclass::fieldedqueryfilterclass () 
+  : queryfilterclass() {
+
+  FilterOption_t filtopt;
+  
+  // -- onePerTerm  Level          enumerated
+  // likely to be Doc, Sec, Para, but we dont assume anything now
+  filtopt.clear();
+  filtopt.name = "Level";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Level"] = filtopt;
+
+  // --  IndexField, enumerated, used to list available fields
+  filtopt.clear();
+  filtopt.name = "IndexField";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["IndexField"] = filtopt;
+
+}
+
+void fieldedqueryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  queryfilterclass::configure(key, cfgline);
+
+  if (key == "indexfieldmap") {
+    indexfieldmap.importmap (cfgline);
+    text_tarray options;
+    indexfieldmap.gettoarray (options);
+    filterOptions["IndexField"].validValues = options;
+    
+  } else if (key == "levelmap") {
+    levelmap.importmap (cfgline);
+  } else if (key == "indexlevels") {
+    filterOptions["Level"].validValues.erase(filterOptions["Level"].validValues.begin(), filterOptions["Level"].validValues.end());
+    text_tarray::const_iterator here = cfgline.begin();
+    text_tarray::const_iterator end = cfgline.end();
+    while (here != end) {
+      if (!(*here).empty()) {
+	filterOptions["Level"].validValues.push_back(*here);
+      }
+      ++here;
+    }
+  } else if (key == "defaultindex") { // used for fields 
+    indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
+  } else if (key == "defaultlevel") { 
+    levelmap.from2to (cfgline[0], filterOptions["Level"].defaultValue);
+  }
+  
+}
+
+fieldedqueryfilterclass::~fieldedqueryfilterclass () {
+}
+
+bool fieldedqueryfilterclass::init (ostream &logout) {
+
+  if (!queryfilterclass::init(logout)) {
+    return false;
+  }
+  
+  if (filterOptions["IndexField"].defaultValue.empty()) {
+    // use first index in map as default if no default is set explicitly
+    text_tarray fromarray;
+    indexfieldmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["IndexField"].defaultValue = fromarray[0];
+    }
+  }
+  if (filterOptions["Levels"].defaultValue.empty()) {
+    // use first level as default if no default is set explicitly
+    if (!filterOptions["Level"].validValues[0].empty())
+      filterOptions["Levels"].defaultValue = filterOptions["Level"].validValues[0];
+  }
+
+  return true;
+}
+
+//whether a query is a full text browse
+bool fieldedqueryfilterclass::full_text_browse (int filterRequestOptions) {
+  return (filterRequestOptions & FRfullTextBrowse);
+}
Index: main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.h	(revision 27064)
+++ main/trunk/greenstone2/runtime-src/src/colservr/fieldedqueryfilter.h	(revision 27064)
@@ -0,0 +1,71 @@
+/**********************************************************************
+ *
+ * queryfilter.h -- abstract base class for fielded queryfilters
+ *         mgppqueryfilter and lucenequeryfilter 
+ *          implement this
+ * Copyright (C) 2013  The New Zealand Digital Library Project
+ *
+ * A component of the Greenstone digital library software
+ * from the New Zealand Digital Library Project at the
+ * University of Waikato, New Zealand.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *********************************************************************/
+
+
+#ifndef FIELDEDQUERYFILTER_H
+#define FIELDEDQUERYFILTER_H
+
+
+#include "queryfilter.h"
+
+
+class fieldedqueryfilterclass : public queryfilterclass {
+protected:
+
+  stringmap indexfieldmap;
+  stringmap levelmap;
+
+  bool full_text_browse (int filterRequestOptions);
+
+  // do query that might involve multiple sub queries
+  // textsearchptr and db_ptr are assumed to be valid
+  virtual void do_multi_query (const FilterRequest_t &request,
+		       const vector<queryparamclass> &query_params,
+		       queryresultsclass &multiresults,
+		       comerror_t &err, ostream &logout)=0;
+
+public:
+  fieldedqueryfilterclass ();
+  virtual ~fieldedqueryfilterclass ();
+
+  void configure (const text_t &key, const text_tarray &cfgline);
+  bool init (ostream &logout);
+
+  void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout)=0;
+
+  void browsefilter(const FilterRequest_t &request,
+		    FilterResponse_t &response,
+		    comerror_t &err, ostream &logout);  
+
+
+};
+
+
+#endif
+
Index: main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.cpp	(revision 27064)
@@ -28,32 +28,43 @@
 #include "lucenesearch.h"
 
-/////////////////////////////////
-// functions for queryfilterclass
-/////////////////////////////////
-
-
 lucenequeryfilterclass::lucenequeryfilterclass () 
-  : queryfilterclass() {
+  : fieldedqueryfilterclass() {
 
   
   FilterOption_t filtopt;
   
-  // -- onePerTerm  Level          enumerated
-  // likely to be Doc, Sec, Para, but we dont assume anything now
+  // -- onePerQuery SortField, enumerated, used to list available sorting fields
   filtopt.clear();
-  filtopt.name = "Level";
+  filtopt.name = "SortField";
   filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
   filtopt.defaultValue = "";
-  filterOptions["Level"] = filtopt;
-
-  // --  IndexField, enumerated, used to list available fields
+  filterOptions["SortField"] = filtopt;
+
+  // -- onePerQuery SortOder      enumerated (0=ascending, 1=descending)
   filtopt.clear();
-  filtopt.name = "IndexField";
+  filtopt.name = "SortOrder";
   filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "ascending";
+  filtopt.validValues.push_back("ascending");
+  filtopt.validValues.push_back("descending");
+  filterOptions["SortOrder"] = filtopt;
+
+  // -- onePerQuery Fuzziness string 0.0-1.0
+  filtopt.clear();
+  filtopt.name = "Fuzziness";
+  filtopt.type = FilterOption_t::stringt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
   filtopt.defaultValue = "";
-  filterOptions["IndexField"] = filtopt;
-
+  filterOptions["Fuzziness"] = filtopt;
+
+ // -- onePerQuery FilterString  string
+  filtopt.clear();
+  filtopt.name = "FilterString";
+  filtopt.type = FilterOption_t::stringt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "";
+  filterOptions["FilterString"] = filtopt;
 }
 
@@ -62,62 +73,40 @@
 
 
-//whether a query is a full text browse
-bool lucenequeryfilterclass::full_text_browse (int filterRequestOptions) {
-  return (filterRequestOptions & FRfullTextBrowse);
-}
 
 void lucenequeryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
-  queryfilterclass::configure(key, cfgline);
-
-  if (key == "indexfieldmap") {
-    indexfieldmap.importmap (cfgline);
-    
-    // update the list of indexes in the filter information
-    text_tarray options;
-    indexfieldmap.gettoarray (options);
-    filterOptions["IndexField"].validValues = options;
-  } else if (key == "levelmap") {
-    levelmap.importmap (cfgline);
-  } else if (key == "indexlevels") {
-    text_tarray::const_iterator here = cfgline.begin();
-    text_tarray::const_iterator end = cfgline.end();
-    while (here != end) {
-      if (!(*here).empty()) {
-	filterOptions["Level"].validValues.push_back(*here);
-      }
-      ++here;
-    }
-  } else if (key == "textlevel") {
-      ((lucenesearchclass *)textsearchptr)->set_text_level(cfgline[0]);
-  } else if (key == "defaultindex") { 
-    indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
-  } else if (key == "defaultlevel") { 
-    levelmap.from2to (cfgline[0], filterOptions["Level"].defaultValue);
-  }
-  
+  fieldedqueryfilterclass::configure(key, cfgline);
+
+  if (key == "textlevel") {
+    ((lucenesearchclass *)textsearchptr)->set_text_level(cfgline[0]);
+  }
 }
 
 bool lucenequeryfilterclass::init (ostream &logout) {
   
-  if (!queryfilterclass::init(logout)) {
+  if (!fieldedqueryfilterclass::init(logout)) {
     return false;
   }
   
-  if (filterOptions["IndexField"].defaultValue.empty()) {
-    // use first index in map as default if no default is set explicitly
-    text_tarray fromarray;
-    indexfieldmap.getfromarray(fromarray);
-    if (fromarray.size()) {
-      filterOptions["IndexField"].defaultValue = fromarray[0];
-    }
-  }
-  if (filterOptions["Levels"].defaultValue.empty()) {
-    // use first level as default if no default is set explicitly
-    if (!filterOptions["Level"].validValues[0].empty())
-      filterOptions["Levels"].defaultValue = filterOptions["Level"].validValues[0];
-  }
-
+  text_tarray field_array;
+  indexfieldmap.gettoarray(field_array);
+  for (int i=0; i<field_array.size(); i++) {
+    text_t field = field_array[i];
+    if (field!="ZZ" && field !="ZZ") {
+      filterOptions["SortField"].validValues.push_back("by"+field);
+    }
+  }
   return true;
 }
+
+void lucenequeryfilterclass::set_queryparam_defaults(queryparamclass &query ) {
+
+  fieldedqueryfilterclass::set_queryparam_defaults(query);
+  query.filterstring = filterOptions["FilterString"].defaultValue;  
+  query.sortfield = filterOptions["SortField"].defaultValue;
+  query.sortorder = (filterOptions["SortOrder"].defaultValue == "descending");
+  query.fuzziness = filterOptions["Fuzziness"].defaultValue;  
+
+}
+
 
 void lucenequeryfilterclass::filter(const FilterRequest_t &request,
@@ -160,8 +149,7 @@
   // get the query parameters
   int startresults, endresults;
-  text_t phrasematch; // not used here any more
   vector<queryparamclass> queryfilterparams;
   parse_query_params (request, queryfilterparams, startresults, 
-		      endresults, phrasematch, logout);  
+		      endresults, logout);  
  
    
@@ -258,10 +246,8 @@
   // get the query parameters
   int startresults, endresults;
-  text_t phrasematch; // not used here any more, just have it so can use
-                      // parse_query_params function
   
   vector<queryparamclass> queryfilterparams;
   parse_query_params (request, queryfilterparams, startresults, 
-		      endresults, phrasematch, logout);  
+		      endresults, logout);  
 
   vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
@@ -392,3 +378,2 @@
 
 
-
Index: main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.h	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/lucenequeryfilter.h	(revision 27064)
@@ -30,13 +30,9 @@
 #define LUCENEQUERYFILTER_H
 
-#include "queryfilter.h"
+#include "fieldedqueryfilter.h"
 
-class lucenequeryfilterclass : public queryfilterclass {
+class lucenequeryfilterclass : public fieldedqueryfilterclass {
 protected:
 
-  stringmap indexfieldmap;
-  stringmap levelmap;
-
-  bool full_text_browse (int filterRequestOptions);
 
   // mgsearchptr and db_ptr are assumed to be valid
@@ -46,4 +42,5 @@
 		       comerror_t &err, ostream &logout);
 
+  void set_queryparam_defaults(queryparamclass &query );
 
 public:
Index: main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.cpp	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.cpp	(revision 27064)
@@ -1,5 +1,5 @@
 /**********************************************************************
  *
- * queryfilter.cpp -- 
+ * mgppqueryfilter.cpp -- 
  * Copyright (C) 1999  The New Zealand Digital Library Project
  *
@@ -28,31 +28,6 @@
 #include "mgppsearch.h"
 
-/////////////////////////////////
-// functions for queryfilterclass
-/////////////////////////////////
-
-
 mgppqueryfilterclass::mgppqueryfilterclass () 
-  : queryfilterclass() {
-
-  
-  FilterOption_t filtopt;
-  
-  // -- onePerTerm  Level          enumerated
-  // likely to be Doc, Sec, Para, but we dont assume anything now
-  filtopt.clear();
-  filtopt.name = "Level";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["Level"] = filtopt;
-
-  // --  IndexField, enumerated, used to list available fields
-  filtopt.clear();
-  filtopt.name = "IndexField";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["IndexField"] = filtopt;
+  : fieldedqueryfilterclass() {
 
 }
@@ -62,63 +37,13 @@
 
 
-//whether a query is a full text browse
-bool mgppqueryfilterclass::full_text_browse (int filterRequestOptions) {
-  return (filterRequestOptions & FRfullTextBrowse);
-}
 
 void mgppqueryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
-  queryfilterclass::configure(key, cfgline);
-
-  if (key == "indexfieldmap") {
-    indexfieldmap.importmap (cfgline);
-    text_tarray options;
-    indexfieldmap.gettoarray (options);
-    filterOptions["IndexField"].validValues = options;
-    
-  } else if (key == "levelmap") {
-    levelmap.importmap (cfgline);
-  } else if (key == "indexlevels") {
-    filterOptions["Level"].validValues.erase(filterOptions["Level"].validValues.begin(), filterOptions["Level"].validValues.end());
-    text_tarray::const_iterator here = cfgline.begin();
-    text_tarray::const_iterator end = cfgline.end();
-    while (here != end) {
-      if (!(*here).empty()) {
-	filterOptions["Level"].validValues.push_back(*here);
-      }
-      ++here;
-    }
-  } else if (key == "textlevel") {
-      ((mgppsearchclass *)textsearchptr)->set_text_level(cfgline[0]);
+  fieldedqueryfilterclass::configure(key, cfgline);
+
+  if (key == "textlevel") {
+    ((mgppsearchclass *)textsearchptr)->set_text_level(cfgline[0]);
   } else if (key == "indexstem") {
     ((mgppsearchclass *)textsearchptr)->set_indexstem (cfgline[0]);
-  } else if (key == "defaultindex") { // used for fields in mgpp
-    indexfieldmap.from2to (cfgline[0], filterOptions["IndexField"].defaultValue);
-  } else if (key == "defaultlevel") { 
-    levelmap.from2to (cfgline[0], filterOptions["Level"].defaultValue);
-  }
-  
-}
-
-bool mgppqueryfilterclass::init (ostream &logout) {
-  
-  if (!queryfilterclass::init(logout)) {
-    return false;
-  }
-  
-  if (filterOptions["IndexField"].defaultValue.empty()) {
-    // use first index in map as default if no default is set explicitly
-    text_tarray fromarray;
-    indexfieldmap.getfromarray(fromarray);
-    if (fromarray.size()) {
-      filterOptions["IndexField"].defaultValue = fromarray[0];
-    }
-  }
-  if (filterOptions["Levels"].defaultValue.empty()) {
-    // use first level as default if no default is set explicitly
-    if (!filterOptions["Level"].validValues[0].empty())
-      filterOptions["Levels"].defaultValue = filterOptions["Level"].validValues[0];
-  }
-
-  return true;
+  }
 }
 
@@ -163,8 +88,7 @@
   // get the query parameters
   int startresults, endresults;
-  text_t phrasematch; // not used here any more
   vector<queryparamclass> queryfilterparams;
   parse_query_params (request, queryfilterparams, startresults, 
-		      endresults, phrasematch, logout);  
+		      endresults, logout);  
  
    
@@ -261,10 +185,7 @@
   // get the query parameters
   int startresults, endresults;
-  text_t phrasematch; // not used here any more, just have it so can use
-                      // parse_query_params function
-  
   vector<queryparamclass> queryfilterparams;
   parse_query_params (request, queryfilterparams, startresults, 
-		      endresults, phrasematch, logout);  
+		      endresults, logout);  
 
     vector<queryparamclass>::const_iterator query_here = queryfilterparams.begin();
Index: main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.h	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/mgppqueryfilter.h	(revision 27064)
@@ -29,14 +29,10 @@
 #define MGPPQUERYFILTER_H
 
-#include "queryfilter.h"
+#include "fieldedqueryfilter.h"
 
 
-class mgppqueryfilterclass : public queryfilterclass {
+class mgppqueryfilterclass : public fieldedqueryfilterclass {
 protected:
 
-  stringmap indexfieldmap;
-  stringmap levelmap;
-
-  bool full_text_browse (int filterRequestOptions);
 
   // textsearchptr and db_ptr are assumed to be valid
@@ -52,5 +48,5 @@
 
   void configure (const text_t &key, const text_tarray &cfgline);
-  bool init (ostream &logout);
+  //  bool init (ostream &logout);
   void filter (const FilterRequest_t &request,
 		       FilterResponse_t &response,
Index: main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.cpp	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.cpp	(revision 27064)
@@ -285,4 +285,16 @@
 
   num_phrases = 0;
+
+  FilterOption_t filtopt;
+  // -- onePerQuery  PhraseMatch  enumerated
+  filtopt.name = "PhraseMatch";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "some_phrases";
+  filtopt.validValues.push_back ("all_phrases");
+  filtopt.validValues.push_back ("some_phrases");
+  filtopt.validValues.push_back ("all_docs");
+  filterOptions["PhraseMatch"] = filtopt;
+
 }
 
@@ -331,6 +343,6 @@
 		      endresults, phrasematch, logout);
   // do any mg specific diddling with query parameters that may be required
-  mg_parse_query_params (request, queryfilterparams, startresults, 
-			 endresults, phrasematch, logout);
+  //  mg_parse_query_params (request, queryfilterparams, startresults, 
+  //			 endresults, phrasematch, logout);
 
 
@@ -448,10 +460,24 @@
 }
 
-void mgqueryfilterclass::mg_parse_query_params (const FilterRequest_t &/*request*/,
+void mgqueryfilterclass::parse_query_params (const FilterRequest_t &request,
 						vector<queryparamclass> &query_params,
-						int &/*startresults*/, int &/*endresults*/,
-						text_t &/*phrasematch*/, ostream &/*logout*/) {
-
-  //  outconvertclass text_t2ascii;
+						int &startresults, int &endresults,
+						text_t &phrasematch, ostream &logout) {
+
+  queryfilterclass::parse_query_params (request, query_params, 
+					startresults, endresults, logout);
+
+  phrasematch = filterOptions["PhraseMatch"].defaultValue;
+
+  // is there a better way to do this than iterate through all the options again??
+  OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
+  OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
+  while (options_here != options_end) {
+    if ((*options_here).name == "PhraseMatch") {
+      phrasematch = (*options_here).value;
+      break;
+    }
+    ++options_here;
+  }
   
   vector<queryparamclass>::iterator query_here = query_params.begin();
Index: main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.h	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/mgqueryfilter.h	(revision 27064)
@@ -69,8 +69,8 @@
 				 docresultsclass &docs);
 
-  virtual void mg_parse_query_params (const FilterRequest_t &request,
-				      vector<queryparamclass> &query_params,
-				      int &startresults, int &endresults,
-				      text_t &phrasematch, ostream &logout);
+  void parse_query_params (const FilterRequest_t &request,
+			   vector<queryparamclass> &query_params,
+			   int &startresults, int &endresults,
+			   text_t &phrasematch, ostream &logout);
 
   
Index: main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.cpp	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.cpp	(revision 27064)
@@ -28,32 +28,4 @@
 
 
-// translate will return true if successful
-bool queryfilterclass::translate (dbclass *db_ptr, text_t& docnum, text_t &trans_OID) {
-  infodbclass info;
-
-  trans_OID.clear();
-
-  // get the info
-  if (db_ptr == NULL) return false;
-  if (!db_ptr->getinfo(docnum, info)) return false;
-
-  // translate
-  if (info["section"].empty()) return false;
-
-  trans_OID = info["section"];
-  return true;
-}
-
-
-// whether document results are needed
-bool queryfilterclass::need_matching_docs (int filterResultOptions) {
-  return ((filterResultOptions & FROID) || (filterResultOptions & FRranking) ||
-	  (filterResultOptions & FRmetadata));
-}
-
-// whether term information is needed
-bool queryfilterclass::need_term_info (int filterResultOptions) {
-  return ((filterResultOptions & FRtermFreq) || (filterResultOptions & FRmatchTerms));
-}
 
 /////////////////////////////////
@@ -61,20 +33,236 @@
 /////////////////////////////////
 
-// get the query parameters
-void queryfilterclass::parse_query_params (const FilterRequest_t &request,
-					   vector<queryparamclass> &query_params,
-					   int &startresults, int &endresults,
-					   text_t &phrasematch, ostream &logout) {
+
+queryfilterclass::queryfilterclass () {
+  db_ptr = NULL;
+  textsearchptr = NULL;
+  maxnumeric = 4;
+
+  FilterOption_t filtopt;
+  filtopt.name = "CombineQuery";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "and";
+  filtopt.validValues.push_back("and");
+  filtopt.validValues.push_back("or");
+  filtopt.validValues.push_back("not");
+  filterOptions["CombineQuery"] = filtopt;
+
+  // -- onePerQuery StartResults   integer
+  filtopt.clear();
+  filtopt.name = "StartResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "1";
+  filtopt.validValues.push_back("1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["StartResults"] = filtopt;
+
+  // -- onePerQuery EndResults     integer
+  filtopt.clear();
+  filtopt.name = "EndResults";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "10";
+  filtopt.validValues.push_back("-1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["EndResults"] = filtopt;
+
+  // -- onePerQuery QueryType      enumerated (boolean, ranked)
+  filtopt.clear();
+  filtopt.name = "QueryType";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "ranked";
+  filtopt.validValues.push_back("boolean");
+  filtopt.validValues.push_back("ranked");
+  filterOptions["QueryType"] = filtopt;
+
+  // -- onePerQuery MatchMode      enumerated (some, all)
+  filtopt.clear();
+  filtopt.name = "MatchMode";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "some";
+  filtopt.validValues.push_back("some");
+  filtopt.validValues.push_back("all");
+  filterOptions["MatchMode"] = filtopt;
+
+  // -- onePerTerm  Term           string ???
+  filtopt.clear();
+  filtopt.name = "Term";
+  filtopt.type = FilterOption_t::stringt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Term"] = filtopt;
+
+  // -- onePerTerm  Casefold       boolean
+  filtopt.clear();
+  filtopt.name = "Casefold";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "true";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["Casefold"] = filtopt;
+
+  // -- onePerTerm  Stem           boolean
+  filtopt.clear();
+  filtopt.name = "Stem";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "false";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["Stem"] = filtopt;
+
+  // -- onePerTerm  AccentFold           boolean
+  filtopt.clear();
+  filtopt.name = "AccentFold";
+  filtopt.type = FilterOption_t::booleant;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "false";
+  filtopt.validValues.push_back("false");
+  filtopt.validValues.push_back("true");
+  filterOptions["AccentFold"] = filtopt;
+  
+  // -- onePerTerm  Index          enumerated
+  filtopt.clear();
+  filtopt.name = "Index";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Index"] = filtopt;
+
+  // -- onePerTerm  Subcollection  enumerated
+  filtopt.clear();
+  filtopt.name = "Subcollection";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Subcollection"] = filtopt;
+
+  // -- onePerTerm  Language  enumerated
+  filtopt.clear();
+  filtopt.name = "Language";
+  filtopt.type = FilterOption_t::enumeratedt;
+  filtopt.repeatable = FilterOption_t::onePerTerm;
+  filtopt.defaultValue = "";
+  filterOptions["Language"] = filtopt;
+
+  // -- onePerQuery  Maxdocs  integer
+  filtopt.clear();
+  filtopt.name = "Maxdocs";
+  filtopt.type = FilterOption_t::integert;
+  filtopt.repeatable = FilterOption_t::onePerQuery;
+  filtopt.defaultValue = "200";
+  filtopt.validValues.push_back("-1");
+  filtopt.validValues.push_back("1000");
+  filterOptions["Maxdocs"] = filtopt;
+
+}
+
+queryfilterclass::~queryfilterclass () {
+  // don't delete db_ptr or textsearchptr here, they'll be cleaned up by the source
+}
+
+void queryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
+  filterclass::configure (key, cfgline);
+
+  if (key == "indexmap") {
+    indexmap.importmap (cfgline);
+    
+    // update the list of indexes in the filter information
+    text_tarray options;
+    indexmap.gettoarray (options);
+    filterOptions["Index"].validValues = options;
+
+  } else if (key == "defaultindex") {
+    indexmap.from2to (cfgline[0], filterOptions["Index"].defaultValue);
+
+  } else if (key == "subcollectionmap") {
+    subcollectionmap.importmap (cfgline);
+
+    // update the list of subcollections in the filter information
+    text_tarray options;
+    subcollectionmap.gettoarray (options);
+    filterOptions["Subcollection"].validValues = options;
+
+  } else if (key == "defaultsubcollection") {
+    subcollectionmap.from2to (cfgline[0], filterOptions["Subcollection"].defaultValue);
+
+  } else if (key == "languagemap") {
+    languagemap.importmap (cfgline);
+
+    // update the list of languages in the filter information
+    text_tarray options;
+    languagemap.gettoarray (options);
+    filterOptions["Language"].validValues = options;
+
+  } else if (key == "defaultlanguage") {
+    languagemap.from2to (cfgline[0], filterOptions["Language"].defaultValue);
+  } else if (key == "indexstem") {
+    indexstem = cfgline[0];
+  } else if (key == "maxnumeric") {
+    maxnumeric = cfgline[0].getint();
+  }
+  
+}
+
+bool queryfilterclass::init (ostream &logout) {
   outconvertclass text_t2ascii;
 
-  // set defaults for the return parameters
-  query_params.erase(query_params.begin(), query_params.end());
-  startresults = filterOptions["StartResults"].defaultValue.getint();
-  endresults = filterOptions["EndResults"].defaultValue.getint();
-  phrasematch = filterOptions["PhraseMatch"].defaultValue;
-
-  // set defaults for query parameters
-  queryparamclass query;
-  query.combinequery = "or"; // first one must be "or"
+  if (!filterclass::init(logout)) return false;
+
+  if (filterOptions["Index"].defaultValue.empty()) {
+    // use first index in map as default if no default is set explicitly
+    text_tarray fromarray;
+    indexmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Index"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (filterOptions["Subcollection"].defaultValue.empty()) {
+    // use first subcollection in map as default if no default is set explicitly
+    text_tarray fromarray;
+    subcollectionmap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Subcollection"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (filterOptions["Language"].defaultValue.empty()) {
+    // use first language in map as default if no default is set explicitly
+    text_tarray fromarray;
+    languagemap.getfromarray(fromarray);
+    if (fromarray.size()) {
+      filterOptions["Language"].defaultValue = fromarray[0];
+    }
+  }
+
+  if (db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: queryfilter contains a null dbclass\n\n";
+    return false;
+  }
+
+  // get the filename for the database and make sure it exists
+  if (indexstem.empty()) {
+    indexstem = collection;
+  }
+  db_filename = resolve_db_filename(indexstem,db_ptr->getfileextension());
+  if (!file_exists(db_filename)) {
+    logout << text_t2ascii
+	   << "warning: database \"" << db_filename << "\" does not exist\n\n";
+    //return false;
+  }
+
+  return true;
+}
+
+void queryfilterclass::set_queryparam_defaults(queryparamclass &query ) {
+  
   query.collection = collection;
   query.index = filterOptions["Index"].defaultValue;
@@ -89,8 +277,61 @@
   query.maxdocs = filterOptions["Maxdocs"].defaultValue.getint();
   query.level = filterOptions["Level"].defaultValue;
-  query.filterstring = filterOptions["FilterString"].defaultValue;  // Lucene specific
-  query.sortfield = filterOptions["SortField"].defaultValue;  // Lucene specific
-  query.fuzziness = filterOptions["Fuzziness"].defaultValue;  // Lucene specific
   query.maxnumeric = maxnumeric;
+
+}
+
+bool queryfilterclass::set_queryparam_field(OptionValue_t option, queryparamclass &query) {
+
+if (option.name == "QueryType") {
+      query.search_type = (option.value == "ranked");
+    } else if (option.name == "MatchMode") {
+      query.match_mode = (option.value == "all");
+      if (query.match_mode == 1) query.maxdocs = -1;
+    } else if (option.name == "Term") {
+      query.querystring = option.value;
+    } else if (option.name == "Casefold") {
+      query.casefolding = (option.value == "true");
+    } else if (option.name == "Stem") {
+      query.stemming = (option.value == "true");
+    } else if (option.name == "AccentFold") {
+      query.accentfolding = (option.value == "true");
+    } else if (option.name == "Index"&& option.value !="") {
+      query.index = option.value;
+    } else if (option.name == "Subcollection") {
+      query.subcollection = option.value;
+    } else if (option.name == "Language") {
+      query.language = option.value;
+    } else if (option.name == "Maxdocs") {
+      query.maxdocs = option.value.getint();
+    // } else if (option.name == "PhraseMatch") {
+    //   phrasematch = option.value;
+    } else if (option.name == "Level") {
+      query.level = option.value;
+    } else if (option.name == "FilterString") {
+      query.filterstring = option.value;
+    } else if (option.name == "SortField") {
+      query.sortfield = option.value;
+    } else if (option.name == "SortOrder") {
+      query.sortorder = (option.value == "descending");
+    } else if (option.name == "Fuzziness") {
+      query.fuzziness = option.value;
+ } 
+}
+// get the query parameters
+void queryfilterclass::parse_query_params (const FilterRequest_t &request,
+					   vector<queryparamclass> &query_params,
+					   int &startresults, int &endresults,
+					   ostream &logout) {
+  outconvertclass text_t2ascii;
+
+  // set defaults for the return parameters
+  query_params.erase(query_params.begin(), query_params.end());
+  startresults = filterOptions["StartResults"].defaultValue.getint();
+  endresults = filterOptions["EndResults"].defaultValue.getint();
+
+  // set defaults for query parameters
+  queryparamclass query;
+  query.combinequery = "or"; // first one must be "or"
+  set_queryparam_defaults(query);
   OptionValue_tarray::const_iterator options_here = request.filterOptions.begin();
   OptionValue_tarray::const_iterator options_end = request.filterOptions.end();
@@ -108,22 +349,8 @@
 
       // set defaults for query parameters
-      query.collection = collection;
-      query.index = filterOptions["Index"].defaultValue;
-      query.subcollection = filterOptions["Subcollection"].defaultValue;
-      query.language = filterOptions["Language"].defaultValue;
-      query.querystring.clear();
-      query.search_type = (filterOptions["QueryType"].defaultValue == "ranked");
-      query.match_mode = (filterOptions["MatchMode"].defaultValue == "all");
-      query.casefolding = (filterOptions["Casefold"].defaultValue == "true");
-      query.stemming = (filterOptions["Stem"].defaultValue == "true");
-      query.accentfolding = (filterOptions["AccentFold"].defaultValue == "true");
-      query.level = filterOptions["Level"].defaultValue;
-      query.filterstring = filterOptions["FilterString"].defaultValue;  // Lucene specific
-      query.sortfield = filterOptions["SortField"].defaultValue;  // Lucene specific
-      query.fuzziness = filterOptions["Fuzziness"].defaultValue;  // Lucene specific
-      query.maxnumeric = maxnumeric;
+      set_queryparam_defaults(query);
+
       // "all", needed when combining queries where the document results are needed
       if (need_matching_docs (request.filterResultOptions)) query.maxdocs = -1; 
-      else query.maxdocs = filterOptions["Maxdocs"].defaultValue.getint();
       
     } else if ((*options_here).name == "StartResults") {
@@ -131,36 +358,5 @@
     } else if ((*options_here).name == "EndResults") {
       endresults = (*options_here).value.getint();
-    } else if ((*options_here).name == "QueryType") {
-      query.search_type = ((*options_here).value == "ranked");
-    } else if ((*options_here).name == "MatchMode") {
-      query.match_mode = ((*options_here).value == "all");
-      if (query.match_mode == 1) query.maxdocs = -1;
-    } else if ((*options_here).name == "Term") {
-      query.querystring = (*options_here).value;
-    } else if ((*options_here).name == "Casefold") {
-      query.casefolding = ((*options_here).value == "true");
-    } else if ((*options_here).name == "Stem") {
-      query.stemming = ((*options_here).value == "true");
-    } else if ((*options_here).name == "AccentFold") {
-      query.accentfolding = ((*options_here).value == "true");
-    } else if ((*options_here).name == "Index"&& (*options_here).value !="") {
-      query.index = (*options_here).value;
-    } else if ((*options_here).name == "Subcollection") {
-      query.subcollection = (*options_here).value;
-    } else if ((*options_here).name == "Language") {
-      query.language = (*options_here).value;
-    } else if ((*options_here).name == "Maxdocs") {
-      query.maxdocs = (*options_here).value.getint();
-    } else if ((*options_here).name == "PhraseMatch") {
-      phrasematch = (*options_here).value;
-    } else if ((*options_here).name == "Level") {
-      query.level = (*options_here).value;
-    } else if ((*options_here).name == "FilterString") {
-      query.filterstring = (*options_here).value;
-    } else if ((*options_here).name == "SortField") {
-      query.sortfield = (*options_here).value;
-    } else if ((*options_here).name == "Fuzziness") {
-      query.fuzziness = (*options_here).value;
-    } else {
+    } else if (!set_queryparam_field(*options_here, query)) {
       logout << text_t2ascii
 	     << "warning: unknown queryfilter option \""
@@ -183,242 +379,30 @@
 
 
-
-queryfilterclass::queryfilterclass () {
-  db_ptr = NULL;
-  textsearchptr = NULL;
-  maxnumeric = 4;
-
-  FilterOption_t filtopt;
-  filtopt.name = "CombineQuery";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "and";
-  filtopt.validValues.push_back("and");
-  filtopt.validValues.push_back("or");
-  filtopt.validValues.push_back("not");
-  filterOptions["CombineQuery"] = filtopt;
-
-  // -- onePerQuery StartResults   integer
-  filtopt.clear();
-  filtopt.name = "StartResults";
-  filtopt.type = FilterOption_t::integert;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "1";
-  filtopt.validValues.push_back("1");
-  filtopt.validValues.push_back("1000");
-  filterOptions["StartResults"] = filtopt;
-
-  // -- onePerQuery EndResults     integer
-  filtopt.clear();
-  filtopt.name = "EndResults";
-  filtopt.type = FilterOption_t::integert;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "10";
-  filtopt.validValues.push_back("-1");
-  filtopt.validValues.push_back("1000");
-  filterOptions["EndResults"] = filtopt;
-
-  // -- onePerQuery QueryType      enumerated (boolean, ranked)
-  filtopt.clear();
-  filtopt.name = "QueryType";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "ranked";
-  filtopt.validValues.push_back("boolean");
-  filtopt.validValues.push_back("ranked");
-  filterOptions["QueryType"] = filtopt;
-
-  // -- onePerQuery MatchMode      enumerated (some, all)
-  filtopt.clear();
-  filtopt.name = "MatchMode";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "some";
-  filtopt.validValues.push_back("some");
-  filtopt.validValues.push_back("all");
-  filterOptions["MatchMode"] = filtopt;
-
-  // -- onePerTerm  Term           string ???
-  filtopt.clear();
-  filtopt.name = "Term";
-  filtopt.type = FilterOption_t::stringt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["Term"] = filtopt;
-
-  // -- onePerTerm  Casefold       boolean
-  filtopt.clear();
-  filtopt.name = "Casefold";
-  filtopt.type = FilterOption_t::booleant;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "true";
-  filtopt.validValues.push_back("false");
-  filtopt.validValues.push_back("true");
-  filterOptions["Casefold"] = filtopt;
-
-  // -- onePerTerm  Stem           boolean
-  filtopt.clear();
-  filtopt.name = "Stem";
-  filtopt.type = FilterOption_t::booleant;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "false";
-  filtopt.validValues.push_back("false");
-  filtopt.validValues.push_back("true");
-  filterOptions["Stem"] = filtopt;
-
-  // -- onePerTerm  AccentFold           boolean
-  filtopt.clear();
-  filtopt.name = "AccentFold";
-  filtopt.type = FilterOption_t::booleant;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "false";
-  filtopt.validValues.push_back("false");
-  filtopt.validValues.push_back("true");
-  filterOptions["AccentFold"] = filtopt;
-  
-  // -- onePerTerm  Index          enumerated
-  filtopt.clear();
-  filtopt.name = "Index";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["Index"] = filtopt;
-
-  // -- onePerTerm  Subcollection  enumerated
-  filtopt.clear();
-  filtopt.name = "Subcollection";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["Subcollection"] = filtopt;
-
-  // -- onePerTerm  Language  enumerated
-  filtopt.clear();
-  filtopt.name = "Language";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerTerm;
-  filtopt.defaultValue = "";
-  filterOptions["Language"] = filtopt;
-
-  // -- onePerQuery  Maxdocs  integer
-  filtopt.clear();
-  filtopt.name = "Maxdocs";
-  filtopt.type = FilterOption_t::integert;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "200";
-  filtopt.validValues.push_back("-1");
-  filtopt.validValues.push_back("1000");
-  filterOptions["Maxdocs"] = filtopt;
-
-  // -- onePerQuery  PhraseMatch  enumerated
-  filtopt.clear();
-  filtopt.name = "PhraseMatch";
-  filtopt.type = FilterOption_t::enumeratedt;
-  filtopt.repeatable = FilterOption_t::onePerQuery;
-  filtopt.defaultValue = "some_phrases";
-  filtopt.validValues.push_back ("all_phrases");
-  filtopt.validValues.push_back ("some_phrases");
-  filtopt.validValues.push_back ("all_docs");
-  filterOptions["PhraseMatch"] = filtopt;
-}
-
-queryfilterclass::~queryfilterclass () {
-  // don't delete db_ptr or textsearchptr here, they'll be cleaned up by the source
-}
-
-void queryfilterclass::configure (const text_t &key, const text_tarray &cfgline) {
-  filterclass::configure (key, cfgline);
-
-  if (key == "indexmap") {
-    indexmap.importmap (cfgline);
-    
-    // update the list of indexes in the filter information
-    text_tarray options;
-    indexmap.gettoarray (options);
-    filterOptions["Index"].validValues = options;
-
-  } else if (key == "defaultindex") {
-    indexmap.from2to (cfgline[0], filterOptions["Index"].defaultValue);
-
-  } else if (key == "subcollectionmap") {
-    subcollectionmap.importmap (cfgline);
-
-    // update the list of subcollections in the filter information
-    text_tarray options;
-    subcollectionmap.gettoarray (options);
-    filterOptions["Subcollection"].validValues = options;
-
-  } else if (key == "defaultsubcollection") {
-    subcollectionmap.from2to (cfgline[0], filterOptions["Subcollection"].defaultValue);
-
-  } else if (key == "languagemap") {
-    languagemap.importmap (cfgline);
-
-    // update the list of languages in the filter information
-    text_tarray options;
-    languagemap.gettoarray (options);
-    filterOptions["Language"].validValues = options;
-
-  } else if (key == "defaultlanguage") {
-    languagemap.from2to (cfgline[0], filterOptions["Language"].defaultValue);
-  } else if (key == "indexstem") {
-    indexstem = cfgline[0];
-  } else if (key == "maxnumeric") {
-    maxnumeric = cfgline[0].getint();
-  }
-  
-}
-
-bool queryfilterclass::init (ostream &logout) {
-  outconvertclass text_t2ascii;
-
-  if (!filterclass::init(logout)) return false;
-
-  if (filterOptions["Index"].defaultValue.empty()) {
-    // use first index in map as default if no default is set explicitly
-    text_tarray fromarray;
-    indexmap.getfromarray(fromarray);
-    if (fromarray.size()) {
-      filterOptions["Index"].defaultValue = fromarray[0];
-    }
-  }
-
-  if (filterOptions["Subcollection"].defaultValue.empty()) {
-    // use first subcollection in map as default if no default is set explicitly
-    text_tarray fromarray;
-    subcollectionmap.getfromarray(fromarray);
-    if (fromarray.size()) {
-      filterOptions["Subcollection"].defaultValue = fromarray[0];
-    }
-  }
-
-  if (filterOptions["Language"].defaultValue.empty()) {
-    // use first language in map as default if no default is set explicitly
-    text_tarray fromarray;
-    languagemap.getfromarray(fromarray);
-    if (fromarray.size()) {
-      filterOptions["Language"].defaultValue = fromarray[0];
-    }
-  }
-
-  if (db_ptr == NULL) {
-    // most likely a configuration problem
-    logout << text_t2ascii 
-	   << "configuration error: queryfilter contains a null dbclass\n\n";
-    return false;
-  }
-
-  // get the filename for the database and make sure it exists
-  if (indexstem.empty()) {
-    indexstem = collection;
-  }
-  db_filename = resolve_db_filename(indexstem,db_ptr->getfileextension());
-  if (!file_exists(db_filename)) {
-    logout << text_t2ascii
-	   << "warning: database \"" << db_filename << "\" does not exist\n\n";
-    //return false;
-  }
-
+// translate will return true if successful
+bool queryfilterclass::translate (dbclass *db_ptr, text_t& docnum, text_t &trans_OID) {
+  infodbclass info;
+
+  trans_OID.clear();
+
+  // get the info
+  if (db_ptr == NULL) return false;
+  if (!db_ptr->getinfo(docnum, info)) return false;
+
+  // translate
+  if (info["section"].empty()) return false;
+
+  trans_OID = info["section"];
   return true;
 }
 
+
+// whether document results are needed
+bool queryfilterclass::need_matching_docs (int filterResultOptions) {
+  return ((filterResultOptions & FROID) || (filterResultOptions & FRranking) ||
+	  (filterResultOptions & FRmetadata));
+}
+
+// whether term information is needed
+bool queryfilterclass::need_term_info (int filterResultOptions) {
+  return ((filterResultOptions & FRtermFreq) || (filterResultOptions & FRmatchTerms));
+}
Index: main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.h	(revision 27063)
+++ main/trunk/greenstone2/runtime-src/src/colservr/queryfilter.h	(revision 27064)
@@ -56,9 +56,10 @@
   int maxnumeric;
 
-   // get the query parameters
+  void set_queryparam_defaults(queryparamclass &query );
+  bool set_queryparam_field(OptionValue_t option, queryparamclass &query);
   void parse_query_params (const FilterRequest_t &request,
 			   vector<queryparamclass> &query_params,
 			   int &startresults, int &endresults,
-			   text_t &phrasematch, ostream &logout);
+			   ostream &logout);
 
   // do query that might involve multiple sub queries
