Index: trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java
===================================================================
--- trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java	(revision 12653)
+++ trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java	(revision 12656)
@@ -3,4 +3,6 @@
  * @author  kjdon@cs.waikato.ac.nz
  * @author  davidb@cs.waikato.ac.nz
+ * @author  michael@dlconsulting.com
+ * @author  john@dlconsulting.com
  * @version 
  */
@@ -11,4 +13,5 @@
 import java.io.*;
 import java.util.*;
+import java.util.regex.*;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -41,5 +44,5 @@
     {
 	if (args.length == 0) {
-	    System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzzy] [-filter filter_string] [-sort sort_field] [-dco AND|OR]");
+	    System.out.println("Usage: GS2LuceneQuery <index directory> [-fuzzy] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number]");
 	    return;
 	}
@@ -49,11 +52,15 @@
 	    IndexReader reader = ((IndexSearcher) searcher).getIndexReader();
 
-	    // Create one query parser with stop words, and one with none
+	    // Create one query parser with the standard set of stop words, and one with none
 	    QueryParser query_parser = new QueryParser("TX", new StandardAnalyzer(stop_words));
 	    QueryParser query_parser_no_stop_words = new QueryParser("TX", new StandardAnalyzer(new String[] { }));
 
 	    Sort sorter = new Sort();
-	    QueryFilter filter = null;
+	    Filter filter = null;
             boolean fuzzy = false;
+
+	    // Paging
+	    int start_results = 1;
+	    int end_results = -1;
 
             // New code to allow the default conjunction operator to be
@@ -70,10 +77,7 @@
                         {
                             i++;
-			    try {
-				filter = new QueryFilter(query_parser.parse(args[i]));
-			    }
-			    catch (ParseException exception) {
-				exception.printStackTrace();
-			    }
+
+			    // Parse up filter
+			    filter = parseFilterString(args[i]);
                         }
                     if (args[i].equals("-dco"))
@@ -86,4 +90,20 @@
                             fuzzy = true;
                         }
+		    if (args[i].equals("-startresults"))
+			{
+			    i++;
+			    if (args[i].matches("\\d+"))
+				{
+				    start_results = Integer.parseInt(args[i]);
+				}
+			}
+		    if (args[i].equals("-endresults"))
+			{
+			    i++;
+			    if (args[i].matches("\\d+"))
+				{
+				    end_results = Integer.parseInt(args[i]);
+				}
+			}
                 }
 
@@ -104,4 +124,8 @@
 		System.out.println("<ResultSet>");
 		System.out.println("  <QueryString>" + query_string + "</QueryString>");
+		if (filter != null)
+		    {
+			System.out.println("  <FilterString>" + filter.toString() + "</FilterString>");
+		    }
 
 		try {
@@ -139,4 +163,8 @@
 		    // Do we need to use a hit iterator to get sorted results?
 		    System.out.println("  <MatchingDocsInfo num=\"" + hits.length() + "\"/>");
+		    System.out.println("  <StartResults num=\"" + start_results + "\" />");
+		    System.out.println("  <EndsResults num=\"" + end_results + "\" />");
+
+		    int counter = 1;
 		    Iterator hit_iter = hits.iterator();
 		    while (hit_iter.hasNext())
@@ -145,6 +173,17 @@
 			    Document doc = hit.getDocument();
 			    String node_id = doc.get("nodeID");
-			    System.out.println("  <Match id=\"" + node_id + "\" />"); 
-                        
+
+			    // May not be paging results
+			    if (start_results == 1 && end_results == -1)
+				{
+				    System.out.println("  <Match id=\"" + node_id + "\" />");
+				}
+			    // Otherwise skip up until page offset
+			    else if (start_results <= counter && counter <= end_results)
+				{
+				    System.out.println("  <Match id=\"" + node_id + "\" />");
+				}
+			    // And skip all the rest
+
 			    // From the document, extract the Term Vector for the
 			    // TX field
@@ -182,4 +221,5 @@
 				    ///ystem.err.println("Error! Missing term vector for document " + hit.getId());
 				}
+			    ++counter;
 			}
 
@@ -347,3 +387,29 @@
 	return query;
     }
+
+
+  /**
+   *  @todo Michael to comment
+   */
+  private static Filter parseFilterString(String filter_string)
+  {
+    Filter result = null;
+    Pattern pattern = Pattern.compile("\\s*\\+(\\w+)\\:([\\{\\[])(\\d+)\\s+TO\\s+(\\d+)([\\}\\]])\\s*");
+    Matcher matcher = pattern.matcher(filter_string);
+    if (matcher.matches())
+      {
+        String field_name = matcher.group(1);
+        boolean include_lower = matcher.group(2).equals("[");
+        String lower_term = matcher.group(3);
+        String upper_term = matcher.group(4);
+        boolean include_upper = matcher.group(5).equals("]");
+        result = new RangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);
+      }
+    else
+      {
+        System.err.println("Error: Could not understand filter string \"" + filter_string + "\"");
+      }
+    return result;
+  }
+  /** parseFilterString() **/
 }
