lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r738182 - /lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java
Date Tue, 27 Jan 2009 18:12:34 GMT
Author: uschindler
Date: Tue Jan 27 18:12:34 2009
New Revision: 738182

URL: http://svn.apache.org/viewvc?rev=738182&view=rev
Log:
Implement a shortcut, when range has min>max. In this case a static empty SortedVIntList
is returned.

Modified:
    lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java

Modified: lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java?rev=738182&r1=738181&r2=738182&view=diff
==============================================================================
--- lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java
(original)
+++ lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/trie/TrieRangeFilter.java
Tue Jan 27 18:12:34 2009
@@ -27,6 +27,7 @@
 import org.apache.lucene.index.TermEnum;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.util.OpenBitSet;
+import org.apache.lucene.util.SortedVIntList;
 
 /**
  * Implementation of a Lucene {@link Filter} that implements trie-based range filtering.
@@ -257,19 +258,24 @@
    */
   //@Override
   public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
-    final OpenBitSet bits = new OpenBitSet(reader.maxDoc());
-    final TermDocs termDocs = reader.termDocs();
-    try {
-      lastNumberOfTerms=splitRange(
-        reader,termDocs,bits,
-        min,trieVariant.TRIE_CODED_NUMERIC_MIN.equals(min),
-        max,trieVariant.TRIE_CODED_NUMERIC_MAX.equals(max)
-      );
-      //System.out.println("Found "+lastNumberOfTerms+" distinct terms in filtered range
for field '"+field+"'.");
-    } finally {
-      termDocs.close();
+    if (min.compareTo(max) > 0) {
+      // shortcut: if min>max, no docs will match!
+      lastNumberOfTerms=0;
+      return EMPTY_DOCIDSET;
+    } else {
+      final OpenBitSet bits = new OpenBitSet(reader.maxDoc());
+      final TermDocs termDocs = reader.termDocs();
+      try {
+        lastNumberOfTerms=splitRange(
+          reader,termDocs,bits,
+          min,trieVariant.TRIE_CODED_NUMERIC_MIN.equals(min),
+          max,trieVariant.TRIE_CODED_NUMERIC_MAX.equals(max)
+        );
+      } finally {
+        termDocs.close();
+      }
+      return bits;
     }
-    return bits;
   }
   
   /**
@@ -289,4 +295,6 @@
   private final boolean minInclusive,maxInclusive;
   private Object minUnconverted,maxUnconverted;
   private int lastNumberOfTerms=-1;
+  
+  private static final DocIdSet EMPTY_DOCIDSET = new SortedVIntList(new int[0]);
 }



Mime
View raw message