LUCENE-7416: Rewriting `BooleanQuery` to a `MatchNoDocsQuery` is not safe because of `queryNorm`.

This commit is contained in:
Adrien Grand 2016-08-25 17:50:54 +02:00
parent 1ac9609cae
commit da6a502f26
2 changed files with 0 additions and 40 deletions

View File

@ -296,17 +296,6 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
}
}
// Check whether some clauses are both required and excluded
if (clauseSets.get(Occur.MUST_NOT).size() > 0) {
final Set<Query> reqAndExclQueries = new HashSet<Query>(clauseSets.get(Occur.FILTER));
reqAndExclQueries.addAll(clauseSets.get(Occur.MUST));
reqAndExclQueries.retainAll(clauseSets.get(Occur.MUST_NOT));
if (reqAndExclQueries.isEmpty() == false) {
return new MatchNoDocsQuery("FILTER or MUST clause also in MUST_NOT");
}
}
// remove FILTER clauses that are also MUST clauses
// or that match all documents
if (clauseSets.get(Occur.MUST).size() > 0 && clauseSets.get(Occur.FILTER).size() > 0) {

View File

@ -246,35 +246,6 @@ public class TestBooleanRewrites extends LuceneTestCase {
assertEquals(expected, searcher.rewrite(bq));
}
// Duplicate Must or Filter with MustNot returns no match
public void testDuplicateMustOrFilterWithMustNot() throws IOException {
IndexSearcher searcher = newSearcher(new MultiReader());
// Test Must with MustNot
BooleanQuery bq = new BooleanQuery.Builder()
.add(new TermQuery(new Term("foo", "bar")), Occur.MUST)
// other terms
.add(new TermQuery(new Term("foo", "baz")), Occur.MUST)
.add(new TermQuery(new Term("foo", "bad")), Occur.SHOULD)
//
.add(new TermQuery(new Term("foo", "bar")), Occur.MUST_NOT)
.build();
assertEquals(new MatchNoDocsQuery(), searcher.rewrite(bq));
// Test Filter with MustNot
BooleanQuery bq2 = new BooleanQuery.Builder()
.add(new TermQuery(new Term("foo", "bar")), Occur.FILTER)
// other terms
.add(new TermQuery(new Term("foo", "baz")), Occur.MUST)
.add(new TermQuery(new Term("foo", "bad")), Occur.SHOULD)
//
.add(new TermQuery(new Term("foo", "bar")), Occur.MUST_NOT)
.build();
assertEquals(new MatchNoDocsQuery(), searcher.rewrite(bq2));
}
public void testRemoveMatchAllFilter() throws IOException {
IndexSearcher searcher = newSearcher(new MultiReader());