Index: trunk/gsdl/bin/script/lucene_query.pl
===================================================================
--- trunk/gsdl/bin/script/lucene_query.pl	(revision 12407)
+++ trunk/gsdl/bin/script/lucene_query.pl	(revision 12408)
@@ -45,4 +45,5 @@
     my $full_indexdir = shift(@_);
     my $fuzzy = shift(@_);
+    my $filter_string = shift(@_);
     my $sort_field = shift(@_);
     my $dco = shift(@_);
@@ -55,4 +56,7 @@
     if (defined($fuzzy)) {
         $cmd .= " -fuzzy";
+    }
+    if (defined($filter_string)) {
+	$cmd .= " -filter \"" . $filter_string . "\"";
     }
     if (defined($sort_field)) {
@@ -82,5 +86,5 @@
     my $argc = scalar(@argv);
     if ($argc == 0) {
-	print STDERR "Usage: $PROGNAME full-index-dir [query] [-fuzzy] [-sort sort_field] [-dco AND|OR] [-out out_file]\n";
+	print STDERR "Usage: $PROGNAME full-index-dir [query] [-fuzzy] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-out out_file]\n";
 	exit 1;
     }
@@ -89,4 +93,5 @@
     my $query = undef;
     my $fuzzy = undef;
+    my $filter_string = undef;
     my $sort_field = undef;
     my $dco = undef;
@@ -96,4 +101,8 @@
 	if ($argv[$i] eq "-fuzzy") {
 	    $fuzzy = 1;
+	}
+        elsif ($argv[$i] eq "-filter") {
+            $i++;
+            $filter_string = $argv[$i];
 	}
         elsif ($argv[$i] eq "-sort") {
@@ -114,5 +123,5 @@
     }
 
-    open_java_lucene($full_indexdir, $fuzzy, $sort_field, $dco, $out_file);
+    open_java_lucene($full_indexdir, $fuzzy, $filter_string, $sort_field, $dco, $out_file);
 
     if (defined $query) {
Index: trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java
===================================================================
--- trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java	(revision 12407)
+++ trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java	(revision 12408)
@@ -24,8 +24,10 @@
 import org.apache.lucene.index.TermFreqVector;
 import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.Hit;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.RangeFilter;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Sort;
@@ -46,4 +48,5 @@
 
 	    Sort sorter = new Sort();
+	    Filter filter = null;
             boolean fuzzy = false;
 
@@ -58,4 +61,9 @@
                             ///ystem.err.println("**** sort by = " + args[i]);
                             sorter = new Sort(args[i]);
+                        }
+                    if (args[i].equals("-filter"))
+                        {
+                            i++;
+			    filter = parseFilterString(args[i]);
                         }
                     if (args[i].equals("-dco"))
@@ -211,5 +219,11 @@
 
 		// Perform the query
-		Hits hits = searcher.search(query, sorter);
+		Hits hits;
+		if (filter != null) {
+		    hits = searcher.search(query, filter, sorter);
+		}
+		else {
+		    hits = searcher.search(query, sorter);
+		}
 		System.out.println("<ResultSet>");
 		System.out.println("  <QueryString>" + query_string + "</QueryString>");
@@ -244,5 +258,5 @@
                         // TX field
                         TermFreqVector term_freq_vector = reader.getTermFreqVector(hit.getId(), "TX");
-                        if (term_freq_vector.size() > 0)
+                        if (term_freq_vector != null && term_freq_vector.size() > 0)
                             {
                                 int[] term_frequencies = term_freq_vector.getTermFrequencies();
@@ -316,3 +330,20 @@
         }
     }
+
+
+    private static Filter parseFilterString(String filter_string)
+    {
+	// Range filters
+	if (filter_string.matches("(.*):[\\{\\[](.+) TO (.+)[\\}\\]]")) {
+	    String field_name = filter_string.substring(0, filter_string.indexOf(":"));
+	    boolean include_lower = (filter_string.charAt(filter_string.indexOf(":") + 1) == '[');
+	    String lower_term = filter_string.substring(filter_string.indexOf(":") + 2, filter_string.indexOf(" TO "));
+	    String upper_term = filter_string.substring(filter_string.indexOf(" TO ") + " TO ".length(), filter_string.length() - 1);
+	    boolean include_upper = (filter_string.charAt(filter_string.length() - 1) == ']');
+	    return new RangeFilter(field_name, lower_term, upper_term, include_lower, include_upper);
+	}
+
+	System.err.println("Error: Could not understand filter string \"" + filter_string + "\"");
+	return null;
+    }
 }
