LUCENE-3238: make MTQ.rewrite final, and merge test

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1139465 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-06-24 23:40:30 +00:00
parent 7574f33abe
commit bd4a05c8cd
3 changed files with 25 additions and 1 deletions

View File

@ -503,6 +503,13 @@ Changes in backwards compatibility policy
overridden one of these methods, cut over to the non-deprecated
implementation. (Uwe Schindler, Robert Muir, Yonik Seeley)
* LUCENE-3238: Made MultiTermQuery.rewrite() final, to prevent
problems (such as not properly setting rewrite methods, or
not working correctly with things like SpanMultiTermQueryWrapper).
To rewrite to a simpler form, instead return a simpler enum
from getEnum(IndexReader). For example, to rewrite to a single term,
return a SingleTermEnum. (ludovic Boutros, Uwe Schindler, Robert Muir)
Changes in runtime behavior
* LUCENE-2834: the hash used to compute the lock file name when the
@ -555,6 +562,10 @@ Bug fixes
failing to measure the space required to hold the term's field and
text character data. (Mike McCandless)
* LUCENE-3238: Fixed bug where using WildcardQuery("prefix*") inside
of a SpanMultiTermQueryWrapper rewrote incorrectly and returned
an error instead. (ludovic Boutros, Uwe Schindler, Robert Muir)
API Changes
* LUCENE-3208: Renamed protected IndexSearcher.createWeight() to expert

View File

@ -301,8 +301,13 @@ public abstract class MultiTermQuery extends Query {
numberOfTerms += inc;
}
/**
* To rewrite to a simpler form, instead return a simpler
* enum from {@link #getTermsEnum(Terms, AttributeSource)}. For example,
* to rewrite to a single term, return a {@link SingleTermsEnum}
*/
@Override
public Query rewrite(IndexReader reader) throws IOException {
public final Query rewrite(IndexReader reader) throws IOException {
return rewriteMethod.rewrite(reader, this);
}

View File

@ -72,6 +72,14 @@ public class TestSpanMultiTermQueryWrapper extends LuceneTestCase {
assertEquals(1, searcher.search(sfq, 10).totalHits);
}
public void testPrefix() throws Exception {
WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
SpanQuery swq = new SpanMultiTermQueryWrapper<WildcardQuery>(wq);
// will only match "jumps over extremely very lazy broxn dog"
SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
assertEquals(1, searcher.search(sfq, 10).totalHits);
}
public void testFuzzy() throws Exception {
FuzzyQuery fq = new FuzzyQuery(new Term("field", "broan"));
SpanQuery sfq = new SpanMultiTermQueryWrapper<FuzzyQuery>(fq);