iverase commented on code in PR #15989:
URL: https://github.com/apache/lucene/pull/15989#discussion_r3153660827
##########
lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java:
##########
@@ -137,140 +137,28 @@ public ScorerSupplier scorerSupplier(LeafReaderContext
context) throws IOExcepti
final NumericDocValues singleton = DocValues.unwrapSingleton(values);
final DocValuesSkipper skipper =
context.reader().getDocValuesSkipper(field);
- if (singleton != null && skipper != null) {
- final DocIdSetIterator psIterator =
- getDocIdSetIteratorOrNullForPrimarySort(context.reader(),
singleton, skipper);
- if (psIterator != null) {
- return ConstantScoreScorerSupplier.fromIterator(psIterator,
score(), scoreMode, maxDoc);
+ if (singleton != null) {
+ if (skipper != null) {
+ final DocIdSetIterator psIterator =
+ getDocIdSetIteratorOrNullForPrimarySort(context.reader(),
singleton, skipper);
+ if (psIterator != null) {
+ return ConstantScoreScorerSupplier.fromIterator(
+ psIterator, score(), scoreMode, maxDoc);
+ }
}
- }
-
- TwoPhaseIterator iterator;
- if (skipper != null) {
- // Use SkipBlockRangeIterator as the approximation: block-level skip
- // filtering with no DV decoding. This exposes block skips to
- // ConjunctionDISI so that when one field's block is NO, other fields
- // never decode DV data for that block.
- final SkipBlockRangeIterator skipApprox =
- new SkipBlockRangeIterator(skipper, lowerValue, upperValue);
- iterator =
- new TwoPhaseIterator(skipApprox) {
- private int cachedBlockEnd = -1;
- private int cachedClassification = BLOCK_MAYBE;
-
- @Override
- public boolean matches() throws IOException {
- int blockMatch = classifyBlockCached();
- if (blockMatch == BLOCK_YES) {
- return true;
- }
- if (blockMatch == BLOCK_IF_DOC_HAS_VALUE) {
- if (singleton != null) {
- return singleton.advanceExact(skipApprox.docID());
- } else {
- return values.advanceExact(skipApprox.docID());
- }
- }
- // MAYBE — need to decode DV and check the actual value.
- if (singleton != null) {
- if (singleton.advanceExact(skipApprox.docID())) {
- final long value = singleton.longValue();
- return value >= lowerValue && value <= upperValue;
- }
- } else {
- if (values.advanceExact(skipApprox.docID())) {
- for (int i = 0, cnt = values.docValueCount(); i < cnt;
++i) {
- final long value = values.nextValue();
- if (value < lowerValue) {
- continue;
- }
- return value <= upperValue;
- }
- }
- }
- return false;
- }
-
- @Override
- public int docIDRunEnd() throws IOException {
- if (classifyBlockCached() == BLOCK_YES) {
- // Only report the current level-0 block as a run. The
- // approximation's docIDRunEnd() may expand to higher
levels
- // that could be MAYBE, not YES.
- return cachedBlockEnd + 1;
- }
- return super.docIDRunEnd();
- }
-
- @Override
- public float matchCost() {
- return 3; // advanceExact + 2 comparisons
- }
-
- private static final int BLOCK_MAYBE = 0;
- private static final int BLOCK_YES = 1;
- private static final int BLOCK_IF_DOC_HAS_VALUE = 2;
-
- private int classifyBlockCached() {
- int blockEnd = skipper.maxDocID(0);
- if (blockEnd != cachedBlockEnd) {
- cachedBlockEnd = blockEnd;
- cachedClassification = classifyBlock();
- }
- return cachedClassification;
- }
-
- private int classifyBlock() {
- long blockMin = skipper.minValue(0);
- long blockMax = skipper.maxValue(0);
- if (blockMin >= lowerValue && blockMax <= upperValue) {
- if (skipper.docCount(0) == skipper.maxDocID(0) -
skipper.minDocID(0) + 1) {
- return BLOCK_YES;
- }
- return BLOCK_IF_DOC_HAS_VALUE;
- }
- return BLOCK_MAYBE;
- }
- };
- } else if (singleton != null) {
- iterator =
- new TwoPhaseIterator(singleton) {
- @Override
- public boolean matches() throws IOException {
- final long value = singleton.longValue();
- return value >= lowerValue && value <= upperValue;
- }
-
- @Override
- public float matchCost() {
- return 2; // 2 comparisons
- }
- };
- } else {
- iterator =
- new TwoPhaseIterator(values) {
- @Override
- public boolean matches() throws IOException {
- for (int i = 0, count = values.docValueCount(); i < count;
++i) {
- final long value = values.nextValue();
- if (value < lowerValue) {
- continue;
- }
- // Values are sorted, so the first value that is >=
lowerValue is our best
- // candidate
- return value <= upperValue;
- }
- return false; // all values were < lowerValue
- }
-
- @Override
- public float matchCost() {
- return 2; // 2 comparisons
- }
- };
+ return ConstantScoreScorerSupplier.fromIterator(
Review Comment:
:heart:
--
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]