diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java index bf5b29e942c..ec8e52ca91e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java @@ -296,17 +296,6 @@ public class BooleanQuery extends Query implements Iterable { } } - // Check whether some clauses are both required and excluded - if (clauseSets.get(Occur.MUST_NOT).size() > 0) { - final Set reqAndExclQueries = new HashSet(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) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java index 425dc1344e8..c928653098c 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java @@ -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());