From 552b3f52d74ea5d1e7dab44d61e08d0569a5a306 Mon Sep 17 00:00:00 2001 From: Michael Froh Date: Tue, 3 Dec 2024 10:24:41 -0800 Subject: [PATCH] Simplify logic in ScoreCachingWrappingScorer (#14012) This is functionally equivalent to the logic that was present, but makes the behavior clearer. --- .../lucene/search/ScoreCachingWrappingScorer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java b/lucene/core/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java index e9a23921ece..9ebc053a660 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java @@ -31,8 +31,7 @@ import java.util.Collections; */ public final class ScoreCachingWrappingScorer extends Scorable { - private int lastDoc = -1; - private int curDoc = -1; + private boolean scoreIsCached; private float curScore; private final Scorable in; @@ -64,7 +63,8 @@ public final class ScoreCachingWrappingScorer extends Scorable { @Override public void collect(int doc) throws IOException { if (scorer != null) { - scorer.curDoc = doc; + // Invalidate cache when collecting a new doc + scorer.scoreIsCached = false; } super.collect(doc); } @@ -82,9 +82,9 @@ public final class ScoreCachingWrappingScorer extends Scorable { @Override public float score() throws IOException { - if (lastDoc != curDoc) { + if (scoreIsCached == false) { curScore = in.score(); - curDoc = lastDoc; + scoreIsCached = true; } return curScore;