Skip to content

Commit 8ec9930

Browse files
committed
feedback iter
1 parent ab6773d commit 8ec9930

File tree

4 files changed

+45
-71
lines changed

4 files changed

+45
-71
lines changed

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

Lines changed: 0 additions & 68 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public BulkScorer bulkScorer() throws IOException {
173173
return ConstantScoreScorerSupplier.fromIterator(iterator, 0f, scoreMode, maxDoc)
174174
.bulkScorer();
175175
}
176-
return new BatchScoreBulkScorer(get(Long.MAX_VALUE));
176+
return new DefaultBulkScorer(get(Long.MAX_VALUE), scoreMode);
177177
}
178178

179179
@Override

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,24 @@ protected static class DefaultBulkScorer extends BulkScorer {
231231
private final Scorer scorer;
232232
private final DocIdSetIterator iterator;
233233
private final TwoPhaseIterator twoPhase;
234+
private final ScoreMode scoreMode;
235+
private DocAndScoreBuffer buffer;
234236

235237
/** Sole constructor. */
236238
public DefaultBulkScorer(Scorer scorer) {
239+
this(scorer, null);
240+
}
241+
242+
/** Sole constructor. */
243+
public DefaultBulkScorer(Scorer scorer, ScoreMode scoreMode) {
237244
this.scorer = Objects.requireNonNull(scorer);
238245
this.twoPhase = scorer.twoPhaseIterator();
239246
if (twoPhase == null) {
240247
this.iterator = scorer.iterator();
241248
} else {
242249
this.iterator = twoPhase.approximation();
243250
}
251+
this.scoreMode = scoreMode;
244252
}
245253

246254
@Override
@@ -251,9 +259,14 @@ public long cost() {
251259
@Override
252260
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
253261
throws IOException {
254-
collector.setScorer(scorer);
255262
DocIdSetIterator competitiveIterator = collector.competitiveIterator();
256263

264+
if (scoreMode != null && scoreMode.needsScores() && competitiveIterator == null) {
265+
return batchScore(collector, acceptDocs, min, max);
266+
}
267+
268+
collector.setScorer(scorer);
269+
257270
if (competitiveIterator != null) {
258271
if (competitiveIterator.docID() > min) {
259272
min = competitiveIterator.docID();
@@ -290,6 +303,35 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
290303
return iterator.docID();
291304
}
292305

306+
private int batchScore(LeafCollector collector, Bits acceptDocs, int min, int max)
307+
throws IOException {
308+
if (buffer == null) {
309+
buffer = new DocAndScoreBuffer();
310+
}
311+
312+
SimpleScorable scorable = new SimpleScorable();
313+
collector.setScorer(scorable);
314+
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
315+
316+
if (scorer.docID() < min) {
317+
scorer.iterator().advance(min);
318+
}
319+
320+
for (scorer.nextDocsAndScores(max, acceptDocs, buffer);
321+
buffer.size > 0;
322+
scorer.nextDocsAndScores(max, acceptDocs, buffer)) {
323+
for (int i = 0, size = buffer.size; i < size; i++) {
324+
float score = scorable.score = buffer.scores[i];
325+
if (score >= scorable.minCompetitiveScore) {
326+
collector.collect(buffer.docs[i]);
327+
}
328+
}
329+
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
330+
}
331+
332+
return scorer.docID();
333+
}
334+
293335
private static void scoreIterator(
294336
LeafCollector collector, Bits acceptDocs, DocIdSetIterator iterator, int max)
295337
throws IOException {

lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void testOptimizeTopLevelClauseOrNull() throws IOException {
201201
weight = searcher.createWeight(searcher.rewrite(query), ScoreMode.COMPLETE, 1);
202202
ss = weight.scorerSupplier(ctx);
203203
scorer = ((BooleanScorerSupplier) ss).booleanScorer();
204-
assertThat(scorer, instanceOf(BatchScoreBulkScorer.class)); // term scorer
204+
assertThat(scorer, instanceOf(DefaultBulkScorer.class)); // term scorer
205205

206206
w.close();
207207
reader.close();

0 commit comments

Comments
 (0)