count() in BooleanQuery could be early quit (#11895)

* Count() in BooleanQuery could be early quit if queries are pure disjunctional
This commit is contained in:
Lu Xugang 2022-11-15 17:57:51 +08:00 committed by GitHub
parent 69a7cb22e7
commit e5426dbbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -163,6 +163,8 @@ Optimizations
* GITHUB#11884: Simplify the logic of matchAll() in IndexSortSortedNumericDocValuesRangeQuery. (Lu Xugang)
* GITHUB#11895: count() in BooleanQuery could be early quit. (Lu Xugang)
Other
---------------------

View File

@ -401,8 +401,9 @@ final class BooleanWeight extends Weight {
final int numDocs = context.reader().numDocs();
int positiveCount;
if (query.isPureDisjunction()) {
positiveCount = optCount(context, Occur.SHOULD);
} else if ((query.getClauses(Occur.FILTER).isEmpty() == false
return optCount(context, Occur.SHOULD);
}
if ((query.getClauses(Occur.FILTER).isEmpty() == false
|| query.getClauses(Occur.MUST).isEmpty() == false)
&& query.getMinimumNumberShouldMatch() == 0) {
positiveCount = reqCount(context);