lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r797741 - in /lucene/java/trunk/src: java/org/apache/lucene/search/ test/org/apache/lucene/search/
Date Sat, 25 Jul 2009 10:54:31 GMT
Author: uschindler
Date: Sat Jul 25 10:54:30 2009
New Revision: 797741

URL: http://svn.apache.org/viewvc?rev=797741&view=rev
Log:
Some additional changes to LUCENE-1644 / MTQ:
- Deprecate one ctor of MultiTermQuery(Term), as Term field is deprecated
- Add readResolve also for the default auto rewrite method (not really needed because equals/hashcode
impl, but singleton status is preserved)
- Some changes in NumericRangeQueryTests (now they use always constant score boolean/filter
rewrite in basic tests, the default in all other tests)
- Add some explanations for the rewriteMethod used in NumericRangeQery's ctor (term enum seeks
and so on). I also made a switch statement of the valSize (like at other places in this class,
this is for later 8 or 16 bit valSize extensions)

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java
    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/MultiTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java?rev=797741&r1=797740&r2=797741&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQuery.java Sat Jul 25 10:54:30
2009
@@ -310,9 +310,18 @@
     public void setDocCountPercent(double percent) {
       throw new UnsupportedOperationException("Please create a private instance");
     }
+
+    // Make sure we are still a singleton even after deserializing
+    protected Object readResolve() {
+      return CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
+    }
   };
 
-  /** Constructs a query for terms matching <code>term</code>. */
+  /**
+   * Constructs a query for terms matching <code>term</code>.
+   * @deprecated check sub class for possible term access - the Term does not
+   * make sense for all MultiTermQuerys and will be removed.
+   */
   public MultiTermQuery(Term term) {
     this.term = term;
   }

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=797741&r1=797740&r2=797741&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 Sat Jul 25
10:54:30 2009
@@ -129,8 +129,8 @@
  * e.g. bounding boxes or exact date/time stamps is important.</p>
  *
  * <p>The query defaults to {@linkplain MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}
- * for 32 bit (int/float) ranges with precisionStep <= 8 and
- * 64 bit (long/double) ranges with precisionStep <= 6.
+ * for 32 bit (int/float) ranges with precisionStep &le;8 and
+ * 64 bit (long/double) ranges with precisionStep &le;6.
  * Otherwise it uses {@linkplain
  * MultiTermQuery#CONSTANT_SCORE_FILTER_REWRITE} as the
  * number of terms is likely to be high.
@@ -159,27 +159,27 @@
     this.minInclusive = minInclusive;
     this.maxInclusive = maxInclusive;
 
-    final MultiTermQuery.RewriteMethod rewriteMethod;
-    if (valSize == 64) {
-      if (precisionStep > 6) {
-        // Likely to hit too many terms, so set to
-        // CONSTANT_SCORE_FILTER right off
-        rewriteMethod = CONSTANT_SCORE_FILTER_REWRITE;
-      } else {
-        rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
-      }
-    } else if (valSize == 32) {
-      if (precisionStep > 8) {
-        // Likely to hit too many terms, so set to
-        // CONSTANT_SCORE_FILTER right off
-        rewriteMethod = CONSTANT_SCORE_FILTER_REWRITE;
-      } else {
-        rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
-      }
-    } else {
-      throw new IllegalStateException("unrecognized valSize " + valSize);
+    // For bigger precisionSteps this query likely
+    // hits too many terms, so set to CONSTANT_SCORE_FILTER right off
+    // (especially as the FilteredTermEnum is costly if wasted only for AUTO tests because
it
+    // creates new enums from IndexReader for each sub-range)
+    switch (valSize) {
+      case 64:
+        setRewriteMethod( (precisionStep > 6) ?
+          CONSTANT_SCORE_FILTER_REWRITE : 
+          CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
+        );
+        break;
+      case 32:
+        setRewriteMethod( (precisionStep > 8) ?
+          CONSTANT_SCORE_FILTER_REWRITE : 
+          CONSTANT_SCORE_AUTO_REWRITE_DEFAULT
+        );
+        break;
+      default:
+        // should never happen
+        throw new IllegalArgumentException("valSize must be 32 or 64");
     }
-    setRewriteMethod(rewriteMethod);
   }
   
   /**

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=797741&r1=797740&r2=797741&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 Sat Jul
25 10:54:30 2009
@@ -102,14 +102,14 @@
       f.clearTotalNumberOfTerms();
       switch (i) {
         case 0:
-          type = " (constant score)";
+          type = " (constant score filter rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
           terms = q.getTotalNumberOfTerms();
           break;
         case 1:
-          type = " (boolean query)";
-          q.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+          type = " (constant score boolean rewrite)";
+          q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
           terms = q.getTotalNumberOfTerms();
           break;
@@ -228,7 +228,6 @@
       // test inclusive range
       NumericRangeQuery tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower),
new Integer(upper), true, true);
       TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper),
true, true);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       TopDocs tTopDocs = searcher.search(tq, 1);
       TopDocs cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -237,7 +236,6 @@
       // test exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper),
false, false);
       cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper),
false, false);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -246,7 +244,6 @@
       // test left exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper),
false, true);
       cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper),
false, true);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -255,7 +252,6 @@
       // test right exclusive range
       tq=NumericRangeQuery.newIntRange(field, precisionStep, new Integer(lower), new Integer(upper),
true, false);
       cq=new TermRangeQuery(field, NumericUtils.intToPrefixCoded(lower), NumericUtils.intToPrefixCoded(upper),
true, false);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );

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=797741&r1=797740&r2=797741&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 Sat Jul
25 10:54:30 2009
@@ -106,14 +106,14 @@
       f.clearTotalNumberOfTerms();
       switch (i) {
         case 0:
-          type = " (constant score)";
+          type = " (constant score filter rewrite)";
           q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
           terms = q.getTotalNumberOfTerms();
           break;
         case 1:
-          type = " (boolean query)";
-          q.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+          type = " (constant score boolean rewrite)";
+          q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
           topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
           terms = q.getTotalNumberOfTerms();
           break;
@@ -244,7 +244,6 @@
       // test inclusive range
       NumericRangeQuery tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower),
new Long(upper), true, true);
       TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower),
NumericUtils.longToPrefixCoded(upper), true, true);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       TopDocs tTopDocs = searcher.search(tq, 1);
       TopDocs cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -253,7 +252,6 @@
       // test exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper),
false, false);
       cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper),
false, false);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -262,7 +260,6 @@
       // test left exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper),
false, true);
       cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper),
false, true);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );
@@ -271,7 +268,6 @@
       // test right exclusive range
       tq=NumericRangeQuery.newLongRange(field, precisionStep, new Long(lower), new Long(upper),
true, false);
       cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper),
true, false);
-      cq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
       tTopDocs = searcher.search(tq, 1);
       cTopDocs = searcher.search(cq, 1);
       assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal",
cTopDocs.totalHits, tTopDocs.totalHits );



Mime
View raw message