Apache Solr open-source search software
LUCENE-1134: Fixed BooleanQuery.rewrite to only optimze a single clause query if minNumShouldMatch<=0.
Michael Busch3e6a40e89e41
diff --git a/CHANGES.txt b/CHANGES.txtindex bd907a2fb6c..9447a5ea8a6 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -22,6 +22,9 @@ API ChangesBug fixes+ 1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimze a single+ clause query if minNumShouldMatch<=0. (Shai Erera via Michael Busch)+New features1. LUCENE-1137: Added Token.set/getFlags() accessors for passing more information about a Token through the analysisdiff --git a/src/java/org/apache/lucene/search/BooleanQuery.java b/src/java/org/apache/lucene/search/BooleanQuery.javaindex 3d5a89b05a8..5873321dfc0 100644--- a/src/java/org/apache/lucene/search/BooleanQuery.java+++ b/src/java/org/apache/lucene/search/BooleanQuery.java@@ -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 queriesBooleanClause c = (BooleanClause)clauses.get(0);if (!c.isProhibited()) { // just return clausediff --git a/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java b/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.javaindex 7d4ebfec60b..f0559657364 100644--- a/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java+++ b/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java@@ -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);