msfroh commented on code in PR #13987: URL: https://github.com/apache/lucene/pull/13987#discussion_r1840841444
########## 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); + } + + for (int i = 0; i < scores.length; i++) { + assertEquals(scores[i], scc.mscores[i * 2], 0f); + assertEquals(scores[i], scc.mscores[i * 2 + 1], 0f); + } + + assertEquals(scores.length, countingScorable.count); Review Comment: This is similar to the other test method (`testGetScores`), but we assert that each score is collected twice (since we collect each document twice), but the `score()` method is only called once per document. -- 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