LuXugang commented on code in PR #12405: URL: https://github.com/apache/lucene/pull/12405#discussion_r1276083269
########## lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java: ########## @@ -329,87 +324,65 @@ private void updateSkipInterval(boolean success) { * value is 5, we will use a range on [MIN_VALUE, 4]. */ private void encodeBottom() { - if (pruning == Pruning.GREATER_THAN_OR_EQUAL_TO && isBottomMinOrMax() == false) { - byte[] bottom = new byte[bytesCount]; - encodeBottom(bottom); - if (reverse == false) { - NumericUtils.subtract(bytesCount, 0, bottom, deltaOne, maxValueAsBytes); - } else { - NumericUtils.add(bytesCount, 0, bottom, deltaOne, minValueAsBytes); + if (reverse == false) { + encodeBottom(maxValueAsBytes); + if (pruning == Pruning.GREATER_THAN_OR_EQUAL_TO) { + NumericUtils.nextDown(maxValueAsBytes); } } else { - encodeBottom(reverse == false ? maxValueAsBytes : minValueAsBytes); + encodeBottom(minValueAsBytes); + if (pruning == Pruning.GREATER_THAN_OR_EQUAL_TO) { + NumericUtils.nextUp(minValueAsBytes); + } } } - private class CompetitiveIterator extends DocIdSetIterator { - - private final LeafReaderContext context; - private final int maxDoc; - private final String field; - private int doc = -1; - private DocIdSetIterator docsWithDocValue; - private DocIdSetIterator docsWithPoint; - private final boolean skipWithDocValues; - - CompetitiveIterator(LeafReaderContext context, String field, boolean skipWithDocValues) { - this.context = context; - this.maxDoc = context.reader().maxDoc(); - this.field = field; - this.skipWithDocValues = skipWithDocValues; - } - - @Override - public int docID() { - return doc; - } - - @Override - public int nextDoc() throws IOException { - return advance(docID() + 1); - } - - @Override - public int advance(int target) throws IOException { - if (target >= maxDoc) { - return doc = NO_MORE_DOCS; - } else if (docsWithPoint != null) { - assert hitsThresholdReached == true; - return doc = docsWithPoint.advance(target); - } else if (docsWithDocValue != null) { - assert hitsThresholdReached == true; - return doc = docsWithDocValue.advance(target); - } else { - return doc = target; + /** + * If {@link NumericComparator#pruning} equals {@link Pruning#GREATER_THAN_OR_EQUAL_TO}, we + * could better tune the {@link NumericLeafComparator#maxValueAsBytes}/{@link + * NumericLeafComparator#minValueAsBytes}. For instance, if the sort is ascending and top value + * is 3, we will use a range on [4, MAX_VALUE]. + */ + private void encodeTop() { + if (reverse == false) { + encodeTop(minValueAsBytes); + if (pruning == Pruning.GREATER_THAN_OR_EQUAL_TO) { Review Comment: > Oh, indeed, good catch! Can you fix it? addressed in [9d30e0b](https://github.com/apache/lucene/pull/12405/commits/9d30e0b71c0c8a787f352bc39b2faf0c025810fb) -- 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