LUCENE-1134: Fixed BooleanQuery.rewrite to only optimze a single clause query if minNumShouldMatch<=0.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@617963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Busch 2008-02-03 08:21:16 +00:00
parent 18b61286fa
commit 3e6a40e89e
3 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,9 @@ API Changes
Bug fixes
1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimze a single
clause query if minNumShouldMatch<=0. (Shai Erera via Michael Busch)
New features
1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about a Token through the analysis

View File

@ -363,7 +363,7 @@ public class BooleanQuery extends Query {
}
public Query rewrite(IndexReader reader) throws IOException {
if (clauses.size() == 1) { // optimize 1-clause queries
if (minNrShouldMatch == 0 && clauses.size() == 1) { // optimize 1-clause queries
BooleanClause c = (BooleanClause)clauses.get(0);
if (!c.isProhibited()) { // just return clause

View File

@ -284,6 +284,16 @@ public class TestBooleanMinShouldMatch extends LuceneTestCase {
verifyNrHits(q, 0);
}
public void testNoOptionalButMin2() throws Exception {
/* one required, no optional */
BooleanQuery q = new BooleanQuery();
q.add(new TermQuery(new Term("all", "all" )), BooleanClause.Occur.MUST);//true, false);
q.setMinimumNumberShouldMatch(1); // 1 of 0 optional
verifyNrHits(q, 0);
}
public void testRandomQueries() throws Exception {
final Random rnd = new Random(0);