Skip to content

Commit d1ac4b1

Browse files
committed
Revert "Merge branch 'opt_term_query' into int_score"
This reverts commit 212d73d, reversing changes made to ac598df.
1 parent de56623 commit d1ac4b1

File tree

4 files changed

+71
-48
lines changed

4 files changed

+71
-48
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 org.apache.lucene.util.Bits;
21+
22+
/**
23+
* A bulk scorer used when {@link ScoreMode#needsScores()} is true and {@link
24+
* Scorer#nextDocsAndScores} has optimizations to run faster than one-by-one iteration.
25+
*/
26+
class BatchScoreBulkScorer extends BulkScorer {
27+
28+
private final SimpleScorable scorable = new SimpleScorable();
29+
private final DocAndScoreBuffer buffer = new DocAndScoreBuffer();
30+
private final Scorer scorer;
31+
32+
BatchScoreBulkScorer(Scorer scorer) {
33+
this.scorer = scorer;
34+
}
35+
36+
@Override
37+
public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException {
38+
if (collector.competitiveIterator() != null) {
39+
return new Weight.DefaultBulkScorer(scorer).score(collector, acceptDocs, min, max);
40+
}
41+
42+
collector.setScorer(scorable);
43+
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
44+
45+
if (scorer.docID() < min) {
46+
scorer.iterator().advance(min);
47+
}
48+
49+
for (scorer.nextDocsAndScores(max, acceptDocs, buffer);
50+
buffer.size > 0;
51+
scorer.nextDocsAndScores(max, acceptDocs, buffer)) {
52+
for (int i = 0, size = buffer.size; i < size; i++) {
53+
float score = scorable.score = buffer.scores[i];
54+
if (score >= scorable.minCompetitiveScore) {
55+
collector.collect(buffer.docs[i]);
56+
}
57+
}
58+
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
59+
}
60+
61+
return scorer.docID();
62+
}
63+
64+
@Override
65+
public long cost() {
66+
return scorer.iterator().cost();
67+
}
68+
}

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 DefaultBulkScorer(get(Long.MAX_VALUE), scoreMode);
176+
return new BatchScoreBulkScorer(get(Long.MAX_VALUE));
177177
}
178178

179179
@Override

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

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -231,25 +231,16 @@ 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;
236-
private SimpleScorable scorable;
237234

238235
/** Sole constructor. */
239236
public DefaultBulkScorer(Scorer scorer) {
240-
this(scorer, null);
241-
}
242-
243-
/** Sole constructor. */
244-
public DefaultBulkScorer(Scorer scorer, ScoreMode scoreMode) {
245237
this.scorer = Objects.requireNonNull(scorer);
246238
this.twoPhase = scorer.twoPhaseIterator();
247239
if (twoPhase == null) {
248240
this.iterator = scorer.iterator();
249241
} else {
250242
this.iterator = twoPhase.approximation();
251243
}
252-
this.scoreMode = scoreMode;
253244
}
254245

255246
@Override
@@ -260,13 +251,8 @@ public long cost() {
260251
@Override
261252
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
262253
throws IOException {
263-
DocIdSetIterator competitiveIterator = collector.competitiveIterator();
264-
265-
if (scoreMode != null && scoreMode.needsScores() && competitiveIterator == null) {
266-
return batchScore(collector, acceptDocs, min, max);
267-
}
268-
269254
collector.setScorer(scorer);
255+
DocIdSetIterator competitiveIterator = collector.competitiveIterator();
270256

271257
if (competitiveIterator != null) {
272258
if (competitiveIterator.docID() > min) {
@@ -304,37 +290,6 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
304290
return iterator.docID();
305291
}
306292

307-
private int batchScore(LeafCollector collector, Bits acceptDocs, int min, int max)
308-
throws IOException {
309-
if (buffer == null) {
310-
buffer = new DocAndScoreBuffer();
311-
}
312-
if (scorable == null) {
313-
scorable = new SimpleScorable();
314-
}
315-
316-
collector.setScorer(scorable);
317-
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
318-
319-
if (scorer.docID() < min) {
320-
scorer.iterator().advance(min);
321-
}
322-
323-
for (scorer.nextDocsAndScores(max, acceptDocs, buffer);
324-
buffer.size > 0;
325-
scorer.nextDocsAndScores(max, acceptDocs, buffer)) {
326-
for (int i = 0, size = buffer.size; i < size; i++) {
327-
float score = scorable.score = buffer.scores[i];
328-
if (score >= scorable.minCompetitiveScore) {
329-
collector.collect(buffer.docs[i]);
330-
}
331-
}
332-
scorer.setMinCompetitiveScore(scorable.minCompetitiveScore);
333-
}
334-
335-
return scorer.docID();
336-
}
337-
338293
private static void scoreIterator(
339294
LeafCollector collector, Bits acceptDocs, DocIdSetIterator iterator, int max)
340295
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(DefaultBulkScorer.class)); // term scorer
204+
assertThat(scorer, instanceOf(BatchScoreBulkScorer.class)); // term scorer
205205

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

0 commit comments

Comments
 (0)