diff --git a/src/java/org/apache/lucene/search/MultiTermQuery.java b/src/java/org/apache/lucene/search/MultiTermQuery.java
index 25afb33914c..995a857c708 100644
--- a/src/java/org/apache/lucene/search/MultiTermQuery.java
+++ b/src/java/org/apache/lucene/search/MultiTermQuery.java
@@ -310,9 +310,18 @@ public abstract class MultiTermQuery extends Query {
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 term
. */
+ /**
+ * Constructs a query for terms matching term
.
+ * @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;
}
diff --git a/src/java/org/apache/lucene/search/NumericRangeQuery.java b/src/java/org/apache/lucene/search/NumericRangeQuery.java
index fdc2a92025f..d2f94ec207a 100644
--- a/src/java/org/apache/lucene/search/NumericRangeQuery.java
+++ b/src/java/org/apache/lucene/search/NumericRangeQuery.java
@@ -129,8 +129,8 @@ import org.apache.lucene.index.Term;
* e.g. bounding boxes or exact date/time stamps is important.
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 ≤8 and + * 64 bit (long/double) ranges with precisionStep ≤6. * Otherwise it uses {@linkplain * MultiTermQuery#CONSTANT_SCORE_FILTER_REWRITE} as the * number of terms is likely to be high. @@ -159,27 +159,27 @@ public final class NumericRangeQuery extends MultiTermQuery { 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); } /** diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java index bbfc7c5eb8c..d97a6b76c7d 100644 --- a/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java +++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java @@ -102,14 +102,14 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { 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 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { // 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 ); diff --git a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java index 6342616eb16..01a1432a1ef 100644 --- a/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java +++ b/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java @@ -106,14 +106,14 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { 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 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { // 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 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { // 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 );