epotyom commented on code in PR #16700:
URL: https://github.com/apache/lucene/pull/16700#discussion_r4402646297
##########
lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java:
##########
@@ -78,21 +82,41 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs
firstPassTopDocs, int top
// We advanced to another segment:
docBase = readerContext.docBase;
scorer = weight.scorer(readerContext);
+ lastCheckedDoc = -1;
+ lastCheckedMatch = false;
+ if (scorer == null) {
+ iterator = null;
+ twoPhase = null;
+ } else {
+ twoPhase = scorer.twoPhaseIterator();
+ // Only confirm the first-pass hits. Advancing the iterator of a
two-phase scorer would
+ // confirm every approximation match until the next matching
document.
+ iterator = twoPhase == null ? scorer.iterator() :
twoPhase.approximation();
+ }
}
if (scorer != null) {
int targetDoc = docID - docBase;
- int actualDoc = scorer.docID();
+ int actualDoc = iterator.docID();
if (actualDoc < targetDoc) {
- actualDoc = scorer.iterator().advance(targetDoc);
+ actualDoc = iterator.advance(targetDoc);
+ }
+
+ boolean secondPassMatches = actualDoc == targetDoc;
+ if (secondPassMatches && twoPhase != null) {
+ if (actualDoc != lastCheckedDoc) {
Review Comment:
I suppose in practice we don't usually have duplicates to rescore, so
lastCheckedDoc is kind of redundant? At the same time `twoPhase.matches();`
javadoc says it can only be called once, so looks like we have to keep
lastCheckedDoc just in case.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]