LUCENE-6944: Prevent BooleanWeight from creating sub bulk-scorers to only trash them later.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1721215 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2015-12-21 17:01:57 +00:00
parent 822785a15f
commit 9a4b4f69e8
3 changed files with 24 additions and 14 deletions

View File

@ -146,6 +146,9 @@ Optimizations
* LUCENE-6926: MUST_NOT clauses now use the match cost API to run the slow bits
last 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 least

View File

@ -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>

View File

@ -191,25 +191,27 @@ final class BooleanWeight extends Weight {
* cannot be used. */
// pkg-private for forcing use of BooleanScorer in tests
BulkScorer 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);
}
}