This is an automated email from the ASF dual-hosted git repository.

tingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new cfd72684709 [BugFix] Fix NOT TEXT_MATCH fence to exclude all docs when 
Lucene searcher has zero visible docs (#18006)
cfd72684709 is described below

commit cfd72684709037500cda024bfed035e2fc3ff1a9
Author: heng-kuang-777 <[email protected]>
AuthorDate: Fri Mar 27 15:26:50 2026 -0700

    [BugFix] Fix NOT TEXT_MATCH fence to exclude all docs when Lucene searcher 
has zero visible docs (#18006)
    
    In `TextMatchFilterOperator.getSearchableDocCount()`, the condition
    `searchableDocCount > 0` caused a fallback to `numDocs` when the Lucene
    searcher had refreshed to 0 visible documents. This can occur on a newly
    created consuming segment before the first Lucene SearcherManager refresh
    has completed. This made NOT TEXT_MATCH invert over the full `[0, numDocs)`
    range, producing false positives for all tail documents.
    
    Fix by changing the guard to `searchableDocCount >= 0`, so a zero
    searchable count is respected and NOT results are correctly empty.
    Adds a regression test covering this corner case.
    
    Co-authored-by: heng kuang <[email protected]>
---
 .../pinot/core/operator/filter/TextMatchFilterOperator.java       | 2 +-
 .../pinot/core/operator/filter/FilterOperatorUtilsTest.java       | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/filter/TextMatchFilterOperator.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/filter/TextMatchFilterOperator.java
index b7e775d5d80..b03b6147a49 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/operator/filter/TextMatchFilterOperator.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/operator/filter/TextMatchFilterOperator.java
@@ -56,7 +56,7 @@ public class TextMatchFilterOperator extends 
BaseFilterOperator {
 
   private static int getSearchableDocCount(TextIndexReader reader, int 
numDocs) {
     int searchableDocCount = reader.getSearchableDocCount();
-    return searchableDocCount > 0 && searchableDocCount < numDocs ? 
searchableDocCount : numDocs;
+    return searchableDocCount >= 0 && searchableDocCount < numDocs ? 
searchableDocCount : numDocs;
   }
 
   public TextMatchFilterOperator(TextIndexReader textIndexReader, 
TextMatchPredicate predicate, int numDocs) {
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/filter/FilterOperatorUtilsTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/filter/FilterOperatorUtilsTest.java
index d805c8d2e66..0dd0d3c871b 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/operator/filter/FilterOperatorUtilsTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/operator/filter/FilterOperatorUtilsTest.java
@@ -247,6 +247,14 @@ public class FilterOperatorUtilsTest {
     assertEquals(result.size(), TOTAL_DOCS - LUCENE_MATCH_DOC_IDS.length);
   }
 
+  @Test
+  public void testTextMatchNotFenceZeroSearchableDocsReturnsEmpty() {
+    // searchableDocCount = 0 means Lucene searcher has not yet refreshed; NOT 
result must be empty
+    NotFilterOperator notOp = new NotFilterOperator(textMatchOp(TOTAL_DOCS, 
0), TOTAL_DOCS, false);
+    List<Integer> result = TestUtils.getDocIds(notOp.getTrues());
+    assertEquals(result.size(), 0, "NOT result must be empty when no docs are 
visible to Lucene yet");
+  }
+
   @Test
   public void testTextMatchNotFenceNoMatchesReturnsAllSearchable() {
     TextMatchPredicate predicate =


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to