mirror of https://github.com/apache/lucene.git
Allow implementers of AbstractKnnVectorQuery to access final topK results (#12590)
* Make AbstractKnnVectorQuery#createRewrittenQuery protected * Add explicit method to merge per-segment results * Add javadocs explaining the new method * Run gradlew tidy --------- Co-authored-by: Kaival Parikh <kaivalnp@amazon.com>
This commit is contained in:
parent
91019d685a
commit
2474940bff
|
@ -88,7 +88,7 @@ abstract class AbstractKnnVectorQuery extends Query {
|
|||
TopDocs[] perLeafResults = taskExecutor.invokeAll(tasks).toArray(TopDocs[]::new);
|
||||
|
||||
// Merge sort the results
|
||||
TopDocs topK = TopDocs.merge(k, perLeafResults);
|
||||
TopDocs topK = mergeLeafResults(perLeafResults);
|
||||
if (topK.scoreDocs.length == 0) {
|
||||
return new MatchNoDocsQuery();
|
||||
}
|
||||
|
@ -200,6 +200,22 @@ abstract class AbstractKnnVectorQuery extends Query {
|
|||
return new TopDocs(totalHits, topScoreDocs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges all segment-level kNN results to get the index-level kNN results.
|
||||
*
|
||||
* <p>The default implementation delegates to {@link TopDocs#merge(int, TopDocs[])} to find the
|
||||
* overall top {@link #k}, which requires input results to be sorted.
|
||||
*
|
||||
* <p>This method is useful for reading and / or modifying the final results as needed.
|
||||
*
|
||||
* @param perLeafResults array of segment-level kNN results.
|
||||
* @return index-level kNN results (no constraint on their ordering).
|
||||
* @lucene.experimental
|
||||
*/
|
||||
protected TopDocs mergeLeafResults(TopDocs[] perLeafResults) {
|
||||
return TopDocs.merge(k, perLeafResults);
|
||||
}
|
||||
|
||||
private Query createRewrittenQuery(IndexReader reader, TopDocs topK) {
|
||||
int len = topK.scoreDocs.length;
|
||||
|
||||
|
|
Loading…
Reference in New Issue