Index: /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.bat
===================================================================
--- /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.bat	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.bat	(revision 24644)
@@ -0,0 +1,3 @@
+@echo off
+
+javac -cp ..\lib\java\apache-solr-core-3.3.0.jar\;..\lib\java\apache-solr-solrj-3.3.0.jar QueryTest.java
Index: /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.sh
===================================================================
--- /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.sh	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/COMPILE-TEST.sh	(revision 24644)
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+javac -cp ..\\lib\\java\\apache-solr-core-3.3.0.jar\;..\\lib\\java\\apache-solr-solrj-3.3.0.jar QueryTest.java
Index: /gs3-extensions/solr/trunk/src/test/QueryTest.java
===================================================================
--- /gs3-extensions/solr/trunk/src/test/QueryTest.java	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/QueryTest.java	(revision 24644)
@@ -0,0 +1,233 @@
+
+// Adapted from
+// http://wiki.constellio.com/index.php/Solrj_example
+
+
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.response.FacetField;
+import org.apache.solr.client.solrj.response.FacetField.Count;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.servlet.SolrRequestParsers;
+
+import java.io.File;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.core.CoreContainer;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+
+import java.util.Collection;
+
+/**
+ * A simple main to illustrate how to execute a request using SolrJ
+ * 
+ */
+public class QueryTest 
+{
+    protected static String solr_home_str = "C:\\cygwin\\home\\davidb\\research\\code\\greenstone3-svn-full\\web\\ext\\solr";
+
+    private static final String myCore = "localsite-solr-jdbm-demo-didx";
+    
+    private static final String facet_field = "DS";
+    
+    // q=...
+    //private static final String query = "TX:snails";
+    private static final String query = "TX:farming";
+    
+    private static final int start = 0;
+    private static final int nbDocuments = 11;
+    
+    public static void main(String[] args) throws IOException,
+						  ParserConfigurationException,
+						  SAXException,
+						  SolrServerException {
+	
+	File solr_home = new File(solr_home_str);
+	File solr_xml = new File( solr_home,"solr.xml" );
+
+	try { 
+	    CoreContainer cores = new CoreContainer(solr_home_str,solr_xml);
+	    
+	    Collection<String> core_names = cores.getCoreNames();
+	    
+	    for (String name : core_names) {
+		System.err.println("(**** core name: " + name);
+	    }
+	    
+	    EmbeddedSolrServer server = new EmbeddedSolrServer(cores,myCore);
+	    
+	    // Do the same query three times using three different method
+	    System.out.println("====== 1st way to execute a query ======");
+	    print(doFirstQuery(server));
+	    System.out.println("====== 2nd way to execute a query ======");
+	    print(doSecondQuery(server));
+	    System.out.println("====== 3rd way to execute query ======");
+	    print(doThirdQuery(server));
+	    
+	    /*
+	      System.out.println("======= Using SpellChecker ======");
+	      print(spellCheck(server, "farmng snals"));
+	
+	    */
+
+	    cores.shutdown();
+	}
+	catch (Exception e) {
+	    e.printStackTrace();
+	}
+
+    }
+    
+    /**
+     * Do the query using a StringBuffer
+     */
+    public static QueryResponse doFirstQuery(SolrServer server)
+	throws SolrServerException {
+	StringBuffer request = new StringBuffer();
+	//request.append("collectionName=" + myCore);
+	request.append("facet=" + true);
+	request.append("&facet.field=" + facet_field);
+	request.append("&q=" + query);
+	request.append("&start=" + start);
+	request.append("&rows=" + nbDocuments);
+	SolrParams solrParams = SolrRequestParsers.parseQueryString(request
+								    .toString());
+
+	System.err.println("*** URL request: " + solrParams);
+
+	return server.query(solrParams);
+    }
+    
+    /**
+     * Do the query using a ModifiableSolrParams
+     */
+    public static QueryResponse doSecondQuery(SolrServer server)
+	throws SolrServerException {
+	ModifiableSolrParams solrParams = new ModifiableSolrParams();
+	//solrParams.set("collectionName", myCore);
+	solrParams.set("facet", "true");
+	solrParams.set("facet.field", facet_field);
+	solrParams.set("q", query);
+	solrParams.set("start", start);
+	solrParams.set("rows", nbDocuments);
+	return server.query(solrParams);
+    }
+    
+    /**
+     * Do the query using a SolrQuery
+     */
+    public static QueryResponse doThirdQuery(SolrServer server)
+	throws SolrServerException {
+	SolrQuery solrQuery = new SolrQuery();
+	solrQuery.setQuery(query);
+	//solrQuery.set("collectionName", myCore);
+	solrQuery.set("facet", "true");
+	solrQuery.set("facet.field", facet_field);
+	solrQuery.setStart(start);
+	solrQuery.setRows(nbDocuments);
+	return server.query(solrQuery);
+    }
+    
+    /**
+     * Do the query using a SolrQuery
+     */
+    public static QueryResponse spellCheck(SolrServer server, String badQuery)
+	throws SolrServerException {
+	SolrQuery solrQuery = new SolrQuery();
+	solrQuery.setQuery(badQuery);
+	solrQuery.set("collectionName", myCore);
+
+	// qt=spellcheck || qt=spellchecker
+	solrQuery.setQueryType("spellcheck");
+	return server.query(solrQuery);
+    }
+    
+    /**
+     * Print documents and facets
+     * 
+     * @param response
+     */
+    @SuppressWarnings("unchecked")
+	public static void print(QueryResponse response) {
+	SolrDocumentList docs = response.getResults();
+	if (docs != null) {
+	    System.out.println(docs.getNumFound() + " documents found, "
+			       + docs.size() + " returned : ");
+	    for (int i = 0; i < docs.size(); i++) {
+		SolrDocument doc = docs.get(i);
+		System.out.println("\t" + doc.toString());
+	    }
+	}
+	
+	List<FacetField> fieldFacets = response.getFacetFields();
+	if (fieldFacets != null && !fieldFacets.isEmpty()) {
+	    System.out.println("\nField Facets : ");
+	    for (FacetField fieldFacet : fieldFacets) {
+		System.out.print("\t" + fieldFacet.getName() + " :\t");
+		if (fieldFacet.getValueCount() > 0) {
+		    for (Count count : fieldFacet.getValues()) {
+			System.out.print(count.getName() + "["
+					 + count.getCount() + "]\t");
+		    }
+		}
+		System.out.println("");
+	    }
+	}
+	
+	Map<String, Integer> queryFacets = response.getFacetQuery();
+	if (queryFacets != null && !queryFacets.isEmpty()) {
+	    System.out.println("\nQuery facets : ");
+	    for (String queryFacet : queryFacets.keySet()) {
+		System.out.println("\t" + queryFacet + "\t["
+				   + queryFacets.get(queryFacet) + "]");
+	    }
+	    System.out.println("");
+	}
+	
+	NamedList<NamedList<Object>> spellCheckResponse = (NamedList<NamedList<Object>>) response
+	    .getResponse().get("spellcheck");
+	
+	if (spellCheckResponse != null) {
+	    Iterator<Entry<String, NamedList<Object>>> wordsIterator = spellCheckResponse
+		.iterator();
+	    
+	    while (wordsIterator.hasNext()) {
+		Entry<String, NamedList<Object>> entry = wordsIterator.next();
+		String word = entry.getKey();
+		NamedList<Object> spellCheckWordResponse = entry.getValue();
+		boolean correct = spellCheckWordResponse.get("frequency")
+		    .equals(1);
+		System.out.println("Word: " + word + ",\tCorrect?: " + correct);
+		NamedList<Integer> suggestions = (NamedList<Integer>) spellCheckWordResponse
+		    .get("suggestions");
+		if (suggestions != null && suggestions.size() > 0) {
+		    System.out.println("Suggestions : ");
+		    Iterator<Entry<String, Integer>> suggestionsIterator = suggestions
+			.iterator();
+		    while (suggestionsIterator.hasNext()) {
+			System.out.println("\t"
+					   + suggestionsIterator.next().getKey());
+		    }
+		    
+		}
+		System.out.println("");
+	    }
+	    
+	}
+	
+    }
+
+}
Index: /gs3-extensions/solr/trunk/src/test/QueryTest.java.checkpt1
===================================================================
--- /gs3-extensions/solr/trunk/src/test/QueryTest.java.checkpt1	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/QueryTest.java.checkpt1	(revision 24644)
@@ -0,0 +1,250 @@
+
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
+//import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+//import org.apache.solr.client.solrj.impl.XMLResponseParser;
+import org.apache.solr.client.solrj.response.FacetField;
+import org.apache.solr.client.solrj.response.FacetField.Count;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.servlet.SolrRequestParsers;
+
+import java.io.File;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.core.CoreContainer;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+
+import java.util.Collection;
+
+/**
+ * A simple main to illustrate how to execute a request using SolrJ
+ * 
+ */
+public class QueryTest {
+
+    //private static final String myServer = "http://localhost:8080/constellio/app";
+    
+    private static final String myCollection = "localsite-lucene-jdbm-demo-didx";
+    
+    // Can be set to 'on', 'off' or 'constellio' to include Constellio's facets
+    private static final String facet_field = "DS";
+    
+    // q=...
+    private static final String query = "TX:snails";
+    
+    private static final int start = 0;
+    private static final int nbDocuments = 11;
+    
+    public static void main(String[] args) throws IOException,
+						  ParserConfigurationException,
+						  SAXException,
+						  SolrServerException {
+	
+	
+	String solr_home_str = "C:\\cygwin\\home\\davidb\\research\\code\\greenstone3-svn-full\\ext\\solr";
+	
+	System.setProperty("solr.solr.home", solr_home_str);
+
+	File solr_home = new File(solr_home_str);
+	File solr_xml = new File( solr_home, "solr.xml" );
+	CoreContainer cores = new CoreContainer(solr_home_str,solr_xml);
+
+					       /*	try {
+	    cores.load(solr_home_str,solr_xml);
+	}
+	catch (Exception e) {
+	    e.printStackTrace();
+	}
+
+					       */
+
+	Collection<String> core_names = cores.getCoreNames();
+	
+	for (String name : core_names) {
+	    System.err.println("(**** core name: " + name);
+	}
+
+
+	EmbeddedSolrServer server 
+	    = new EmbeddedSolrServer(cores,myCollection);
+	
+	
+	// Prepare the SolrServer. Right now, the default SolrJ's ResponseParser
+	// isn't supported by Constellio.
+	//CommonsHttpSolrServer server = new CommonsHttpSolrServer(myServer);
+	//server.setParser(new XMLResponseParser());
+	
+	// Do the same query three times using three different method
+	System.out.println("====== 1st way to execute a query ======");
+	print(doFirstQuery(server));
+	System.out.println("====== 2nd way to execute a query ======");
+	print(doSecondQuery(server));
+	System.out.println("====== 3rd way to execute query ======");
+	print(doThirdQuery(server));
+
+	/*
+	System.out.println("======= Using SpellChecker ======");
+	print(spellCheck(server, "farmng snals"));
+
+	*/
+
+	cores.shutdown();
+    }
+    
+    /**
+     * Do the query using a StringBuffer
+     */
+    public static QueryResponse doFirstQuery(SolrServer server)
+	throws SolrServerException {
+	StringBuffer request = new StringBuffer();
+	request.append("collectionName=" + myCollection);
+	//	request.append("&username=" + "admin");
+	//	request.append("&password=" + "password");
+	request.append("&facet=" + true);
+	request.append("&facet.field=" + facet_field);
+	request.append("&q=" + query);
+	request.append("&start=" + start);
+	request.append("&rows=" + nbDocuments);
+	SolrParams solrParams = SolrRequestParsers.parseQueryString(request
+								    .toString());
+	
+	return server.query(solrParams);
+    }
+    
+    /**
+     * Do the query using a ModifiableSolrParams
+     */
+    public static QueryResponse doSecondQuery(SolrServer server)
+	throws SolrServerException {
+	ModifiableSolrParams solrParams = new ModifiableSolrParams();
+	solrParams.set("collectionName", myCollection);
+	//	solrParams.set("username", "admin");
+	//	solrParams.set("password", "password");
+	solrParams.set("facet", "true");
+	solrParams.set("facet.field", facet_field);
+	solrParams.set("q", query);
+	solrParams.set("start", start);
+	solrParams.set("rows", nbDocuments);
+	return server.query(solrParams);
+    }
+    
+    /**
+     * Do the query using a SolrQuery
+     */
+    public static QueryResponse doThirdQuery(SolrServer server)
+	throws SolrServerException {
+	SolrQuery solrQuery = new SolrQuery();
+	solrQuery.setQuery(query);
+	solrQuery.set("collectionName", myCollection);
+	//	solrQuery.set("username", "admin");
+	//	solrQuery.set("password", "password");
+	solrQuery.set("facet", "true");
+	solrQuery.set("facet.field", facet_field);
+	solrQuery.setStart(start);
+	solrQuery.setRows(nbDocuments);
+	return server.query(solrQuery);
+    }
+    
+    /**
+     * Do the query using a SolrQuery
+     */
+    public static QueryResponse spellCheck(SolrServer server, String badQuery)
+	throws SolrServerException {
+	SolrQuery solrQuery = new SolrQuery();
+	solrQuery.setQuery(badQuery);
+	solrQuery.set("collectionName", myCollection);
+
+	// qt=spellcheck || qt=spellchecker
+	solrQuery.setQueryType("spellcheck");
+	return server.query(solrQuery);
+    }
+    
+    /**
+     * Print documents and facets
+     * 
+     * @param response
+     */
+    @SuppressWarnings("unchecked")
+	public static void print(QueryResponse response) {
+	SolrDocumentList docs = response.getResults();
+	if (docs != null) {
+	    System.out.println(docs.getNumFound() + " documents found, "
+			       + docs.size() + " returned : ");
+	    for (int i = 0; i < docs.size(); i++) {
+		SolrDocument doc = docs.get(i);
+		System.out.println("\t" + doc.toString());
+	    }
+	}
+	
+	List<FacetField> fieldFacets = response.getFacetFields();
+	if (fieldFacets != null && fieldFacets.isEmpty()) {
+	    System.out.println("\nField Facets : ");
+	    for (FacetField fieldFacet : fieldFacets) {
+		System.out.print("\t" + fieldFacet.getName() + " :\t");
+		if (fieldFacet.getValueCount() > 0) {
+		    for (Count count : fieldFacet.getValues()) {
+			System.out.print(count.getName() + "["
+					 + count.getCount() + "]\t");
+		    }
+		}
+		System.out.println("");
+	    }
+	}
+	
+	Map<String, Integer> queryFacets = response.getFacetQuery();
+	if (queryFacets != null && !queryFacets.isEmpty()) {
+	    System.out.println("\nQuery facets : ");
+	    for (String queryFacet : queryFacets.keySet()) {
+		System.out.println("\t" + queryFacet + "\t["
+				   + queryFacets.get(queryFacet) + "]");
+	    }
+	    System.out.println("");
+	}
+	
+	NamedList<NamedList<Object>> spellCheckResponse = (NamedList<NamedList<Object>>) response
+	    .getResponse().get("spellcheck");
+	
+	if (spellCheckResponse != null) {
+	    Iterator<Entry<String, NamedList<Object>>> wordsIterator = spellCheckResponse
+		.iterator();
+	    
+	    while (wordsIterator.hasNext()) {
+		Entry<String, NamedList<Object>> entry = wordsIterator.next();
+		String word = entry.getKey();
+		NamedList<Object> spellCheckWordResponse = entry.getValue();
+		boolean correct = spellCheckWordResponse.get("frequency")
+		    .equals(1);
+		System.out.println("Word: " + word + ",\tCorrect?: " + correct);
+		NamedList<Integer> suggestions = (NamedList<Integer>) spellCheckWordResponse
+		    .get("suggestions");
+		if (suggestions != null && suggestions.size() > 0) {
+		    System.out.println("Suggestions : ");
+		    Iterator<Entry<String, Integer>> suggestionsIterator = suggestions
+			.iterator();
+		    while (suggestionsIterator.hasNext()) {
+			System.out.println("\t"
+					   + suggestionsIterator.next().getKey());
+		    }
+		    
+		}
+		System.out.println("");
+	    }
+	    
+	}
+	
+    }
+
+}
Index: /gs3-extensions/solr/trunk/src/test/README.txt
===================================================================
--- /gs3-extensions/solr/trunk/src/test/README.txt	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/README.txt	(revision 24644)
@@ -0,0 +1,15 @@
+
+Rudamentary program to test Solr built indexes.  Includes three
+different ways to build a query, and how to access facetted
+information.
+
+
+1. Edit QueryTest.java to suit your installation/needs, in particular the static fields:
+     'solr_home_str', 'myCore' and 'facet_field', and 'query'
+
+2. Ensure 'javac' is in your path, then compile with:
+     COMPILE-TEST.sh (or COMPILE-TEST.bat)
+
+3. Assuming successful compilation, run with:
+
+     RUN-TEST.sh (or RUN-TEST.bat)
Index: /gs3-extensions/solr/trunk/src/test/RUN-TEST.bat
===================================================================
--- /gs3-extensions/solr/trunk/src/test/RUN-TEST.bat	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/RUN-TEST.bat	(revision 24644)
@@ -0,0 +1,14 @@
+@echo on
+
+setlocal enabledelayedexpansion
+
+set classpath=.
+
+for %%J in (..\lib\java\*.jar) do set classpath=!classpath!;%%J
+
+set classpath=%classpath%\;..\lib\servlet-api-2.5-20081211.jar
+
+java -Djava.util.logging.config.file=logging.properties -cp %classpath% QueryTest
+
+endlocal
+
Index: /gs3-extensions/solr/trunk/src/test/RUN-TEST.sh
===================================================================
--- /gs3-extensions/solr/trunk/src/test/RUN-TEST.sh	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/RUN-TEST.sh	(revision 24644)
@@ -0,0 +1,32 @@
+
+jars="apache-solr-core-3.3.0.jar \
+  apache-solr-solrj-3.3.0.jar \
+  log4j-over-slf4j-1.6.1.jar \
+  slf4j-jdk14-1.6.1.jar \
+  slf4j-api-1.6.1.jar \
+  commons-io-1.4.jar \
+  commons-fileupload-1.2.1.jar \
+  lucene-analyzers-3.3.0.jar \
+  lucene-core-3.3.0.jar \
+  lucene-grouping-3.3.0.jar \
+  lucene-highlighter-3.3.0.jar \
+  lucene-memory-3.3.0.jar \
+  lucene-misc-3.3.0.jar \
+  lucene-queries-3.3.0.jar \
+  lucene-spatial-3.3.0.jar \
+  lucene-spellchecker-3.3.0.jar \
+  velocity-1.6.1.jar"
+
+classpath="."
+
+for j in $jars ; do
+  classpath="$classpath\;lib\\java\\$j"
+done
+
+
+classpath="$classpath\;lib\\servlet-api-2.5-20081211.jar"
+
+java -Djava.util.logging.config.file=logging.properties \
+     -cp $classpath \
+    QueryTest
+
Index: /gs3-extensions/solr/trunk/src/test/logging.properties
===================================================================
--- /gs3-extensions/solr/trunk/src/test/logging.properties	(revision 24644)
+++ /gs3-extensions/solr/trunk/src/test/logging.properties	(revision 24644)
@@ -0,0 +1,23 @@
+# Set the default logging level for the root logger
+.level = WARNING
+
+
+# Specify the handlers to create in the root logger
+# (all loggers are children of the root logger)
+# The following creates two handlers
+#handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
+
+# Set the default logging level for the root logger
+#.level = ALL
+
+# Set the default logging level for new ConsoleHandler instances
+#java.util.logging.ConsoleHandler.level = INFO
+
+# Set the default logging level for new FileHandler instances
+#java.util.logging.FileHandler.level = ALL
+
+# Set the default formatter for new ConsoleHandler instances
+#java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+# Set the default logging level for the logger named com.mycompany
+#com.mycompany.level = ALL
