romseygeek commented on code in PR #15083: URL: https://github.com/apache/lucene/pull/15083#discussion_r2282720998
########## lucene/core/src/java/org/apache/lucene/index/DocValuesSkipper.java: ########## @@ -122,4 +123,61 @@ public final void advance(long minValue, long maxValue) throws IOException { advance(maxDocID + 1); } } + + /** + * Returns the minimum value for a field across all segments, or {@link Long#MIN_VALUE} if not + * available + * + * @param searcher a searcher over the index + * @param field the field to retrieve values for + */ + public static long globalMinValue(IndexSearcher searcher, String field) throws IOException { + long minValue = Long.MAX_VALUE; + for (LeafReaderContext ctx : searcher.getLeafContexts()) { + DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(field); + if (skipper == null) { + minValue = Long.MIN_VALUE; + } else { + minValue = Math.min(minValue, skipper.minValue()); + } + } + return minValue; + } + + /** + * Returns the maximum value for a field across all segments, or {@link Long#MIN_VALUE} if not + * available + * + * @param searcher a searcher over the index + * @param field the field to retrieve values for + */ + public static long globalMaxValue(IndexSearcher searcher, String field) throws IOException { + long maxValue = Long.MIN_VALUE; + for (LeafReaderContext ctx : searcher.getLeafContexts()) { + DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(field); + if (skipper == null) { + maxValue = Long.MAX_VALUE; + } else { + maxValue = Math.max(maxValue, skipper.maxValue()); + } + } + return maxValue; + } + + /** + * Returns the total skipper document count for a field across all segments + * + * @param searcher a searcher over the index + * @param field the field to retrieve values for + */ + public static int globalDocCount(IndexSearcher searcher, String field) throws IOException { + int docCount = 0; + for (LeafReaderContext ctx : searcher.getLeafContexts()) { + DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(field); + if (skipper != null) { + docCount += skipper.docCount(); + } + } + return docCount; + } Review Comment: In general I'd expect this to be used to check that all documents in a reader are included in the skipper (ie, there aren't any documents with no value in this field). If you have a MultiReader which includes segments with skippers and segments without, then this will return a value that is less that the top-level reader's `maxDoc()`, so you would know not to use the global values as a shortcut for an all-values-match 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org