jpountz commented on code in PR #15123:
URL: https://github.com/apache/lucene/pull/15123#discussion_r2303961450
##########
lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java:
##########
@@ -199,19 +194,30 @@ public float matchCost() {
@Override
public int count(LeafReaderContext context) throws IOException {
- DocValuesSkipper skipper = context.reader().getDocValuesSkipper(field);
- if (skipper == null) {
- return -1;
- }
- if (skipper.minValue() > upperValue || skipper.maxValue() <
lowerValue) {
- return 0;
- }
- if (skipper.docCount() == context.reader().maxDoc()
- && skipper.minValue() >= lowerValue
- && skipper.maxValue() <= upperValue) {
+ int cnt = docCount(context);
+ return switch (cnt) {
+ case 1 -> context.reader().numDocs();
+ default -> cnt;
+ };
+ }
- return context.reader().numDocs();
+ /* Returning 1 instead of LeafReader#numDocs as it may run in O(maxDoc)
+ * which is unnecessary when docCount is invoked from ScorerSupplier
+ */
+ private int docCount(LeafReaderContext context) throws IOException {
Review Comment:
I wonder if calling it `docCountIgnoringDeletes` and returning `maxDoc`
instead of 1 would make the contract of this method a bit less awkward?
--
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]