From 533fd1ec5f431feb908a4aa2956fb489f5afe969 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Wed, 24 Jul 2024 16:57:52 -0700 Subject: [PATCH] Revert small optimization Signed-off-by: Harsha Vamsi Kalluri --- .../approximate/ApproximatePointRangeQuery.java | 13 ++++++++++++- .../search/approximate/ApproximateScoreQuery.java | 6 +----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java b/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java index 49949e935e7e7..26ed3dbe4e48e 100644 --- a/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java @@ -92,7 +92,18 @@ public final ApproximateConstantScoreWeight createWeight(IndexSearcher searcher, private final ArrayUtil.ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(pointRangeQuery.getBytesPerDim()); private boolean matches(byte[] packedValue) { - return relate(packedValue, packedValue) != PointValues.Relation.CELL_OUTSIDE_QUERY; + for (int dim = 0; dim < pointRangeQuery.getNumDims(); dim++) { + int offset = dim * pointRangeQuery.getBytesPerDim(); + if (comparator.compare(packedValue, offset, pointRangeQuery.getLowerPoint(), offset) < 0) { + // Doc's value is too low, in this dimension + return false; + } + if (comparator.compare(packedValue, offset, pointRangeQuery.getUpperPoint(), offset) > 0) { + // Doc's value is too high, in this dimension + return false; + } + } + return true; } private PointValues.Relation relate(byte[] minPackedValue, byte[] maxPackedValue) { diff --git a/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java b/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java index f6a49a017f3e5..c78ec00142719 100644 --- a/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java @@ -134,11 +134,7 @@ public void visit(QueryVisitor queryVisitor) { @Override public boolean equals(Object o) { - if (!sameClassAs(o)) { - return false; - } - ApproximateScoreQuery that = (ApproximateScoreQuery) o; - return originalQuery.equals(that.originalQuery) && approximationQuery.equals(that.approximationQuery); + return sameClassAs(o); } @Override