Index: main/trunk/greenstone2/common-src/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
===================================================================
--- main/trunk/greenstone2/common-src/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java	(revision 24725)
+++ main/trunk/greenstone2/common-src/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java	(revision 24731)
@@ -45,45 +45,59 @@
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermRangeFilter;
+import org.apache.lucene.search.RangeFilter;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.TopFieldDocs;
 
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.Version;
-
-public class GS2LuceneQuery extends SharedSoleneQuery
+
+public class GS2LuceneQuery
 {
-    protected String full_indexdir="";
-
-    protected Sort sorter=new Sort();
-    protected Filter filter = null;
-
-    protected static Version matchVersion = Version.LUCENE_24;
-
-    protected QueryParser query_parser = null;
-    protected QueryParser query_parser_no_stop_words = null;
-    protected Searcher searcher = null;
-    protected IndexReader reader = null;
-
+
+
+    static private String TEXTFIELD = "TX";
+
+    // Use the standard set of English stop words by default
+    static private String[] stop_words = GS2Analyzer.STOP_WORDS;
+
+    private String full_indexdir="";
+    private String default_conjunction_operator = "OR";
+    private String fuzziness = null;
+    private String sort_field = null;
+    private Sort sorter=new Sort();
+    private String filter_string = null;
+    private Filter filter = null;
+    private int start_results=1;
+    private int end_results=Integer.MAX_VALUE;
+
+    private QueryParser query_parser = null;
+    private QueryParser query_parser_no_stop_words = null;
+    private Searcher searcher = null;
+    private IndexReader reader = null;
+
+    static private PrintWriter utf8out = null;
+
+    static
+    {
+	try {
+	    OutputStreamWriter osw = new OutputStreamWriter(System.out, "UTF-8");
+	    utf8out = new PrintWriter(osw, true);
+	}
+        catch (UnsupportedEncodingException e) { 
+	    System.out.println(e); 
+	}
+    }
+
+    
     public GS2LuceneQuery() {
-	super();
 
 	// Create one query parser with the standard set of stop words, and one with none
 
-	query_parser = new QueryParser(matchVersion, TEXTFIELD, new GS2Analyzer()); // uses built-in stop_words_set
-    	query_parser_no_stop_words = new QueryParser(matchVersion, TEXTFIELD, new GS2Analyzer(new String[] { }));
+	query_parser = new QueryParser(TEXTFIELD, new GS2Analyzer(stop_words));
+    	query_parser_no_stop_words = new QueryParser(TEXTFIELD, new GS2Analyzer(new String[] { }));
     }
     
     
     public boolean initialise() {
-
-	if (!super.initialise()) {
-	    return false;
-	}
-
 
     	if (full_indexdir==null || full_indexdir.length()==-1){
@@ -92,8 +106,6 @@
 	    return false;
     	}
-
         try {
-	    Directory full_indexdir_dir = FSDirectory.open(new File(full_indexdir));
-    	    searcher = new IndexSearcher(full_indexdir_dir,true);
+    	    searcher = new IndexSearcher(full_indexdir);
     	    reader = ((IndexSearcher) searcher).getIndexReader();
 	    
@@ -106,28 +118,4 @@
 
     }
-
-    public void setIndexDir(String full_indexdir) {
-	this.full_indexdir = full_indexdir;
-    }
-
-    public void setSortField(String sort_field) {
-	super.setSortField(sort_field);
-
-	if (sort_field == null) {
-	    this.sorter = new Sort();
-	} else {
-	    this.sorter = new Sort(new SortField(sort_field,SortField.STRING)); // **** can do better than this?!?
-	}
-    }
-
-    public void setFilterString(String filter_string) {
-	super.setFilterString(filter_string);
-	this.filter = parseFilterString(filter_string);
-    }
-
-    public Filter getFilter() {
-	return this.filter;
-    }
-
     
     public LuceneQueryResult runQuery(String query_string) {
@@ -206,14 +194,14 @@
 	    if (end_results == Integer.MAX_VALUE) {
 		// Perform the query (filter and sorter may be null)
-		TopFieldDocs hits = searcher.search(query, filter, end_results, sorter);
-		lucene_query_result.setTotalDocs(hits.totalHits);
+		Hits hits = searcher.search(query, filter, sorter);
+		lucene_query_result.setTotalDocs(hits.length());
 
 		// Output the matching documents
 		lucene_query_result.setStartResults(start_results);
-		lucene_query_result.setEndResults(hits.totalHits);
-
-		for (int i = start_results; i <= hits.totalHits; i++) {
-		    int lucene_doc_num = hits.scoreDocs[i - 1].doc;
-		    Document doc = reader.document(lucene_doc_num);
+		lucene_query_result.setEndResults(hits.length());
+
+		for (int i = start_results; i <= hits.length(); i++) {
+		    int lucene_doc_num = hits.id(i - 1);
+		    Document doc = hits.doc(i - 1);
 		    int doc_term_freq = 0;
 		    Integer doc_term_freq_object = (Integer) doc_term_freq_map.get(new Integer(lucene_doc_num));
@@ -222,5 +210,5 @@
 			doc_term_freq = doc_term_freq_object.intValue();
 		    }
-		    lucene_query_result.addDoc(doc.get("docOID").trim(), hits.scoreDocs[i-1].score, doc_term_freq);
+		    lucene_query_result.addDoc(doc.get("docOID").trim(), hits.score(i-1), doc_term_freq);
 		}
 	    }
@@ -268,6 +256,5 @@
 
     public void setDefaultConjunctionOperator(String default_conjunction_operator) {
-	super.setDefaultConjunctionOperator(default_conjunction_operator);
-
+	this.default_conjunction_operator = default_conjunction_operator.toUpperCase();
 	if (default_conjunction_operator.equals("AND")) {
 	    query_parser.setDefaultOperator(query_parser.AND_OPERATOR);
@@ -278,8 +265,62 @@
 	}
     }
-     
-       
+    
+    public String getDefaultConjunctionOperator() {
+	return this.default_conjunction_operator;
+    }
+    
+    public void setEndResults(int end_results) {
+	this.end_results = end_results;
+    }
+    public int getEndResults() {
+	return this.end_results;
+    }
+        
+    public void setFilterString(String filter_string) {
+	this.filter_string = filter_string;
+	this.filter = parseFilterString(filter_string);
+    }
+    public String getFilterString() {
+	return this.filter_string ;
+    }
+    
+    public Filter getFilter() {
+	return this.filter;
+    }
+
+    public void setIndexDir(String full_indexdir) {
+	this.full_indexdir = full_indexdir;
+    }
+    
+    public void setFuzziness(String fuzziness) {
+	this.fuzziness = fuzziness;
+    }
+    public String getFuzziness() {
+	return this.fuzziness;
+    }
+    
+    public void setSortField(String sort_field) {
+	this.sort_field = sort_field;
+	if (sort_field == null) {
+	    this.sorter = new Sort();
+	} else {
+	    this.sorter = new Sort(sort_field);
+	}
+    }
+    public String getSortField() {
+	return this.sort_field;
+    }
+        
+    public void setStartResults(int start_results) {
+	if (start_results < 1) {
+	    start_results = 1;
+	}
+	this.start_results = start_results;
+    }
+    public int getStartResults() {
+	return this.start_results;
+    }
+        
     public void cleanUp() {
-	super.cleanUp();
 	try {
 	    if (searcher != null) {
@@ -291,6 +332,5 @@
     }
 
-
-    protected Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, String fuzziness)
+    private Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, String fuzziness)
 	throws java.io.IOException, org.apache.lucene.queryParser.ParseException
     {
@@ -394,5 +434,5 @@
     }
 
-    protected Filter parseFilterString(String filter_string)
+    private Filter parseFilterString(String filter_string)
     {
 	Filter result = null;
@@ -405,5 +445,5 @@
 	    String upper_term = matcher.group(4);
 	    boolean include_upper = matcher.group(5).equals("]");
-	    result = new TermRangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);
+	    result = new RangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);
 	}
 	else {
@@ -412,14 +452,26 @@
 	return result;
     }
-    
-
+
+
+    protected void finalize() throws Throwable 
+    {
+	try {
+	    utf8out.flush(); 
+	} finally {
+	    super.finalize();
+	}
+    }
+
+    
     /** command line program and auxiliary methods */
 
     // Fairly self-explanatory I should hope
-    static protected boolean query_result_caching_enabled = false;
+    static private boolean query_result_caching_enabled = false;
 
 
     static public void main (String args[])
     {
+
+
 	if (args.length == 0) {
 	    System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzziness value] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number] [query]");
@@ -514,5 +566,5 @@
     }
 
-    protected static void runQueryCaching(String index_directory, GS2LuceneQuery queryer, String query_string) 
+    private static void runQueryCaching(String index_directory, GS2LuceneQuery queryer, String query_string) 
 	throws IOException
     {
@@ -602,5 +654,5 @@
     }
     
-    protected static String fileSafe(String text)
+    private static String fileSafe(String text)
     {
 	StringBuffer file_safe_text = new StringBuffer();
