Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,16 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
}

int maxDoc = context.reader().maxDoc();
DocValuesSkipper skipper = context.reader().getDocValuesSkipper(field);
if (skipper != null) {
if (skipper.minValue() > upperValue || skipper.maxValue() < lowerValue) {
return null;
}
if (skipper.docCount() == maxDoc
&& skipper.minValue() >= lowerValue
&& skipper.maxValue() <= upperValue) {

return ConstantScoreScorerSupplier.matchAll(score(), scoreMode, maxDoc);
}
int count = docCount(context);
if (count == 0) {
return null;
} else if (count == 1) {
return ConstantScoreScorerSupplier.matchAll(score(), scoreMode, maxDoc);
}

SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), field);
final NumericDocValues singleton = DocValues.unwrapSingleton(values);
final DocValuesSkipper skipper = context.reader().getDocValuesSkipper(field);
TwoPhaseIterator iterator;
if (singleton != null) {
if (skipper != null) {
Expand Down Expand Up @@ -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 {
final DocValuesSkipper skipper = context.reader().getDocValuesSkipper(field);
if (skipper != null) {
if (skipper.minValue() > upperValue || skipper.maxValue() < lowerValue) {
return 0;
}
if (skipper.docCount() == context.reader().maxDoc()
&& skipper.minValue() >= lowerValue
&& skipper.maxValue() <= upperValue) {

return 1;
}
}

return -1;
}
};
Expand Down
Loading