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 1cd80db38dbe1..5e248b6271f67 100644 --- a/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java @@ -8,8 +8,6 @@ package org.opensearch.search.approximate; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.PointValues; @@ -224,17 +222,20 @@ private boolean checkValidPointValues(PointValues values) throws IOException { return true; } - private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) throws IOException { + private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) + throws IOException { intersectLeft(visitor, pointTree, count); assert pointTree.moveToParent() == false; } - private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) throws IOException { + private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) + throws IOException { intersectRight(visitor, pointTree, count); assert pointTree.moveToParent() == false; } - private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) throws IOException { + private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) + throws IOException { PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); if (docCount[0] >= count) { return 0; @@ -244,7 +245,8 @@ private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poi // This cell is fully outside the query shape: stop recursing break; case CELL_INSIDE_QUERY: - // If the cell is fully inside, we keep moving to child until we reach a point where we can no longer move or when we have sufficient doc count + // If the cell is fully inside, we keep moving to child until we reach a point where we can no longer move or when + // we have sufficient doc count if (pointTree.moveToChild()) { do { docCount[0] += intersectLeft(visitor, pointTree, count); @@ -285,7 +287,8 @@ private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poi return docCount[0] > 0 ? docCount[0] : 0; } - private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) throws IOException { + private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) + throws IOException { PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); if (docCount[0] >= count) { return 0; @@ -295,9 +298,10 @@ private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Po // This cell is fully outside the query shape: stop recursing break; case CELL_INSIDE_QUERY: - // If the cell is fully inside, we keep moving to child until we reach a point where we can no longer move or when we have sufficient doc count + // If the cell is fully inside, we keep moving to child until we reach a point where we can no longer move or when + // we have sufficient doc count if (pointTree.moveToChild()) { - while (pointTree.moveToSibling() && docCount[0] <= count){ + while (pointTree.moveToSibling() && docCount[0] <= count) { docCount[0] += intersectRight(visitor, pointTree, count); } pointTree.moveToParent(); diff --git a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java index ba5e4c73bdf09..932a86def843e 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -331,9 +331,8 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto if (searchContext.size() > 10_000) ((ApproximatePointRangeQuery) query.getApproximationQuery()).setSize(searchContext.size()); if (searchContext.request() != null && searchContext.request().source() != null) { FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(searchContext.request().source()); - if (primarySortField != null - && primarySortField.missing() == null) { - if(primarySortField.order() == SortOrder.DESC){ + if (primarySortField != null && primarySortField.missing() == null) { + if (primarySortField.order() == SortOrder.DESC) { ((ApproximatePointRangeQuery) query.getApproximationQuery()).setSortOrder(SortOrder.DESC); } } diff --git a/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java b/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java index 51920157eb691..3877dd6952a2d 100644 --- a/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java @@ -102,7 +102,7 @@ public void testApproximateRangeWithSize() throws IOException { pack(upper).bytes, dims, 10, - SortOrder.ASC + SortOrder.ASC ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); @@ -114,7 +114,7 @@ protected String toString(int dimension, byte[] value) { pack(upper).bytes, dims, 100, - SortOrder.ASC + SortOrder.ASC ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); @@ -159,7 +159,14 @@ public void testApproximateRangeShortCircuit() throws IOException { try { long lower = 0; long upper = 100; - Query approximateQuery = new ApproximatePointRangeQuery("point", pack(lower).bytes, pack(upper).bytes, dims, 10, SortOrder.ASC) { + Query approximateQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 10, + SortOrder.ASC + ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); }