gsmiller commented on code in PR #15803:
URL: https://github.com/apache/lucene/pull/15803#discussion_r2960596460
##########
lucene/core/src/java/org/apache/lucene/index/ReaderUtil.java:
##########
@@ -89,4 +93,82 @@ public static int subIndex(int n, List<LeafReaderContext>
leaves) {
}
return hi;
}
+
+ /**
+ * Partitions global doc IDs from ScoreDoc array by leaf. Extracts doc IDs,
sorts them, and
+ * partitions across leaves.
+ *
+ * @param hits the ScoreDoc array (typically from TopDocs.scoreDocs)
+ * @param leaves the index reader's leaves
+ * @return array indexed by leaf ord, containing global doc IDs for that
leaf (empty if no hits)
+ */
+ public static int[][] partitionByLeaf(ScoreDoc[] hits,
List<LeafReaderContext> leaves) {
+ int[] docIds = new int[hits.length];
+ for (int i = 0; i < hits.length; i++) {
+ docIds[i] = hits[i].doc;
+ }
+ Arrays.sort(docIds);
+ return partitionByLeaf(docIds, leaves);
+ }
+
+ /**
+ * Partitions sorted global doc IDs by leaf.
+ *
+ * @param sortedDocIds global doc IDs, must be sorted ascending
+ * @param leaves the index reader's leaves
+ * @return array indexed by leaf ord, containing global doc IDs for that
leaf (empty if no hits)
+ */
+ public static int[][] partitionByLeaf(int[] sortedDocIds,
List<LeafReaderContext> leaves) {
Review Comment:
I was thinking about this a bit more and I wonder if we should actually
remove this method in favor of only adding the method that takes ScoreDoc[] as
input? It's kind of trappy to add two similar methods but where one requires
input data to be sorted and the other doesn't. I'm also not sure there's a
use-case for this "lower level" version of the logic that users would use? I
think the most likely use-cases all involve calling code that has a ScoreDoc[]
as input. We could always come back and add a method with this signature later
if there's a need for it, but it would be nice to keep the API lean and
narrowly focused to start.
--
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]