msfroh commented on code in PR #13987:
URL: https://github.com/apache/lucene/pull/13987#discussion_r1841125795


##########
lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java:
##########
@@ -157,4 +157,40 @@ public void testGetScores() throws Exception {
     ir.close();
     directory.close();
   }
+
+  private static class CountingScorable extends FilterScorable {
+    int count = 0;
+
+    public CountingScorable(Scorable in) {
+      super(in);
+    }
+
+    @Override
+    public float score() throws IOException {
+      count++;
+      return in.score();
+    }
+  }
+
+  public void testRepeatedCollectReusesScore() throws Exception {
+    Scorer s = new SimpleScorer();
+    CountingScorable countingScorable = new CountingScorable(s);
+    ScoreCachingCollector scc = new ScoreCachingCollector(scores.length * 2);
+    LeafCollector lc = scc.getLeafCollector(null);
+    lc.setScorer(countingScorable);
+
+    // We need to iterate on the scorer so that its doc() advances.
+    int doc;
+    while ((doc = s.iterator().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+      lc.collect(doc);
+      lc.collect(doc);

Review Comment:
   Yeah -- that's why I'd hesitate to really call this a "bug fix". 
   
   I'm pretty sure you meant to write `lastDoc = currDoc` in 
https://github.com/apache/lucene/pull/12407, but functionally `currDoc = 
lastDoc` works fine as long as you don't call `collect()` multiple times on the 
same doc.
   
   I only noticed this because I was [copy/pasting the 
logic](https://github.com/opensearch-project/OpenSearch/pull/16366/files#diff-45fac6161bed1775163b916fba9ea296fbe9a8adf931a48593672c5c558a114b)
 to adapt it for `LeafBucketCollector` in OpenSearch and IntelliJ warned me 
that `lastDoc` could be `final`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to