mirror of https://github.com/apache/lucene.git
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) git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@797741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
228888a882
commit
0f9d2ec5b8
|
@ -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 <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;
|
||||
}
|
||||
|
|
|
@ -129,8 +129,8 @@ import org.apache.lucene.index.Term;
|
|||
* 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 ≤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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue