Skip to content

Commit 9792d88

Browse files
authored
Implement #docIDRunEnd() on DisjunctionDISIApproximation. (#14363)
I kept it simple for now, it just takes the max `#docIDRunEnd()` across top clauses.
1 parent 9472dca commit 9792d88

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,16 @@ private DisiWrapper computeTopList() {
187187
}
188188
return topList;
189189
}
190+
191+
@Override
192+
public int docIDRunEnd() throws IOException {
193+
// We're only looking at the "top" clauses. In theory, we may be able to find longer runs if
194+
// other clauses have overlapping runs with the runs of the top clauses, but does it actually
195+
// happen in practice and would it buy much?
196+
int maxDocIDRunEnd = super.docIDRunEnd();
197+
for (DisiWrapper w = topList(); w != null; w = w.next) {
198+
maxDocIDRunEnd = Math.max(maxDocIDRunEnd, w.approximation.docIDRunEnd());
199+
}
200+
return maxDocIDRunEnd;
201+
}
190202
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.lucene.search;
18+
19+
import java.io.IOException;
20+
import java.util.Arrays;
21+
import org.apache.lucene.tests.util.LuceneTestCase;
22+
import org.apache.lucene.tests.util.TestUtil;
23+
24+
public class TestDisjunctionDISIApproximation extends LuceneTestCase {
25+
26+
public void testDocIDRunEnd() throws IOException {
27+
DocIdSetIterator clause1 = DocIdSetIterator.range(10_000, 30_000);
28+
DocIdSetIterator clause2 = DocIdSetIterator.range(20_000, 50_000);
29+
DocIdSetIterator clause3 = DocIdSetIterator.range(60_000, 60_001);
30+
long leadCost = TestUtil.nextLong(random(), 1, 100_000);
31+
Scorer scorer1 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause1);
32+
Scorer scorer2 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause2);
33+
Scorer scorer3 = new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, clause3);
34+
DocIdSetIterator iterator =
35+
new DisjunctionDISIApproximation(
36+
Arrays.asList(
37+
new DisiWrapper(scorer1, false),
38+
new DisiWrapper(scorer2, false),
39+
new DisiWrapper(scorer3, false)),
40+
leadCost);
41+
assertEquals(10_000, iterator.nextDoc());
42+
assertEquals(30_000, iterator.docIDRunEnd());
43+
assertEquals(25_000, iterator.advance(25_000));
44+
assertEquals(50_000, iterator.docIDRunEnd());
45+
assertEquals(60_000, iterator.advance(50_000));
46+
assertEquals(60_001, iterator.docIDRunEnd());
47+
}
48+
}

0 commit comments

Comments
 (0)