You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2025/03/17 21:42:38 UTC

(lucene) branch branch_10x updated: Implement #docIDRunEnd() on `DisjunctionDISIApproximation`. (#14363)

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

jpountz pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 0e6911da5de Implement #docIDRunEnd() on `DisjunctionDISIApproximation`. (#14363)
0e6911da5de is described below

commit 0e6911da5de89c21146beaef7149f01550f248aa
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Mon Mar 17 22:28:18 2025 +0100

    Implement #docIDRunEnd() on `DisjunctionDISIApproximation`. (#14363)
    
    I kept it simple for now, it just takes the max `#docIDRunEnd()` across top
    clauses.
---
 .../search/DisjunctionDISIApproximation.java       | 12 ++++++
 .../search/TestDisjunctionDISIApproximation.java   | 48 ++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java
index 08018dacf9b..b4b5b4adf26 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java
@@ -187,4 +187,16 @@ public final class DisjunctionDISIApproximation extends DocIdSetIterator {
     }
     return topList;
   }
+
+  @Override
+  public int docIDRunEnd() throws IOException {
+    // We're only looking at the "top" clauses. In theory, we may be able to find longer runs if
+    // other clauses have overlapping runs with the runs of the top clauses, but does it actually
+    // happen in practice and would it buy much?
+    int maxDocIDRunEnd = super.docIDRunEnd();
+    for (DisiWrapper w = topList(); w != null; w = w.next) {
+      maxDocIDRunEnd = Math.max(maxDocIDRunEnd, w.approximation.docIDRunEnd());
+    }
+    return maxDocIDRunEnd;
+  }
 }
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionDISIApproximation.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionDISIApproximation.java
new file mode 100644
index 00000000000..3d13f76c35a
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionDISIApproximation.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.io.IOException;
+import java.util.Arrays;
+import org.apache.lucene.tests.util.LuceneTestCase;
+import org.apache.lucene.tests.util.TestUtil;
+
+public class TestDisjunctionDISIApproximation extends LuceneTestCase {
+
+  public void testDocIDRunEnd() throws IOException {
+    DocIdSetIterator clause1 = DocIdSetIterator.range(10_000, 30_000);
+    DocIdSetIterator clause2 = DocIdSetIterator.range(20_000, 50_000);
+    DocIdSetIterator clause3 = DocIdSetIterator.range(60_000, 60_001);
+    long leadCost = TestUtil.nextLong(random(), 1, 100_000);
+    Scorer scorer1 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause1);
+    Scorer scorer2 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause2);
+    Scorer scorer3 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause3);
+    DocIdSetIterator iterator =
+        new DisjunctionDISIApproximation(
+            Arrays.asList(
+                new DisiWrapper(scorer1, false),
+                new DisiWrapper(scorer2, false),
+                new DisiWrapper(scorer3, false)),
+            leadCost);
+    assertEquals(10_000, iterator.nextDoc());
+    assertEquals(30_000, iterator.docIDRunEnd());
+    assertEquals(25_000, iterator.advance(25_000));
+    assertEquals(50_000, iterator.docIDRunEnd());
+    assertEquals(60_000, iterator.advance(50_000));
+    assertEquals(60_001, iterator.docIDRunEnd());
+  }
+}