You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by lu...@apache.org on 2022/11/24 05:29:03 UTC
[lucene] branch branch_9x updated: count() in BooleanQuery could be early quit (#11895)
This is an automated email from the ASF dual-hosted git repository.
luxugang pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new cab1802308d count() in BooleanQuery could be early quit (#11895)
cab1802308d is described below
commit cab1802308d63cd29bf5b9c5445c57b6f68743a1
Author: Lu Xugang <lu...@apache.org>
AuthorDate: Tue Nov 15 17:57:51 2022 +0800
count() in BooleanQuery could be early quit (#11895)
* Count() in BooleanQuery could be early quit if queries are pure disjunctional
---
lucene/CHANGES.txt | 2 ++
lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java | 5 +++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2b5e0aeee81..cfdaff048aa 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -90,6 +90,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
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
index d7279df8bbe..50fec3084b6 100644
--- a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
+++ b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java
@@ -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);