Skip to content

Commit e5eb7e7

Browse files
authored
Replace oal.search.Score with oal.search.SimpleScorable. (#14852)
`oal.search.SimpleScorable` is a superset of `oal.search.Score`, so we can remove the latter in favor of the former. I also removed a custom `DocAndScore` class which a copy of `SimpleScorable`.
1 parent 0db12c3 commit e5eb7e7

File tree

10 files changed

+72
-114
lines changed

10 files changed

+72
-114
lines changed

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
4141
private final Scorable[] scorables;
4242
private final DocIdSetIterator[] iterators;
4343
private final DocIdSetIterator lead;
44-
private final DocAndScore scorable = new DocAndScore();
44+
private final SimpleScorable scorable = new SimpleScorable();
4545
private final double[] sumOfOtherClauses;
4646
private final int maxDoc;
4747
private final DocAndFloatFeatureBuffer docAndScoreBuffer = new DocAndFloatFeatureBuffer();
@@ -203,20 +203,4 @@ private void scoreWindowScoreFirst(
203203
public long cost() {
204204
return lead.cost();
205205
}
206-
207-
private static class DocAndScore extends Scorable {
208-
209-
float score;
210-
float minCompetitiveScore;
211-
212-
@Override
213-
public float score() throws IOException {
214-
return score;
215-
}
216-
217-
@Override
218-
public void setMinCompetitiveScore(float minScore) throws IOException {
219-
this.minCompetitiveScore = minScore;
220-
}
221-
}
222206
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static class Bucket {
4848
final DisiWrapper[] leads;
4949
final PriorityQueue<DisiWrapper> head;
5050
final PriorityQueue<DisiWrapper> tail;
51-
final Score score = new Score();
51+
final SimpleScorable score = new SimpleScorable();
5252
final int minShouldMatch;
5353
final long cost;
5454
final boolean needsScores;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public int score(final LeafCollector collector, Bits acceptDocs, int min, int ma
255255
throws IOException {
256256
final LeafCollector noScoreCollector =
257257
new LeafCollector() {
258-
Score fake = new Score();
258+
SimpleScorable fake = new SimpleScorable();
259259

260260
@Override
261261
public void setScorer(Scorable scorer) throws IOException {

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
4343
// The minimum value of minCompetitiveScore that would produce a more favorable partitioning.
4444
float nextMinCompetitiveScore;
4545
private final long cost;
46-
float minCompetitiveScore;
47-
private final Score scorable = new Score();
46+
final SimpleScorable scorable = new SimpleScorable();
4847
final double[] maxScoreSums;
4948
private final DisiWrapper filter;
5049

@@ -130,7 +129,7 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max) thr
130129
while (top.doc < outerWindowMax) {
131130
scoreInnerWindow(collector, acceptDocs, outerWindowMax, filter);
132131
top = essentialQueue.top();
133-
if (minCompetitiveScore >= nextMinCompetitiveScore) {
132+
if (scorable.minCompetitiveScore >= nextMinCompetitiveScore) {
134133
// The minimum competitive score increased substantially, so we can now partition scorers
135134
// in a more favorable way.
136135
break;
@@ -255,9 +254,12 @@ private void scoreInnerWindowAsConjunction(LeafCollector collector, Bits acceptD
255254

256255
for (int i = allScorers.length - 2; i >= firstRequiredScorer; --i) {
257256

258-
if (minCompetitiveScore > 0) {
257+
if (scorable.minCompetitiveScore > 0) {
259258
ScorerUtil.filterCompetitiveHits(
260-
docAndScoreAccBuffer, maxScoreSums[i], minCompetitiveScore, allScorers.length);
259+
docAndScoreAccBuffer,
260+
maxScoreSums[i],
261+
scorable.minCompetitiveScore,
262+
allScorers.length);
261263
}
262264

263265
DisiWrapper scorer = allScorers[i];
@@ -371,10 +373,10 @@ private void scoreNonEssentialClauses(
371373

372374
for (int i = numNonEssentialClauses - 1; i >= 0; --i) {
373375
DisiWrapper scorer = allScorers[i];
374-
assert minCompetitiveScore > 0
376+
assert scorable.minCompetitiveScore > 0
375377
: "All clauses are essential if minCompetitiveScore is equal to zero";
376378
ScorerUtil.filterCompetitiveHits(
377-
buffer, maxScoreSums[i], minCompetitiveScore, allScorers.length);
379+
buffer, maxScoreSums[i], scorable.minCompetitiveScore, allScorers.length);
378380
ScorerUtil.applyOptionalClause(buffer, scorer.iterator, scorer.scorable);
379381
scorer.doc = scorer.iterator.docID();
380382
}
@@ -413,7 +415,7 @@ boolean partitionScorers() {
413415
double newMaxScoreSum = maxScoreSum + w.maxWindowScore;
414416
float maxScoreSumFloat =
415417
(float) MathUtil.sumUpperBound(newMaxScoreSum, firstEssentialScorer + 1);
416-
if (maxScoreSumFloat < minCompetitiveScore) {
418+
if (maxScoreSumFloat < scorable.minCompetitiveScore) {
417419
maxScoreSum = newMaxScoreSum;
418420
allScorers[firstEssentialScorer] = w;
419421
maxScoreSums[firstEssentialScorer] = maxScoreSum;
@@ -451,7 +453,7 @@ boolean partitionScorers() {
451453
if (firstRequiredScorer > 1) {
452454
maxPossibleScoreWithoutPreviousClause += maxScoreSums[firstRequiredScorer - 2];
453455
}
454-
if ((float) maxPossibleScoreWithoutPreviousClause >= minCompetitiveScore) {
456+
if ((float) maxPossibleScoreWithoutPreviousClause >= scorable.minCompetitiveScore) {
455457
break;
456458
}
457459
// The sum of maximum scores ignoring the previous clause is less than the minimum
@@ -485,19 +487,4 @@ private int nextCandidate(int rangeEnd) {
485487
public long cost() {
486488
return cost;
487489
}
488-
489-
private class Score extends Scorable {
490-
491-
float score;
492-
493-
@Override
494-
public float score() {
495-
return score;
496-
}
497-
498-
@Override
499-
public void setMinCompetitiveScore(float minScore) throws IOException {
500-
MaxScoreBulkScorer.this.minCompetitiveScore = minScore;
501-
}
502-
}
503490
}

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int top
5555
int docBase = 0;
5656

5757
LeafCollector leafCollector = null;
58-
Score score = new Score();
58+
SimpleScorable score = new SimpleScorable();
5959

6060
while (hitUpto < hits.length) {
6161
ScoreDoc hit = hits[hitUpto];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public BulkScorer bulkScorer() throws IOException {
108108
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
109109
throws IOException {
110110
assert min == 0;
111-
collector.setScorer(new Score());
111+
collector.setScorer(new SimpleScorable());
112112
collector.collect(0);
113113
return DocIdSetIterator.NO_MORE_DOCS;
114114
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -658,23 +658,23 @@ public void testPartition() throws IOException {
658658
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
659659

660660
// less than the minimum score of every clause
661-
scorer.minCompetitiveScore = 0.09f;
661+
scorer.scorable.minCompetitiveScore = 0.09f;
662662
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
663663
scorer.updateMaxWindowScores(4, 100);
664664
assertTrue(scorer.partitionScorers());
665665
assertEquals(0, scorer.firstEssentialScorer); // all clauses are still essential
666666
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
667667

668668
// equal to the maximum score of `the`
669-
scorer.minCompetitiveScore = 0.1f;
669+
scorer.scorable.minCompetitiveScore = 0.1f;
670670
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
671671
scorer.updateMaxWindowScores(4, 100);
672672
assertTrue(scorer.partitionScorers());
673673
assertEquals(0, scorer.firstEssentialScorer); // all clauses are still essential
674674
assertEquals(3, scorer.firstRequiredScorer); // no required clauses
675675

676676
// gt than the minimum score of `the`
677-
scorer.minCompetitiveScore = 0.11f;
677+
scorer.scorable.minCompetitiveScore = 0.11f;
678678
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
679679
scorer.updateMaxWindowScores(4, 100);
680680
assertTrue(scorer.partitionScorers());
@@ -683,7 +683,7 @@ public void testPartition() throws IOException {
683683
assertSame(the, scorer.allScorers[0].scorer);
684684

685685
// equal to the sum of the max scores of the and quick
686-
scorer.minCompetitiveScore = 1.1f;
686+
scorer.scorable.minCompetitiveScore = 1.1f;
687687
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
688688
scorer.updateMaxWindowScores(4, 100);
689689
assertTrue(scorer.partitionScorers());
@@ -692,7 +692,7 @@ public void testPartition() throws IOException {
692692
assertSame(the, scorer.allScorers[0].scorer);
693693

694694
// greater than the sum of the max scores of the and quick
695-
scorer.minCompetitiveScore = 1.11f;
695+
scorer.scorable.minCompetitiveScore = 1.11f;
696696
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
697697
scorer.updateMaxWindowScores(4, 100);
698698
assertTrue(scorer.partitionScorers());
@@ -703,7 +703,7 @@ public void testPartition() throws IOException {
703703
assertSame(fox, scorer.allScorers[2].scorer);
704704

705705
// equal to the sum of the max scores of the and fox
706-
scorer.minCompetitiveScore = 1.2f;
706+
scorer.scorable.minCompetitiveScore = 1.2f;
707707
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
708708
scorer.updateMaxWindowScores(4, 100);
709709
assertTrue(scorer.partitionScorers());
@@ -714,7 +714,7 @@ public void testPartition() throws IOException {
714714
assertSame(fox, scorer.allScorers[2].scorer);
715715

716716
// greater than the sum of the max scores of the and fox
717-
scorer.minCompetitiveScore = 1.21f;
717+
scorer.scorable.minCompetitiveScore = 1.21f;
718718
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
719719
scorer.updateMaxWindowScores(4, 100);
720720
assertTrue(scorer.partitionScorers());
@@ -725,7 +725,7 @@ public void testPartition() throws IOException {
725725
assertSame(fox, scorer.allScorers[2].scorer);
726726

727727
// equal to the sum of the max scores of quick and fox
728-
scorer.minCompetitiveScore = 2.1f;
728+
scorer.scorable.minCompetitiveScore = 2.1f;
729729
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
730730
scorer.updateMaxWindowScores(4, 100);
731731
assertTrue(scorer.partitionScorers());
@@ -736,7 +736,7 @@ public void testPartition() throws IOException {
736736
assertSame(fox, scorer.allScorers[2].scorer);
737737

738738
// greater than the sum of the max scores of quick and fox
739-
scorer.minCompetitiveScore = 2.11f;
739+
scorer.scorable.minCompetitiveScore = 2.11f;
740740
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
741741
scorer.updateMaxWindowScores(4, 100);
742742
assertTrue(scorer.partitionScorers());
@@ -747,7 +747,7 @@ public void testPartition() throws IOException {
747747
assertSame(fox, scorer.allScorers[2].scorer);
748748

749749
// greater than the sum of the max scores of quick and fox
750-
scorer.minCompetitiveScore = 2.11f;
750+
scorer.scorable.minCompetitiveScore = 2.11f;
751751
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
752752
scorer.updateMaxWindowScores(4, 100);
753753
assertTrue(scorer.partitionScorers());
@@ -758,7 +758,7 @@ public void testPartition() throws IOException {
758758
assertSame(fox, scorer.allScorers[2].scorer);
759759

760760
// equal to the sum of the max scores of all terms
761-
scorer.minCompetitiveScore = 2.2f;
761+
scorer.scorable.minCompetitiveScore = 2.2f;
762762
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
763763
scorer.updateMaxWindowScores(4, 100);
764764
assertTrue(scorer.partitionScorers());
@@ -769,7 +769,7 @@ public void testPartition() throws IOException {
769769
assertSame(fox, scorer.allScorers[2].scorer);
770770

771771
// greater than the sum of the max scores of all terms
772-
scorer.minCompetitiveScore = 2.21f;
772+
scorer.scorable.minCompetitiveScore = 2.21f;
773773
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
774774
scorer.updateMaxWindowScores(4, 100);
775775
assertFalse(scorer.partitionScorers()); // no possible match in this window

0 commit comments

Comments
 (0)