Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dummy scorables. #14046

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class BlockMaxConjunctionBulkScorer extends BulkScorer {
private final DocIdSetIterator[] iterators;
private final DocIdSetIterator lead1, lead2;
private final Scorable scorer1, scorer2;
private final DocAndScore scorable = new DocAndScore();
private final SimpleScorable scorable = new SimpleScorable();
private final double[] sumOfOtherClauses;
private final int maxDoc;

Expand Down Expand Up @@ -202,20 +202,4 @@ private void scoreWindow(
public long cost() {
return lead1.cost();
}

private static class DocAndScore extends Scorable {

float score;
float minCompetitiveScore;

@Override
public float score() throws IOException {
return score;
}

@Override
public void setMinCompetitiveScore(float minScore) throws IOException {
this.minCompetitiveScore = minScore;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DisiWrapper get(int i) {
final DisiWrapper[] leads;
final HeadPriorityQueue head;
final TailPriorityQueue tail;
final Score score = new Score();
final SimpleScorable score = new SimpleScorable();
final int minShouldMatch;
final long cost;
final boolean needsScores;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public int score(final LeafCollector collector, Bits acceptDocs, int min, int ma
throws IOException {
final LeafCollector noScoreCollector =
new LeafCollector() {
Score fake = new Score();
SimpleScorable fake = new SimpleScorable();

@Override
public void setScorer(Scorable scorer) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public BulkScorer bulkScorer() throws IOException {
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
throws IOException {
max = Math.min(max, maxDoc);
Score scorer = new Score();
SimpleScorable scorer = new SimpleScorable();
scorer.score = score;
collector.setScorer(scorer);
for (int doc = min; doc < max; ++doc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ final class MaxScoreBulkScorer extends BulkScorer {
// The minimum value of minCompetitiveScore that would produce a more favorable partitioning.
float nextMinCompetitiveScore;
private final long cost;
float minCompetitiveScore;
private final Score scorable = new Score();
final SimpleScorable scorable = new SimpleScorable();
final double[] maxScoreSums;
private final DisiWrapper filter;

Expand Down Expand Up @@ -127,7 +126,7 @@ public int score(LeafCollector collector, Bits acceptDocs, int min, int max) thr
while (top.doc < outerWindowMax) {
scoreInnerWindow(collector, acceptDocs, outerWindowMax, filter);
top = essentialQueue.top();
if (minCompetitiveScore >= nextMinCompetitiveScore) {
if (scorable.minCompetitiveScore >= nextMinCompetitiveScore) {
// The minimum competitive score increased substantially, so we can now partition scorers
// in a more favorable way.
break;
Expand Down Expand Up @@ -254,7 +253,7 @@ private void scoreInnerWindowAsConjunction(LeafCollector collector, Bits acceptD
// We specialize handling the second best scorer, which seems to help a bit with performance.
// But this is the exact same logic as in the below for loop.
if ((float) MathUtil.sumUpperBound(score + maxScoreSumAtLead2, allScorers.length)
< minCompetitiveScore) {
< scorable.minCompetitiveScore) {
// a competitive match is not possible according to max scores, skip to the next candidate
lead1.doc = lead1.iterator.nextDoc();
continue;
Expand All @@ -272,7 +271,7 @@ private void scoreInnerWindowAsConjunction(LeafCollector collector, Bits acceptD

for (int i = allScorers.length - 3; i >= firstRequiredScorer; --i) {
if ((float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length)
< minCompetitiveScore) {
< scorable.minCompetitiveScore) {
// a competitive match is not possible according to max scores, skip to the next candidate
lead1.doc = lead1.iterator.nextDoc();
continue outer;
Expand Down Expand Up @@ -389,7 +388,7 @@ private void scoreNonEssentialClauses(
for (int i = numNonEssentialClauses - 1; i >= 0; --i) {
float maxPossibleScore =
(float) MathUtil.sumUpperBound(score + maxScoreSums[i], allScorers.length);
if (maxPossibleScore < minCompetitiveScore) {
if (maxPossibleScore < scorable.minCompetitiveScore) {
// Hit is not competitive.
return;
}
Expand Down Expand Up @@ -435,7 +434,7 @@ boolean partitionScorers() {
double newMaxScoreSum = maxScoreSum + w.maxWindowScore;
float maxScoreSumFloat =
(float) MathUtil.sumUpperBound(newMaxScoreSum, firstEssentialScorer + 1);
if (maxScoreSumFloat < minCompetitiveScore) {
if (maxScoreSumFloat < scorable.minCompetitiveScore) {
maxScoreSum = newMaxScoreSum;
allScorers[firstEssentialScorer] = w;
maxScoreSums[firstEssentialScorer] = maxScoreSum;
Expand Down Expand Up @@ -473,7 +472,7 @@ boolean partitionScorers() {
if (firstRequiredScorer > 1) {
maxPossibleScoreWithoutPreviousClause += maxScoreSums[firstRequiredScorer - 2];
}
if ((float) maxPossibleScoreWithoutPreviousClause >= minCompetitiveScore) {
if ((float) maxPossibleScoreWithoutPreviousClause >= scorable.minCompetitiveScore) {
break;
}
// The sum of maximum scores ignoring the previous clause is less than the minimum
Expand Down Expand Up @@ -507,19 +506,4 @@ private int nextCandidate(int rangeEnd) {
public long cost() {
return cost;
}

private class Score extends Scorable {

float score;

@Override
public float score() {
return score;
}

@Override
public void setMinCompetitiveScore(float minScore) throws IOException {
MaxScoreBulkScorer.this.minCompetitiveScore = minScore;
}
}
}
30 changes: 0 additions & 30 deletions lucene/core/src/java/org/apache/lucene/search/Score.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int top
int docBase = 0;

LeafCollector leafCollector = null;
Score score = new Score();
SimpleScorable score = new SimpleScorable();

while (hitUpto < hits.length) {
ScoreDoc hit = hits[hitUpto];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public BulkScorer bulkScorer() throws IOException {
public int score(LeafCollector collector, Bits acceptDocs, int min, int max)
throws IOException {
assert min == 0;
collector.setScorer(new Score());
collector.setScorer(new SimpleScorable());
collector.collect(0);
return DocIdSetIterator.NO_MORE_DOCS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testWrapped2Times() throws Exception {

// for the combined BQ, the scorer should always be BooleanScorer's BucketScorer, because our
// scorer supports out-of order collection!
final Class<Score> bucketScorerClass = Score.class;
final Class<SimpleScorable> bucketScorerClass = SimpleScorable.class;
checkHits(searcher, csqbq, csqbq.getBoost(), bucketScorerClass);
} finally {
IOUtils.close(reader, directory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,23 +658,23 @@ public void testPartition() throws IOException {
assertEquals(3, scorer.firstRequiredScorer); // no required clauses

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

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

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

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

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

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

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

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

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

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

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

// greater than the sum of the max scores of all terms
scorer.minCompetitiveScore = 2.21f;
scorer.scorable.minCompetitiveScore = 2.21f;
Collections.shuffle(Arrays.asList(scorer.allScorers), random());
scorer.updateMaxWindowScores(4, 100);
assertFalse(scorer.partitionScorers()); // no possible match in this window
Expand Down
Loading
Loading