Skip to content

Commit c075548

Browse files
HUSTERGSgesong.samuel
andauthored
Implement ConstantScoreScorer#nextDocsAndScores (#14772)
Co-authored-by: gesong.samuel <[email protected]>
1 parent e4c9978 commit c075548

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ Optimizations
185185

186186
* GITHUB#14834: Optimize CombinedFieldQuery by nextDocsAndScores. (Ge Song)
187187

188+
* GITHUB#14772: Implement ConstantScoreScorer#nextDocsAndScores. (Ge Song)
189+
188190
Bug Fixes
189191
---------------------
190192
* GITHUB#14654: ValueSource.fromDoubleValuesSource(dvs).getSortField() would throw errors when

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.apache.lucene.search;
1818

1919
import java.io.IOException;
20+
import java.util.Arrays;
21+
import org.apache.lucene.util.Bits;
2022

2123
/**
2224
* A constant-scoring {@link Scorer}.
@@ -144,4 +146,21 @@ public int docID() {
144146
public float score() throws IOException {
145147
return score;
146148
}
149+
150+
@Override
151+
public void nextDocsAndScores(int upTo, Bits liveDocs, DocAndFloatFeatureBuffer buffer)
152+
throws IOException {
153+
int batchSize = 64;
154+
buffer.growNoCopy(batchSize);
155+
int size = 0;
156+
DocIdSetIterator iterator = iterator();
157+
for (int doc = iterator.docID(); doc < upTo && size < batchSize; doc = iterator.nextDoc()) {
158+
if (liveDocs == null || liveDocs.get(doc)) {
159+
buffer.docs[size] = doc;
160+
++size;
161+
}
162+
}
163+
Arrays.fill(buffer.features, 0, size, score);
164+
buffer.size = size;
165+
}
147166
}

0 commit comments

Comments
 (0)