Index: /gsdl/trunk/src/colservr/Makefile.in
===================================================================
--- /gsdl/trunk/src/colservr/Makefile.in	(revision 15756)
+++ /gsdl/trunk/src/colservr/Makefile.in	(revision 15757)
@@ -93,5 +93,6 @@
 	queryinfo.cpp \
 	search.cpp \
-	source.cpp
+	source.cpp \
+	sqlbrowsefilter.cpp
 
 OBJECTS = \
@@ -120,5 +121,6 @@
 	queryinfo.o \
 	search.o \
-	source.o
+	source.o \
+	sqlbrowsefilter.o
 
 LIBRARY = gsdlcolservr.a
Index: /gsdl/trunk/src/colservr/sqlbrowsefilter.cpp
===================================================================
--- /gsdl/trunk/src/colservr/sqlbrowsefilter.cpp	(revision 15757)
+++ /gsdl/trunk/src/colservr/sqlbrowsefilter.cpp	(revision 15757)
@@ -0,0 +1,130 @@
+/**********************************************************************
+ *
+ * sqlbrowsefilter.cpp -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * 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 "sqlbrowsefilter.h"
+#include "fileutil.h"
+
+
+sqlbrowsefilterclass::sqlbrowsefilterclass ()
+{
+  sql_db_ptr = NULL;
+}
+
+
+sqlbrowsefilterclass::~sqlbrowsefilterclass ()
+{
+}
+
+
+void sqlbrowsefilterclass::configure (const text_t &key, const text_tarray &cfgline)
+{
+  filterclass::configure (key, cfgline);
+
+  if (key == "indexstem")
+  {
+    indexstem = cfgline[0];
+  }
+}
+
+
+bool sqlbrowsefilterclass::init (ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  if (!filterclass::init(logout)) return false;
+
+  if (sql_db_ptr == NULL)
+  {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
+    return false;
+  }
+
+  if (indexstem.empty())
+  {
+    indexstem = collection;
+  }
+
+  // get the filename for the database and make sure it exists
+  sql_db_filename = filename_cat(dbhome, "collect", collection, "index", "text", indexstem);
+  sql_db_filename += sql_db_ptr->getfileextension();
+  if (!file_exists(sql_db_filename))
+  {
+    logout << text_t2ascii
+	   << "warning: database \"" << sql_db_filename << "\" does not exist\n\n";
+    return false;
+  }
+
+  return true;
+}
+
+
+void sqlbrowsefilterclass::filter (const FilterRequest_t &request,
+				   FilterResponse_t &response,
+				   comerror_t &err, ostream &logout)
+{
+  outconvertclass text_t2ascii;
+
+  response.clear();
+  err = noError;
+
+  if (sql_db_ptr == NULL) {
+    // most likely a configuration problem
+    logout << text_t2ascii 
+	   << "configuration error: sqlbrowsefilter contains a null sqldbclass\n\n";
+    err = configurationError;
+    return;
+  }
+
+  // open the database
+  sql_db_ptr->setlogout (&logout);
+  if (!sql_db_ptr->opendatabase (sql_db_filename, DB_READER, 100, false)) {
+    // most likely a system problem (we have already checked that the database exists)
+    logout << text_t2ascii
+	   << "system problem: open on database \""
+	   << sql_db_filename << "\" failed\n\n";
+    err = systemProblem;
+    return;
+  }
+
+  if ((request.filterResultOptions & FRmetadataValues) && !request.fields.empty())
+  {
+    text_t metadata_element_name = *(request.fields.begin());
+    logout << text_t2ascii << "Requesting metadata values for " << metadata_element_name << "...\n";
+    text_tarray metadata_values = sql_db_ptr->getmetadatavalues (metadata_element_name);
+    text_tarray::iterator metadata_value_iterator = metadata_values.begin();
+    while (metadata_value_iterator != metadata_values.end())
+    {
+      ResultDocInfo_t metadata_value_result_doc;
+      metadata_value_result_doc.OID = *metadata_value_iterator;
+      response.docInfo.push_back (metadata_value_result_doc);
+
+      metadata_value_iterator++;
+    }
+  }
+
+  sql_db_ptr->closedatabase();  // Important that local library doesn't leave any files open
+}
Index: /gsdl/trunk/src/colservr/sqlbrowsefilter.h
===================================================================
--- /gsdl/trunk/src/colservr/sqlbrowsefilter.h	(revision 15757)
+++ /gsdl/trunk/src/colservr/sqlbrowsefilter.h	(revision 15757)
@@ -0,0 +1,63 @@
+/**********************************************************************
+ *
+ * sqlbrowsefilter.h -- 
+ * Copyright (C) 2008  DL Consulting Ltd
+ *
+ * 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 SQLBROWSEFILTER_H
+#define SQLBROWSEFILTER_H
+
+
+#include "filter.h"
+#include "comtypes.h"
+#include "sqldbclass.h"
+#include "text_t.h"
+
+
+class sqlbrowsefilterclass : public filterclass {
+protected:
+  text_t sql_db_filename;
+  text_t indexstem;
+  sqldbclass *sql_db_ptr;
+
+public:
+  sqlbrowsefilterclass ();
+  virtual ~sqlbrowsefilterclass ();
+
+  text_t get_filter_name () { return "SQLBrowseFilter"; }
+
+  // configure should be called once for each configuration line
+  // default configures the default filter options
+  virtual void configure (const text_t &key, const text_tarray &cfgline);
+
+  // the sql db ptr remains the responsibility of the calling code and
+  // should be destroyed after this sqlbrowsefilter is destroyed
+  void set_sql_db_ptr (sqldbclass *sql_db_ptr_arg) { sql_db_ptr = sql_db_ptr_arg; }
+
+  bool init (ostream &logout);
+  void filter (const FilterRequest_t &request,
+	       FilterResponse_t &response,
+	       comerror_t &err, ostream &logout);
+};
+
+
+#endif
