Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointInSetQuery clips segments by lower and upper #14268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public abstract class PointInSetQuery extends Query implements Accountable {
final int numDims;
final int bytesPerDim;
final long ramBytesUsed; // cache
byte[] lowerPoint = null;
byte[] upperPoint = null;

/** Iterator of encoded point values. */
// TODO: if we want to stream, maybe we should use jdk stream class?
Expand Down Expand Up @@ -108,6 +110,8 @@ protected PointInSetQuery(String field, int numDims, int bytesPerDim, Stream pac
}
if (previous == null) {
previous = new BytesRefBuilder();
lowerPoint = new byte[bytesPerDim * numDims];
System.arraycopy(current.bytes, current.offset, lowerPoint, 0, lowerPoint.length);
} else {
int cmp = previous.get().compareTo(current);
if (cmp == 0) {
Expand All @@ -122,6 +126,11 @@ protected PointInSetQuery(String field, int numDims, int bytesPerDim, Stream pac
}
sortedPackedPoints = builder.finish();
sortedPackedPointsHashCode = sortedPackedPoints.hashCode();
if (previous != null) {
BytesRef max = previous.get();
upperPoint = new byte[bytesPerDim * numDims];
System.arraycopy(max.bytes, max.offset, upperPoint, 0, upperPoint.length);
}
ramBytesUsed =
BASE_RAM_BYTES
+ RamUsageEstimator.sizeOfObject(field)
Expand Down Expand Up @@ -153,6 +162,21 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
return null;
}

if (values.getDocCount() == 0) {
return null;
} else if (lowerPoint != null && upperPoint != null) {
ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(bytesPerDim);
final byte[] fieldPackedLower = values.getMinPackedValue();
final byte[] fieldPackedUpper = values.getMaxPackedValue();
for (int i = 0; i < numDims; ++i) {
int offset = i * bytesPerDim;
if (comparator.compare(lowerPoint, offset, fieldPackedUpper, offset) > 0
|| comparator.compare(upperPoint, offset, fieldPackedLower, offset) < 0) {
return null;
}
}
}

if (values.getNumIndexDimensions() != numDims) {
throw new IllegalArgumentException(
"field=\""
Expand Down