diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index a17f1ac3deb..94261fa2b02 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -141,6 +141,9 @@ Improvements classes to use the optimized variants through the MR-JAR mechanism. (Uwe Schindler, Robert Muir, Adrien Grand, Mike McCandless) +* LUCENE-8127: Speed up rewriteNoScoring when there are no MUST clauses. + (Michael Braun via Adrien Grand) + Bug Fixes * LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators. 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 8e6df1600cf..f52df9fb9cd 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java @@ -183,6 +183,9 @@ public class BooleanQuery extends Query implements Iterable { } private BooleanQuery rewriteNoScoring() { + if (clauseSets.get(Occur.MUST).size() == 0) { + return this; + } BooleanQuery.Builder newQuery = new BooleanQuery.Builder(); newQuery.setMinimumNumberShouldMatch(getMinimumNumberShouldMatch()); for (BooleanClause clause : clauses) {