Skip to content

Commit

Permalink
Remove this usage
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Jul 19, 2024
1 parent 56da01b commit eace4b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@
* after {@code size} is hit
*/
public abstract class ApproximatePointRangeQuery extends Query {
final String field;
final int numDims;
final int bytesPerDim;
final byte[] lowerPoint;
final byte[] upperPoint;

private int size;

Expand All @@ -61,35 +57,15 @@ protected ApproximatePointRangeQuery(String field, byte[] lowerPoint, byte[] upp
}

protected ApproximatePointRangeQuery(String field, byte[] lowerPoint, byte[] upperPoint, int numDims, int size, SortOrder sortOrder) {
checkArgs(field, lowerPoint, upperPoint);
this.field = field;
if (numDims <= 0) {
throw new IllegalArgumentException("numDims must be positive, got " + numDims);
}
if (lowerPoint.length == 0) {
throw new IllegalArgumentException("lowerPoint has length of zero");
}
if (lowerPoint.length % numDims != 0) {
throw new IllegalArgumentException("lowerPoint is not a fixed multiple of numDims");
}
if (lowerPoint.length != upperPoint.length) {
throw new IllegalArgumentException(
"lowerPoint has length=" + lowerPoint.length + " but upperPoint has different length=" + upperPoint.length
);
}
this.numDims = numDims;
this.bytesPerDim = lowerPoint.length / numDims;

this.lowerPoint = lowerPoint;
this.upperPoint = upperPoint;
this.size = size;
this.sortOrder = sortOrder;
this.pointRangeQuery = new PointRangeQuery(field, lowerPoint, upperPoint, numDims) {
@Override
protected String toString(int dimension, byte[] value) {
return ApproximatePointRangeQuery.this.toString();
return super.toString(field);
}
};
this.bytesPerDim = pointRangeQuery.getLowerPoint().length / pointRangeQuery.getNumDims();
}

public int getSize() {
Expand Down Expand Up @@ -132,16 +108,16 @@ private PointValues.Relation relate(byte[] minPackedValue, byte[] maxPackedValue

boolean crosses = false;

for (int dim = 0; dim < numDims; dim++) {
for (int dim = 0; dim < pointRangeQuery.getNumDims(); dim++) {
int offset = dim * bytesPerDim;

if (comparator.compare(minPackedValue, offset, upperPoint, offset) > 0
|| comparator.compare(maxPackedValue, offset, lowerPoint, offset) < 0) {
if (comparator.compare(minPackedValue, offset, pointRangeQuery.getUpperPoint(), offset) > 0
|| comparator.compare(maxPackedValue, offset, pointRangeQuery.getLowerPoint(), offset) < 0) {
return PointValues.Relation.CELL_OUTSIDE_QUERY;
}

crosses |= comparator.compare(minPackedValue, offset, lowerPoint, offset) < 0
|| comparator.compare(maxPackedValue, offset, upperPoint, offset) > 0;
crosses |= comparator.compare(minPackedValue, offset, pointRangeQuery.getLowerPoint(), offset) < 0
|| comparator.compare(maxPackedValue, offset, pointRangeQuery.getUpperPoint(), offset) > 0;
}

if (crosses) {
Expand Down Expand Up @@ -208,20 +184,20 @@ private boolean checkValidPointValues(PointValues values) throws IOException {
return false;
}

if (values.getNumIndexDimensions() != numDims) {
if (values.getNumIndexDimensions() != pointRangeQuery.getNumDims()) {
throw new IllegalArgumentException(
"field=\""
+ field
+ pointRangeQuery.getField()
+ "\" was indexed with numIndexDimensions="
+ values.getNumIndexDimensions()
+ " but this query has numDims="
+ numDims
+ pointRangeQuery.getNumDims()
);
}
if (bytesPerDim != values.getBytesPerDimension()) {
throw new IllegalArgumentException(
"field=\""
+ field
+ pointRangeQuery.getField()
+ "\" was indexed with bytesPerDim="
+ values.getBytesPerDimension()
+ " but this query has bytesPerDim="
Expand Down Expand Up @@ -351,7 +327,7 @@ private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Po
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
LeafReader reader = context.reader();

PointValues values = (PointValues) reader.getPointValues(field);
PointValues values = (PointValues) reader.getPointValues(pointRangeQuery.getField());
if (checkValidPointValues(values) == false) {
return null;
}
Expand All @@ -361,10 +337,10 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
} else {
final byte[] fieldPackedLower = values.getMinPackedValue();
final byte[] fieldPackedUpper = values.getMaxPackedValue();
for (int i = 0; i < numDims; ++i) {
for (int i = 0; i < pointRangeQuery.getNumDims(); ++i) {
int offset = i * bytesPerDim;
if (comparator.compare(lowerPoint, offset, fieldPackedUpper, offset) > 0
|| comparator.compare(upperPoint, offset, fieldPackedLower, offset) < 0) {
if (comparator.compare(pointRangeQuery.getLowerPoint(), offset, fieldPackedUpper, offset) > 0
|| comparator.compare(pointRangeQuery.getUpperPoint(), offset, fieldPackedLower, offset) < 0) {
// If this query is a required clause of a boolean query, then returning null here
// will help make sure that we don't call ScorerSupplier#get on other required clauses
// of the same boolean query, which is an expensive operation for some queries (e.g.
Expand All @@ -379,10 +355,10 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
final byte[] fieldPackedLower = values.getMinPackedValue();
final byte[] fieldPackedUpper = values.getMaxPackedValue();
allDocsMatch = true;
for (int i = 0; i < numDims; ++i) {
for (int i = 0; i < pointRangeQuery.getNumDims(); ++i) {
int offset = i * bytesPerDim;
if (comparator.compare(lowerPoint, offset, fieldPackedLower, offset) > 0
|| comparator.compare(upperPoint, offset, fieldPackedUpper, offset) < 0) {
if (comparator.compare(pointRangeQuery.getLowerPoint(), offset, fieldPackedLower, offset) > 0
|| comparator.compare(pointRangeQuery.getUpperPoint(), offset, fieldPackedUpper, offset) < 0) {
allDocsMatch = false;
break;
}
Expand All @@ -409,7 +385,7 @@ public long cost() {
if (sortOrder.equals(SortOrder.ASC)) {
return new ScorerSupplier() {

final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, field);
final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, pointRangeQuery.getField());
final PointValues.IntersectVisitor visitor = getIntersectVisitor(result);
long cost = -1;

Expand All @@ -433,7 +409,7 @@ public long cost() {
}
return new ScorerSupplier() {

final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, field);
final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, pointRangeQuery.getField());
final PointValues.IntersectVisitor visitor = getIntersectVisitor(result);
long cost = -1;

Expand Down Expand Up @@ -565,23 +541,23 @@ public final boolean equals(Object o) {
@Override
public final String toString(String field) {
final StringBuilder sb = new StringBuilder();
if (this.field.equals(field) == false) {
sb.append(this.field);
if (pointRangeQuery.getField().equals(field) == false) {
sb.append(pointRangeQuery.getField());
sb.append(':');
}

// print ourselves as "range per dimension"
for (int i = 0; i < numDims; i++) {
for (int i = 0; i < pointRangeQuery.getNumDims(); i++) {
if (i > 0) {
sb.append(',');
}

int startOffset = bytesPerDim * i;

sb.append('[');
sb.append(toString(i, ArrayUtil.copyOfSubArray(lowerPoint, startOffset, startOffset + bytesPerDim)));
sb.append(toString(i, ArrayUtil.copyOfSubArray(pointRangeQuery.getLowerPoint(), startOffset, startOffset + bytesPerDim)));
sb.append(" TO ");
sb.append(toString(i, ArrayUtil.copyOfSubArray(upperPoint, startOffset, startOffset + bytesPerDim)));
sb.append(toString(i, ArrayUtil.copyOfSubArray(pointRangeQuery.getUpperPoint(), startOffset, startOffset + bytesPerDim)));
sb.append(']');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Query getApproximationQuery() {

@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
this.originalQueryWeight = originalQuery.createWeight(searcher, scoreMode, boost);
this.approximationQueryWeight = approximationQuery.createWeight(searcher, scoreMode, boost);
originalQueryWeight = originalQuery.createWeight(searcher, scoreMode, boost);
approximationQueryWeight = approximationQuery.createWeight(searcher, scoreMode, boost);

return new Weight(this) {
@Override
Expand Down

0 comments on commit eace4b9

Please sign in to comment.