-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Update lastDoc in ScoreCachingWrappingScorer #13987
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,44 @@ public void testGetScores() throws Exception { | |
ir.close(); | ||
directory.close(); | ||
} | ||
|
||
private static class CountingScorable extends FilterScorable { | ||
int count; | ||
|
||
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); | ||
// We're going to collect every document twice, so we need to allocate a 2x larger array. | ||
ScoreCachingCollector scc = new ScoreCachingCollector(scores.length * 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment about why we need |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's illegal to call collect() multiple times on the same doc, this shouldn't be necessary as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah -- that's why I'd hesitate to really call this a "bug fix". I'm pretty sure you meant to write I only noticed this because I was copy/pasting the logic to adapt it for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm why are we collecting the same Oh I see, is so Does this new test case fail if you revert the bug fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test does fail if I revert the fix. As I mentioned in #13987 (comment), the condition for this being an actual bug is probably not really valid (i.e. you need to call The caching does work if the wrapped
The multiple calls to Those other two tests broke because my "fix" causes the caching to work (but they didn't expect it). |
||
} | ||
|
||
// Verify that each score was collected twice. | ||
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); | ||
} | ||
|
||
// But we only call score() on the underlying scorer once per document, because scores are | ||
// cached. | ||
assertEquals(scores.length, countingScorable.count); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,7 +359,7 @@ public void testTotalHitsWithScore() throws Exception { | |
leafCollector.collect(1); | ||
|
||
scorer.score = 4; | ||
leafCollector.collect(1); | ||
leafCollector.collect(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another pre-existing test bug fixed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the change, the call to |
||
|
||
TopDocs topDocs = collector.topDocs(); | ||
assertEquals(totalHitsThreshold < 4, scorer.minCompetitiveScore != null); | ||
|
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.
Wow, good catch! So this was a latent pre-existing test bug, and with your above bug fix this test is now (correctly!) failing, and with your fix to this separate test bug, the test now passes?