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/15 09:57:57 UTC

[lucene] branch main 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 main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new e5426dbbd25 count() in BooleanQuery could be early quit (#11895)
e5426dbbd25 is described below

commit e5426dbbd25e6da5a187d79d8a8f605093d23445
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 1cde0758b24..0b7626b9955 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
 ---------------------
 
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);