iprithv commented on code in PR #16271:
URL: https://github.com/apache/lucene/pull/16271#discussion_r3444262064
##########
lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java:
##########
@@ -149,9 +149,64 @@ public Query rewrite(IndexSearcher indexSearcher) throws
IOException {
topK = runSearchTasks(tasks, taskExecutor, perLeafResults,
leafReaderContexts);
}
if (topK.scoreDocs.length == 0) {
- return MatchNoDocsQuery.INSTANCE;
+ return new MatchNoDocsQuery("No documents matched the nearest-neighbor
search");
}
- return DocAndScoreQuery.createDocAndScoreQuery(reader, topK, reentryCount);
+ return DocAndScoreQuery.createDocAndScoreQuery(
+ reader, topK, reentryCount, noMatchExplainer(topK, filterWeight));
+ }
+
+ /** Builds the explainer for documents this query did not collect, capturing
minTopKScore. */
+ private DocAndScoreQuery.NoMatchExplainer noMatchExplainer(TopDocs topK,
Weight filterWeight) {
+ // topK is score-descending, so the lowest collected score is the last
entry.
+ final float minTopKScore = topK.scoreDocs[topK.scoreDocs.length - 1].score;
+ return (context, doc, topN) ->
+ explainNotCollected(context, doc, topN, filterWeight, minTopKScore);
Review Comment:
filterWeight here was created during rewrite() against a specific reader.
But explain() can be called later with a different reader. when that happens,
filterWeight.scorer(context) gets a LeafReaderContext it wasn't built for,
which could blow up.
match side is fine since scores/docs are already materialized in the array.
but this no-match path re-evaluates the filter live, so it has this
stale-reader risk.
can you add a try/catch around the filter check.
--
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]