Apache Lucene open-source search software
LUCENE-6944: Prevent BooleanWeight from creating sub bulk-scorers to only trash them later.
Adrien Grand9a4b4f69e8bc
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex efabd2884b3..5d2874aa65c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -146,6 +146,9 @@ Optimizations* LUCENE-6926: MUST_NOT clauses now use the match cost API to run the slow bitslast whenever possible. (Adrien Grand)+* LUCENE-6944: BooleanWeight no longer creates sub-scorers if BS1 is not+ applicable. (Adrien Grand)+Bug Fixes* LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at leastdiff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.javaindex eb03c6b941f..8edc2532164 100644--- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java@@ -189,6 +189,11 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {return clauses;}+ /** Return the collection of queries for the given {@link Occur}. */+ Collection<Query> getClauses(Occur occur) {+ return clauseSets.get(occur);+ }+/** Returns an iterator on the clauses in this query. It implements the {@link Iterable} interface to* make it possible to do:* <pre class="prettyprint">for (BooleanClause clause : booleanQuery) {}</pre>diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.javaindex a54e7133af3..515307bb52d 100644--- a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java@@ -191,25 +191,27 @@ final class BooleanWeight extends Weight {* cannot be used. */// pkg-private for forcing use of BooleanScorer in testsBulkScorer booleanScorer(LeafReaderContext context) throws IOException {+ if (query.getClauses(Occur.MUST).isEmpty() == false+ || query.getClauses(Occur.FILTER).isEmpty() == false) {+ // TODO: there are some cases where BooleanScorer+ // would handle conjunctions faster than+ // BooleanScorer2...+ return null;+ } else if (query.getClauses(Occur.MUST_NOT).isEmpty() == false) {+ // TODO: there are some cases where BooleanScorer could do this faster+ return null;+ }+List<BulkScorer> optional = new ArrayList<BulkScorer>();Iterator<BooleanClause> cIter = query.iterator();for (Weight w : weights) {BooleanClause c = cIter.next();+ if (c.getOccur() != Occur.SHOULD) {+ throw new AssertionError();+ }BulkScorer subScorer = w.bulkScorer(context);-- if (subScorer == null) {- if (c.isRequired()) {- return null;- }- } else if (c.isRequired()) {- // TODO: there are some cases where BooleanScorer- // would handle conjunctions faster than- // BooleanScorer2...- return null;- } else if (c.isProhibited()) {- // TODO: there are some cases where BooleanScorer could do this faster- return null;- } else {++ if (subScorer != null) {optional.add(subScorer);}}