LuXugang commented on code in PR #12405:
URL: https://github.com/apache/lucene/pull/12405#discussion_r1266459560
##########
lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java:
##########
@@ -309,34 +323,100 @@ private void updateSkipInterval(boolean success) {
}
}
- @Override
- public DocIdSetIterator competitiveIterator() {
- if (enableSkipping == false) return null;
- return new DocIdSetIterator() {
- private int docID = competitiveIterator.docID();
+ 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 byte[] minPackedValue;
+ private final byte[] maxPackedValue;
+ private final boolean skipWithDocValues;
+
+ CompetitiveIterator(
+ LeafReaderContext context,
+ String field,
+ boolean skipWithDocValues,
+ byte[] minPackedValue,
+ byte[] maxPackedValue) {
+ this.context = context;
+ this.maxDoc = context.reader().maxDoc();
+ this.field = field;
+ this.skipWithDocValues = skipWithDocValues;
+ this.minPackedValue = minPackedValue;
+ this.maxPackedValue = maxPackedValue;
+ }
- @Override
- public int nextDoc() throws IOException {
- return advance(docID + 1);
- }
+ @Override
+ public int docID() {
+ return doc;
+ }
- @Override
- public int docID() {
- return docID;
- }
+ @Override
+ public int nextDoc() throws IOException {
+ return advance(docID() + 1);
+ }
- @Override
- public long cost() {
- return competitiveIterator.cost();
+ @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;
}
+ }
- @Override
- public int advance(int target) throws IOException {
- return docID = competitiveIterator.advance(target);
+ @Override
+ public long cost() {
+ return context.reader().maxDoc();
+ }
+
+ private void setDocsWithDocValue() throws IOException {
+ // if dense == true, all documents have docValues, no sense to skip by
docValues
+ // docsWithDocValue need only init once
+ // if missing values are always competitive, we can never skip via doc
values
+ if (skipWithDocValues
+ && docsWithDocValue == null
+ && isMissingValueNotCompetitive(minPackedValue, maxPackedValue)) {
+ this.docsWithDocValue = getNumericDocValues(context, field);
}
- };
+ }
+
+ private void updateDocsWithPoint(DocIdSetIterator iterator) {
+ this.docsWithPoint = iterator;
+ }
+
+ private long docsWithPointCost() {
+ return docsWithPoint.cost();
+ }
}
+ @Override
+ public DocIdSetIterator competitiveIterator() {
+ return competitiveIterator;
+ }
+
+ /**
+ * if reverse == true, missing value is non-competitive when it less than
minPackedValue, if
+ * reverse == false, missing value is non-competitive when it great than
maxPackedValue
+ */
+ protected abstract boolean isMissingValueNotCompetitive(
+ byte[] minPackedValue, byte[] maxPackedValue);
Review Comment:
addressed in
[69c7259](https://github.com/apache/lucene/pull/12405/commits/69c72591d895813a0d045ee170b26a5de3e0e47e)
--
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]