lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r824125 - in /lucene/java/trunk/src: java/org/apache/lucene/search/NumericRangeQuery.java test/org/apache/lucene/search/TestNumericRangeQuery32.java test/org/apache/lucene/search/TestNumericRangeQuery64.java
Date Sun, 11 Oct 2009 18:57:47 GMT
Author: uschindler
Date: Sun Oct 11 18:57:47 2009
New Revision: 824125

URL: http://svn.apache.org/viewvc?rev=824125&view=rev
Log:
Add a small optimization to enable users that use NumericRangeQuery with upper and lower point
identical to be faster by using constant score boolean rewrite by default. By this NumericRangeQuery
can be used like TermQuery to hit exactly one document.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java?rev=824125&r1=824124&r2=824125&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/NumericRangeQuery.java Sun Oct 11
18:57:47 2009
@@ -189,6 +189,11 @@
         // should never happen
         throw new IllegalArgumentException("valSize must be 32 or 64");
     }
+    
+    // shortcut if upper bound == lower bound
+    if (min != null && min.equals(max)) {
+      setRewriteMethod(CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
+    }
   }
   
   /**

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java?rev=824125&r1=824124&r2=824125&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java Sun Oct
11 18:57:47 2009
@@ -159,6 +159,15 @@
       DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
   }
   
+  public void testOneMatchQuery() throws Exception {
+    NumericRangeQuery<Integer> q = NumericRangeQuery.newIntRange("ascfield8", 8, 1000,
1000, true, true);
+    assertSame(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, q.getRewriteMethod());
+    TopDocs topDocs = searcher.search(q, noDocs);
+    ScoreDoc[] sd = topDocs.scoreDocs;
+    assertNotNull(sd);
+    assertEquals("Score doc count", 1, sd.length );
+  }
+  
   private void testLeftOpenRange(int precisionStep) throws Exception {
     String field="field"+precisionStep;
     int count=3000;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java?rev=824125&r1=824124&r2=824125&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java Sun Oct
11 18:57:47 2009
@@ -167,6 +167,15 @@
       DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
   }
   
+  public void testOneMatchQuery() throws Exception {
+    NumericRangeQuery<Long> q = NumericRangeQuery.newLongRange("ascfield8", 8, 1000L,
1000L, true, true);
+    assertSame(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, q.getRewriteMethod());
+    TopDocs topDocs = searcher.search(q, noDocs);
+    ScoreDoc[] sd = topDocs.scoreDocs;
+    assertNotNull(sd);
+    assertEquals("Score doc count", 1, sd.length );
+  }
+  
   private void testLeftOpenRange(int precisionStep) throws Exception {
     String field="field"+precisionStep;
     int count=3000;



Mime
View raw message