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

Unit test for https://github.com/apache/lucene/pull/711 #2

Merged
merged 2 commits into from
Mar 3, 2022
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 @@ -127,8 +127,15 @@ void setMinCompetitiveScore(float minScore) throws IOException {
scorers[i].setMinCompetitiveScore(minCompetitiveScore);
}
}

/** Return the minimum score that a Scorer must produce in order for a hit to be competitive. */

/**
* Return the minimum score that a Scorer must produce in order for a hit to be competitive.
*
* The way that boolean queries combine scores of their sub clauses together is by summing up the
* float scores into a double and finally casting back that double back to a float. This method undoes
* this operation by taking the float score sum and subtracting the sum of other scores as a double as
* a first approximation of the minimum score that this clause must have.
*/
private float getMinCompetitiveScore(float minScoreSum, double sumOfOtherMaxScores) {
assert numClauses > 0;

Expand All @@ -146,7 +153,9 @@ private float getMinCompetitiveScore(float minScoreSum, double sumOfOtherMaxScor
// - one because of the error introduced by sumUpperBound
if (iter > 2) {
throw new IllegalStateException(
"Could not compute a minimum score for minScoreSum="
"Could not compute a minimum score for minScore=" +
+ minScore
+ ", minScoreSum="
+ minScoreSum
+ ", sumOfOtherMaxScores="
+ sumOfOtherMaxScores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,27 @@ private void assertMinCompetitiveScore(
(float) scoreSum <= minCompetitiveScore);
}
}

/*
In https://issues.apache.org/jira/browse/LUCENE-10428 we have observed an issue in production
causing an infinite loop in MaxScoreSumPropagator.getMinCompetitiveScore. This is likely
caused by calling code that is breaking the assumptions made by MaxScoreSumPropagator,
e.g. a query that produces negative or NaN scores. This test reproduces that scenario,
and asserts that getMinCompetitiveScore aborts after more than 2 iterations.

See https://github.com/apache/lucene/pull/711.
*/
public void testMinCompetitiveScoreIllegalState() throws Exception {
List<FakeScorer> scorers = new ArrayList<>();
scorers.add(new FakeScorer(-0.16903716f));
scorers.add(new FakeScorer(0.62573546f));
scorers.add(new FakeScorer(-0.64014715f));
float minScoreSum = 0.31314075f;
MaxScoreSumPropagator p = new MaxScoreSumPropagator(scorers);
Throwable exception = assertThrows(IllegalStateException.class, () -> p.setMinCompetitiveScore(minScoreSum));
assertEquals(
"Could not compute a minimum score for minScore=1.1223251, minScoreSum=0.31314072, sumOfOtherMaxScores=-0.8091843128204346, numClauses=3",
exception.getMessage()
);
}
}