Skip to content

Commit

Permalink
Fix toString implementation
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 eace4b9 commit ce9261b
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import java.util.function.BiFunction;
import java.util.function.Predicate;

import static org.apache.lucene.search.PointRangeQuery.checkArgs;

/**
* An approximate-able version of {@link PointRangeQuery}. It creates an instance of {@link PointRangeQuery} but short-circuits the intersect logic
* after {@code size} is hit
Expand Down Expand Up @@ -62,7 +60,28 @@ protected ApproximatePointRangeQuery(String field, byte[] lowerPoint, byte[] upp
this.pointRangeQuery = new PointRangeQuery(field, lowerPoint, upperPoint, numDims) {
@Override
protected String toString(int dimension, byte[] value) {
return super.toString(field);
final StringBuilder sb = new StringBuilder();
if (pointRangeQuery.getField().equals(field) == false) {
sb.append(pointRangeQuery.getField());
sb.append(':');
}

// print ourselves as "range per dimension"
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(pointRangeQuery.getLowerPoint(), startOffset, startOffset + bytesPerDim)));
sb.append(" TO ");
sb.append(toString(i, ArrayUtil.copyOfSubArray(pointRangeQuery.getUpperPoint(), startOffset, startOffset + bytesPerDim)));
sb.append(']');
}

return sb.toString();
}
};
this.bytesPerDim = pointRangeQuery.getLowerPoint().length / pointRangeQuery.getNumDims();
Expand Down

0 comments on commit ce9261b

Please sign in to comment.