jpountz commented on code in PR #12003: URL: https://github.com/apache/lucene/pull/12003#discussion_r1045084049
########## lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java: ########## @@ -212,9 +212,9 @@ public boolean isCacheable(LeafReaderContext ctx) { @Override public int count(LeafReaderContext context) throws IOException { if (context.reader().hasDeletions() == false) { - BoundedDocIdSetIterator disi = getDocIdSetIteratorOrNull(context); - if (disi != null && disi.delegate == null) { - return disi.lastDoc - disi.firstDoc; + DocIdSetIterator disi = getDocIdSetIteratorOrNull(context); + if (disi != null && disi instanceof BoundedDocIdSetIterator == false) { + return Math.toIntExact(disi.cost()); Review Comment: I worry that this might be a bit fragile since cost() has no guarantee to be accurate. I wonder if we could make `getDocIdSetIteratorOrNull()` return both a `DocIdSetIterator` and a number of matches (possibly -1 when unknown) to make this less trappy. -- 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