mirror of https://github.com/apache/lucene.git
LUCENE-1860: default all multi-term queries to constant score auto
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@808519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c7745f923
commit
1537fe7102
|
@ -205,6 +205,12 @@ Changes in runtime behavior
|
|||
The usage of the US locale is important to guarantee correct ordering of
|
||||
generated terms. (Uwe Schindler)
|
||||
|
||||
15. LUCENE-1860: MultiTermQuery now defaults to
|
||||
CONSTANT_SCORE_AUTO_REWRITE_DEFAULT rewrite method (previously it
|
||||
was SCORING_BOOLEAN_QUERY_REWRITE). This means that PrefixQuery
|
||||
and WildcardQuery will now produce constant score for all matching
|
||||
docs, equal to the boost of the query. (Mike McCandless)
|
||||
|
||||
API Changes
|
||||
|
||||
1. LUCENE-1419: Add expert API to set custom indexing chain. This API is
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<property name="Name" value="Lucene"/>
|
||||
<property name="dev.version" value="2.9"/>
|
||||
<property name="version" value="${dev.version}"/>
|
||||
<property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090815"/>
|
||||
<property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090827"/>
|
||||
<property name="spec.version" value="${version}"/>
|
||||
<property name="year" value="2000-${current.year}"/>
|
||||
<property name="final.name" value="lucene-${name}-${version}"/>
|
||||
|
|
|
@ -50,8 +50,7 @@ public class SpanRegexQuery extends SpanQuery implements RegexQueryCapable {
|
|||
public Query rewrite(IndexReader reader) throws IOException {
|
||||
RegexQuery orig = new RegexQuery(term);
|
||||
orig.setRegexImplementation(regexImpl);
|
||||
|
||||
// RegexQuery (via MultiTermQuery).rewrite always returns a BooleanQuery
|
||||
orig.setRewriteMethod(RegexQuery.SCORING_BOOLEAN_QUERY_REWRITE);
|
||||
BooleanQuery bq = (BooleanQuery) orig.rewrite(reader);
|
||||
|
||||
BooleanClause[] clauses = bq.getClauses();
|
||||
|
|
|
@ -60,7 +60,7 @@ import org.apache.lucene.queryParser.QueryParser; // for javadoc
|
|||
public abstract class MultiTermQuery extends Query {
|
||||
/* @deprecated move to sub class */
|
||||
protected Term term;
|
||||
protected RewriteMethod rewriteMethod = SCORING_BOOLEAN_QUERY_REWRITE;
|
||||
protected RewriteMethod rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
|
||||
transient int numberOfTerms = 0;
|
||||
|
||||
/** Abstract class that defines how the query is rewritten. */
|
||||
|
|
|
@ -26,13 +26,9 @@ import org.apache.lucene.util.ToStringUtils;
|
|||
/** A Query that matches documents containing terms with a specified prefix. A PrefixQuery
|
||||
* is built by QueryParser for input like <code>app*</code>.
|
||||
*
|
||||
* <p><b>NOTE</b>: Currently this query uses {@link
|
||||
* MultiTermQuery#SCORING_BOOLEAN_QUERY_REWRITE}, which
|
||||
* assigns not-very-useful scores to the resulting hits. In
|
||||
* 3.0 this default will change to {@link
|
||||
* MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}; you
|
||||
* can use {@link MultiTermQuery#setRewriteMethod} to change
|
||||
* it. */
|
||||
* <p>This query uses the {@link
|
||||
* MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}
|
||||
* rewrite method. */
|
||||
public class PrefixQuery extends MultiTermQuery {
|
||||
private Term prefix;
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ public class TermRangeQuery extends MultiTermQuery {
|
|||
this.includeLower = includeLower;
|
||||
this.includeUpper = includeUpper;
|
||||
this.collator = collator;
|
||||
rewriteMethod = CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
|
||||
}
|
||||
|
||||
/** Returns the field name for this query */
|
||||
|
|
|
@ -30,12 +30,9 @@ import java.io.IOException;
|
|||
* a Wildcard term should not start with one of the wildcards <code>*</code> or
|
||||
* <code>?</code>.
|
||||
*
|
||||
* <p><b>NOTE</b>: Currently this query uses {@link
|
||||
* MultiTermQuery#SCORING_BOOLEAN_QUERY_REWRITE}, which
|
||||
* assigns not-very-useful scores to the resulting hits. In
|
||||
* 3.0 this default will change to {@link
|
||||
* MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}; you can use {@link
|
||||
* MultiTermQuery#setRewriteMethod} to change it.
|
||||
* <p>This query uses the {@link
|
||||
* MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT}
|
||||
* rewrite method.
|
||||
*
|
||||
* @see WildcardTermEnum */
|
||||
public class WildcardQuery extends MultiTermQuery {
|
||||
|
|
|
@ -53,7 +53,22 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public void testMethod() {
|
||||
private int getCount(IndexReader r, Query q) throws Exception {
|
||||
if (q instanceof BooleanQuery) {
|
||||
return ((BooleanQuery) q).getClauses().length;
|
||||
} else if (q instanceof ConstantScoreQuery) {
|
||||
DocIdSetIterator iter = ((ConstantScoreQuery) q).getFilter().getDocIdSet(r).iterator();
|
||||
int count = 0;
|
||||
while(iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
} else {
|
||||
throw new RuntimeException("unepxected query " + q);
|
||||
}
|
||||
}
|
||||
|
||||
public void testMethod() throws Exception {
|
||||
RAMDirectory directory = new RAMDirectory();
|
||||
|
||||
String[] categories = new String[]{"food",
|
||||
|
@ -63,6 +78,7 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {
|
|||
|
||||
Query rw1 = null;
|
||||
Query rw2 = null;
|
||||
IndexReader reader = null;
|
||||
try {
|
||||
IndexWriter writer = new IndexWriter(directory, new
|
||||
WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||
|
@ -73,9 +89,8 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {
|
|||
}
|
||||
writer.close();
|
||||
|
||||
IndexReader reader = IndexReader.open(directory);
|
||||
reader = IndexReader.open(directory);
|
||||
PrefixQuery query = new PrefixQuery(new Term("category", "foo"));
|
||||
|
||||
rw1 = query.rewrite(reader);
|
||||
|
||||
BooleanQuery bq = new BooleanQuery();
|
||||
|
@ -86,20 +101,7 @@ public class TestBooleanPrefixQuery extends LuceneTestCase {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
BooleanQuery bq1 = null;
|
||||
if (rw1 instanceof BooleanQuery) {
|
||||
bq1 = (BooleanQuery) rw1;
|
||||
}
|
||||
|
||||
BooleanQuery bq2 = null;
|
||||
if (rw2 instanceof BooleanQuery) {
|
||||
bq2 = (BooleanQuery) rw2;
|
||||
} else {
|
||||
fail("Rewrite");
|
||||
}
|
||||
|
||||
assertEquals("Number of Clauses Mismatch", bq1.getClauses().length,
|
||||
bq2.getClauses().length);
|
||||
assertEquals("Number of Clauses Mismatch", getCount(reader, rw1), getCount(reader, rw2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue