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

Support getMaxScore of ConjunctionScorer for non top level scoring clause #13043

Merged
merged 2 commits into from Jan 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Expand Up @@ -202,6 +202,8 @@ Improvements

* GITHUB#12999: Use Automaton for SurroundQuery prefix/pattern matching (Michael Gibney)

* GITHUB#13043: Support getMaxScore of ConjunctionScorer for non top level scoring clause. (Shintaro Murakami)

Optimizations
---------------------

Expand Down
Expand Up @@ -65,22 +65,23 @@ public float score() throws IOException {

@Override
public float getMaxScore(int upTo) throws IOException {
// This scorer is only used for TOP_SCORES when there is at most one scoring clause
switch (scorers.length) {
case 0:
return 0;
case 1:
return scorers[0].getMaxScore(upTo);
default:
return Float.POSITIVE_INFINITY;
double maxScore = 0;
for (Scorer s : scorers) {
if (s.docID() <= upTo) {
maxScore += s.getMaxScore(upTo);
}
}
return (float) maxScore;
}

@Override
public int advanceShallow(int target) throws IOException {
if (scorers.length == 1) {
return scorers[0].advanceShallow(target);
}
for (Scorer scorer : scorers) {
scorer.advanceShallow(target);
}
return super.advanceShallow(target);
}

Expand Down
Expand Up @@ -521,4 +521,20 @@ public void testSingleShouldScoringClause() throws Exception {
assertTrue(clause1.topLevelScoringClause);
assertFalse(clause2.topLevelScoringClause);
}

public void testMaxScoreNonTopLevelScoringClause() throws Exception {
Map<Occur, Collection<ScorerSupplier>> subs = new EnumMap<>(Occur.class);
for (Occur occur : Occur.values()) {
subs.put(occur, new ArrayList<>());
}

FakeScorerSupplier clause1 = new FakeScorerSupplier(10, 10);
subs.get(Occur.MUST).add(clause1);
FakeScorerSupplier clause2 = new FakeScorerSupplier(10, 10);
subs.get(Occur.MUST).add(clause2);

Scorer scorer =
new Boolean2ScorerSupplier(new FakeWeight(), subs, ScoreMode.TOP_SCORES, 0).get(10);
assertEquals(2.0, scorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS), 0.0);
}
}