slow-J commented on code in PR #16271:
URL: https://github.com/apache/lucene/pull/16271#discussion_r3448263295
##########
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:
I added the guard as proposed above and confirmed that it works as intended.
Steps taken to confirmed it:
1. Opened two indexes with readerA and readerB.
2. Created a KNN query and rewrote it with searcherA, creating the
DocAndScoreQuery, and then called createWeight to get weightA.
3. Called the `explain(Weight, int)` with `searcherB.explain(weightA, 6)`;
Without the guard, the IndexSearcher#explain(Weight, int) gives an incorrect
explanation, with the check it gives the generic `Not in top X doc(s).` message.
--
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]