-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Specialize filterCompetitiveHits
when have exact 2 clauses
#14827
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
base: main
Are you sure you want to change the base?
Conversation
This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice speedup! I wonder if we can make it work in the general case with something like that (untested):
diff --git a/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java b/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
index 5c677d7a464..0b1e2f30a6e 100644
--- a/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/search/ScorerUtil.java
@@ -128,15 +128,20 @@ class ScorerUtil {
double maxRemainingScore,
float minCompetitiveScore,
int numScorers) {
- if ((float) MathUtil.sumUpperBound(maxRemainingScore, numScorers) >= minCompetitiveScore) {
+
+ // Compute minRequiredScore as the greatest float value so that (float) MathUtil.sumUpperBound(minRequiredScore + maxRemainingScore, numScorers) <= minCompetitiveScore.
+ float minRequiredScore = (float) (minCompetitiveScore - maxRemainingScore);
+ while ((float) MathUtil.sumUpperBound(minRequiredScore + maxRemainingScore, numScorers) > minCompetitiveScore) {
+ minRequiredScore = Math.nextDown(minRequiredScore);
+ }
+
+ if (minRequiredScore <= 0) {
return;
}
int newSize = 0;
for (int i = 0; i < buffer.size; ++i) {
- float maxPossibleScore =
- (float) MathUtil.sumUpperBound(buffer.scores[i] + maxRemainingScore, numScorers);
- if (maxPossibleScore >= minCompetitiveScore) {
+ if (buffer.scores[i] >= minRequiredScore) {
buffer.docs[newSize] = buffer.docs[i];
buffer.scores[newSize] = buffer.scores[i];
newSize++;
FWIW I could confirm a speedup as well with this change on wiibigall. |
This PR does not have an entry in lucene/CHANGES.txt. Consider adding one. If the PR doesn't need a changelog entry, then add the skip-changelog label to it and you will stop receiving this reminder on future updates to the PR. |
This suggests that the |
Got it, I'll dig into this, thanks for your explaination! It helps me a lot :) |
Description
This PR propose to specialize function
filterCompetitiveHits
when we have exact 2 scorers, in order to reduce float calculation and potential function callsLuceneutil result on
wikimediumall
withsearchConcurrency=0
,taskCountPerCat=5
,taskRepeatCount=50
after 20 iterations