slow-J commented on code in PR #16271:
URL: https://github.com/apache/lucene/pull/16271#discussion_r3497891276
##########
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);
+ }
+
+ /** Explains why a doc was not collected, by recomputing its score. null
when no vectors. */
+ private Explanation explainNotCollected(
+ LeafReaderContext context, int doc, int topN, Weight filterWeight, float
minTopKScore)
+ throws IOException {
+ String prefix = "Not in top " + topN + " doc(s): ";
+ FieldInfo fi = context.reader().getFieldInfos().fieldInfo(field);
+ if (fi == null || fi.getVectorDimension() == 0) {
+ return null;
Review Comment:
It would fall back to the generic `"Not in top " + docs.length + " doc(s)`,
in DocAndScoreQuery's createWeight#explain
https://github.com/slow-J/lucene/blob/KNNexplain/lucene/core/src/java/org/apache/lucene/search/DocAndScoreQuery.java#L164
--
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]