diff --git a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java index 9a717eccc7b76..67c221cc8355f 100644 --- a/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/DateFieldMapper.java @@ -63,7 +63,7 @@ import org.opensearch.index.query.QueryShardContext; import org.opensearch.search.DocValueFormat; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.search.lookup.SearchLookup; import java.io.IOException; @@ -467,28 +467,10 @@ public Query rangeQuery( } DateMathParser parser = forcedDateParser == null ? dateMathParser : forcedDateParser; return dateRangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, timeZone, parser, context, resolution, (l, u) -> { + Query pointRangeQuery = createPointRangeQuery(l, u); + Query dvQuery = hasDocValues() ? SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u) : null; if (isSearchable() && hasDocValues()) { - Query query = new ApproximateableQuery( - new PointRangeQuery(name(), pack(new long[] { l }).bytes, pack(new long[] { u }).bytes, new long[] { l }.length) { - protected String toString(int dimension, byte[] value) { - return Long.toString(LongPoint.decodeDimension(value, 0)); - } - }, - new ApproximatePointRangeQuery( - name(), - pack(new long[] { l }).bytes, - pack(new long[] { u }).bytes, - new long[] { l }.length - ) { - @Override - protected String toString(int dimension, byte[] value) { - return Long.toString(LongPoint.decodeDimension(value, 0)); - } - } - ); - - Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u); - query = new IndexOrDocValuesQuery(query, dvQuery); + Query query = new IndexOrDocValuesQuery(pointRangeQuery, dvQuery); if (context.indexSortedOnField(name())) { query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query); @@ -502,25 +484,29 @@ protected String toString(int dimension, byte[] value) { } return query; } - return new ApproximateableQuery( - new PointRangeQuery(name(), pack(new long[] { l }).bytes, pack(new long[] { u }).bytes, new long[] { l }.length) { + return pointRangeQuery; + }); + } + + private Query createPointRangeQuery(long l, long u) { + return new ApproximateScoreQuery( + new PointRangeQuery(name(), pack(new long[]{l}).bytes, pack(new long[]{u}).bytes, new long[]{l}.length) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }, new ApproximatePointRangeQuery( - name(), - pack(new long[] { l }).bytes, - pack(new long[] { u }).bytes, - new long[] { l }.length + name(), + pack(new long[]{l}).bytes, + pack(new long[]{u}).bytes, + new long[]{l}.length ) { @Override protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } } - ); - }); + ); } public static Query dateRangeQuery( diff --git a/server/src/main/java/org/opensearch/search/approximate/ApproximateConstantScoreWeight.java b/server/src/main/java/org/opensearch/search/approximate/ApproximateConstantScoreWeight.java new file mode 100644 index 0000000000000..f2c41619a82cc --- /dev/null +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximateConstantScoreWeight.java @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.search.approximate; + +import org.apache.lucene.index.PointValues; +import org.apache.lucene.search.ConstantScoreWeight; +import org.apache.lucene.search.Query; +import org.apache.lucene.util.DocIdSetBuilder; + +import java.io.IOException; + +public abstract class ApproximateConstantScoreWeight extends ConstantScoreWeight { + + protected ApproximateConstantScoreWeight(Query query, float score) { + super(query, score); + } + + protected abstract long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException; + + protected abstract long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException; + + protected abstract PointValues.IntersectVisitor getIntersectVisitor(DocIdSetBuilder result) throws IOException; + +} 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 709d0c655f3bb..c2b93d9680a9c 100644 --- a/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java @@ -87,13 +87,11 @@ public void visit(QueryVisitor visitor) { } @Override - public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { + public final ApproximateConstantScoreWeight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { Weight pointRangeQueryWeight = pointRangeQuery.createWeight(searcher, scoreMode, boost); - // We don't use RandomAccessWeight here: it's no good to approximate with "match all docs". - // This is an inverted structure and should be used in the first pass: - return new ConstantScoreWeight(this, boost) { + return new ApproximateConstantScoreWeight(this, boost) { private final ArrayUtil.ByteArrayComparator comparator = ArrayUtil.getUnsignedComparator(pointRangeQuery.getBytesPerDim()); @@ -124,7 +122,7 @@ private PointValues.Relation relate(byte[] minPackedValue, byte[] maxPackedValue } } - private PointValues.IntersectVisitor getIntersectVisitor(DocIdSetBuilder result) { + public PointValues.IntersectVisitor getIntersectVisitor(DocIdSetBuilder result) { return new PointValues.IntersectVisitor() { DocIdSetBuilder.BulkAdder adder; @@ -136,7 +134,9 @@ public void grow(int count) { @Override public void visit(int docID) { - if (docCount[0] <= size) { + // it is possible that size < 1024 and docCount < size but we will continue to count through all the 1024 docs + // and collect less, but it won't hurt performance + if (docCount[0] < size) { adder.add(docID); docCount[0]++; } @@ -204,23 +204,23 @@ private boolean checkValidPointValues(PointValues values) throws IOException { return true; } - private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) + private void intersectLeft(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor) throws IOException { - intersectLeft(visitor, pointTree, count); + intersectLeft(visitor, pointTree); assert pointTree.moveToParent() == false; } - private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor, int count) + private void intersectRight(PointValues.PointTree pointTree, PointValues.IntersectVisitor visitor) throws IOException { - intersectRight(visitor, pointTree, count); + intersectRight(visitor, pointTree); assert pointTree.moveToParent() == false; } // custom intersect visitor to walk the left of the tree - private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) + public long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException { PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); - if (docCount[0] >= count) { + if (docCount[0] >= size) { return 0; } switch (r) { @@ -232,12 +232,12 @@ private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poi // we have sufficient doc count. We first move down and then move to the left child if (pointTree.moveToChild()) { do { - docCount[0] += intersectLeft(visitor, pointTree, count); - } while (pointTree.moveToSibling() && docCount[0] <= count); + docCount[0] += intersectLeft(visitor, pointTree); + } while (pointTree.moveToSibling() && docCount[0] <= size); pointTree.moveToParent(); } else { - // we're at the leaf node, if we're under the count, visit all the docIds in this node. - if (docCount[0] <= count) { + // we're at the leaf node, if we're under the size, visit all the docIds in this node. + if (docCount[0] < size) { pointTree.visitDocIDs(visitor); docCount[0] += pointTree.size(); return docCount[0]; @@ -249,14 +249,14 @@ private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poi // through and do full filtering: if (pointTree.moveToChild()) { do { - docCount[0] += intersectLeft(visitor, pointTree, count); - } while (pointTree.moveToSibling() && docCount[0] <= count); + docCount[0] += intersectLeft(visitor, pointTree); + } while (pointTree.moveToSibling() && docCount[0] <= size); pointTree.moveToParent(); } else { // TODO: we can assert that the first value here in fact matches what the pointTree // claimed? // Leaf node; scan and filter all points in this block: - if (docCount[0] <= count) { + if (docCount[0] < size) { pointTree.visitDocValues(visitor); } else break; } @@ -269,10 +269,10 @@ private long intersectLeft(PointValues.IntersectVisitor visitor, PointValues.Poi } // custom intersect visitor to walk the right of tree - private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, int count) + public long intersectRight(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree) throws IOException { PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); - if (docCount[0] >= count) { + if (docCount[0] >= size) { return 0; } switch (r) { @@ -283,13 +283,13 @@ private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Po // 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. We first move down and then move right if (pointTree.moveToChild()) { - while (pointTree.moveToSibling() && docCount[0] <= count) { - docCount[0] += intersectRight(visitor, pointTree, count); + while (pointTree.moveToSibling() && docCount[0] <= size) { + docCount[0] += intersectRight(visitor, pointTree); } pointTree.moveToParent(); } else { - // we're at the leaf node, if we're under the count, visit all the docIds in this node. - if (docCount[0] <= count) { + // we're at the leaf node, if we're under the size, visit all the docIds in this node. + if (docCount[0] <= size) { pointTree.visitDocIDs(visitor); docCount[0] += pointTree.size(); return docCount[0]; @@ -301,14 +301,14 @@ private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Po // through and do full filtering: if (pointTree.moveToChild()) { do { - docCount[0] += intersectRight(visitor, pointTree, count); - } while (pointTree.moveToSibling() && docCount[0] <= count); + docCount[0] += intersectRight(visitor, pointTree); + } while (pointTree.moveToSibling() && docCount[0] <= size); pointTree.moveToParent(); } else { // TODO: we can assert that the first value here in fact matches what the pointTree // claimed? // Leaf node; scan and filter all points in this block: - if (docCount[0] <= count) { + if (docCount[0] <= size) { pointTree.visitDocValues(visitor); } else break; } @@ -316,7 +316,7 @@ private long intersectRight(PointValues.IntersectVisitor visitor, PointValues.Po default: throw new IllegalArgumentException("Unreachable code"); } - // docCount can be updated by the local visitor so we ensure that we return docCount after pointTree.visitDocValues(visitor) + // docCount can be updated by the local visitor, so we ensure that we return docCount after pointTree.visitDocValues(visitor) return docCount[0] > 0 ? docCount[0] : 0; } @@ -324,7 +324,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(pointRangeQuery.getField()); + PointValues values = reader.getPointValues(pointRangeQuery.getField()); if (checkValidPointValues(values) == false) { return null; } @@ -388,7 +388,7 @@ public long cost() { @Override public Scorer get(long leadCost) throws IOException { - intersectLeft(values.getPointTree(), visitor, size); + intersectLeft(values.getPointTree(), visitor); DocIdSetIterator iterator = result.build().iterator(); return new ConstantScoreScorer(weight, score(), scoreMode, iterator); } @@ -412,7 +412,7 @@ public long cost() { @Override public Scorer get(long leadCost) throws IOException { - intersectRight(values.getPointTree(), visitor, size); + intersectRight(values.getPointTree(), visitor); DocIdSetIterator iterator = result.build().iterator(); return new ConstantScoreScorer(weight, score(), scoreMode, iterator); } @@ -432,7 +432,11 @@ public long cost() { @Override public Scorer scorer(LeafReaderContext context) throws IOException { - return pointRangeQueryWeight.scorer(context); + ScorerSupplier scorerSupplier = scorerSupplier(context); + if (scorerSupplier == null) { + return null; + } + return scorerSupplier.get(Long.MAX_VALUE); } @Override @@ -440,87 +444,9 @@ public int count(LeafReaderContext context) throws IOException { return pointRangeQueryWeight.count(context); } - /** - * Finds the number of points matching the provided range conditions. Using this method is - * faster than calling {@link PointValues#intersect(PointValues.IntersectVisitor)} to get the count of - * intersecting points. This method does not enforce live documents, therefore it should only - * be used when there are no deleted documents. - * - * @param pointTree start node of the count operation - * @param nodeComparator comparator to be used for checking whether the internal node is - * inside the range - * @param leafComparator comparator to be used for checking whether the leaf node is inside - * the range - * @return count of points that match the range - */ - private long pointCount( - PointValues.PointTree pointTree, - BiFunction nodeComparator, - Predicate leafComparator - ) throws IOException { - final long[] matchingNodeCount = { 0 }; - // create a custom IntersectVisitor that records the number of leafNodes that matched - final PointValues.IntersectVisitor visitor = new PointValues.IntersectVisitor() { - @Override - public void visit(int docID) { - // this branch should be unreachable - throw new UnsupportedOperationException( - "This IntersectVisitor does not perform any actions on a " + "docID=" + docID + " node being visited" - ); - } - - @Override - public void visit(int docID, byte[] packedValue) { - if (leafComparator.test(packedValue)) { - matchingNodeCount[0]++; - } - } - - @Override - public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { - return nodeComparator.apply(minPackedValue, maxPackedValue); - } - }; - pointCount(visitor, pointTree, matchingNodeCount); - return matchingNodeCount[0]; - } - - private void pointCount(PointValues.IntersectVisitor visitor, PointValues.PointTree pointTree, long[] matchingNodeCount) - throws IOException { - PointValues.Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue()); - switch (r) { - case CELL_OUTSIDE_QUERY: - // This cell is fully outside the query shape: return 0 as the count of its nodes - return; - case CELL_INSIDE_QUERY: - // This cell is fully inside the query shape: return the size of the entire node as the - // count - matchingNodeCount[0] += pointTree.size(); - return; - case CELL_CROSSES_QUERY: - /* - The cell crosses the shape boundary, or the cell fully contains the query, so we fall - through and do full counting. - */ - if (pointTree.moveToChild()) { - do { - pointCount(visitor, pointTree, matchingNodeCount); - } while (pointTree.moveToSibling()); - pointTree.moveToParent(); - } else { - // we have reached a leaf node here. - pointTree.visitDocValues(visitor); - // leaf node count is saved in the matchingNodeCount array by the visitor - } - return; - default: - throw new IllegalArgumentException("Unreachable code"); - } - } - @Override public boolean isCacheable(LeafReaderContext ctx) { - return pointRangeQueryWeight.isCacheable(ctx); + return true; } }; } diff --git a/server/src/main/java/org/opensearch/search/approximate/ApproximateableQuery.java b/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java similarity index 86% rename from server/src/main/java/org/opensearch/search/approximate/ApproximateableQuery.java rename to server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java index 9de060711dab0..f6a49a017f3e5 100644 --- a/server/src/main/java/org/opensearch/search/approximate/ApproximateableQuery.java +++ b/server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java @@ -23,19 +23,21 @@ import java.io.IOException; /** - * Base class for a query that can be approximated + * Base class for a query that can be approximated. + * + * This class is heavily inspired by {@link org.apache.lucene.search.IndexOrDocValuesQuery}. It acts as a wrapper that consumer two queries, a regular query and an approximate version of the same. By default, it executes the regular query and returns {@link Weight#scorer} for the original query. At run-time, depending on certain constraints, we can re-write the {@code Weight} to use the approximate weight instead. */ -public final class ApproximateableQuery extends Query { +public final class ApproximateScoreQuery extends Query { private final Query originalQuery, approximationQuery; private Weight originalQueryWeight, approximationQueryWeight; - public ApproximateableQuery(Query originalQuery, Query approximationQuery) { + public ApproximateScoreQuery(Query originalQuery, Query approximationQuery) { this(originalQuery, approximationQuery, null, null); } - public ApproximateableQuery( + public ApproximateScoreQuery( Query originalQuery, Query approximationQuery, Weight originalQueryWeight, @@ -116,7 +118,7 @@ public boolean isCacheable(LeafReaderContext leafReaderContext) { @Override public String toString(String s) { - return "ApproximateableQuery(originalQuery=" + return "ApproximateScoreQuery(originalQuery=" + originalQuery.toString() + ", approximationQuery=" + approximationQuery.toString() @@ -135,7 +137,7 @@ public boolean equals(Object o) { if (!sameClassAs(o)) { return false; } - ApproximateableQuery that = (ApproximateableQuery) o; + ApproximateScoreQuery that = (ApproximateScoreQuery) o; return originalQuery.equals(that.originalQuery) && approximationQuery.equals(that.approximationQuery); } 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 932a86def843e..7e0c675d696d3 100644 --- a/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java +++ b/server/src/main/java/org/opensearch/search/internal/ContextIndexSearcher.java @@ -72,7 +72,7 @@ import org.opensearch.search.DocValueFormat; import org.opensearch.search.SearchService; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.search.dfs.AggregatedDfs; import org.opensearch.search.profile.ContextualProfileBreakdown; import org.opensearch.search.profile.Timer; @@ -327,7 +327,7 @@ private void searchLeaf(LeafReaderContext ctx, Weight weight, Collector collecto Bits liveDocs = ctx.reader().getLiveDocs(); BitSet liveDocsBitSet = getSparseBitSetOrNull(liveDocs); if (isApproximateableRangeQuery()) { - ApproximateableQuery query = ((ApproximateableQuery) ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery()); + ApproximateScoreQuery query = ((ApproximateScoreQuery) ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery()); 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()); @@ -432,8 +432,8 @@ private static BitSet getSparseBitSetOrNull(Bits liveDocs) { private boolean isApproximateableRangeQuery() { return searchContext.query() instanceof IndexOrDocValuesQuery - && ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery() instanceof ApproximateableQuery - && ((ApproximateableQuery) ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery()) + && ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery() instanceof ApproximateScoreQuery + && ((ApproximateScoreQuery) ((IndexOrDocValuesQuery) searchContext.query()).getIndexQuery()) .getOriginalQuery() instanceof PointRangeQuery; } diff --git a/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java b/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java index 02c923acca290..cef4c2a31d099 100644 --- a/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/DateFieldTypeTests.java @@ -67,7 +67,7 @@ import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.QueryShardContext; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.joda.time.DateTimeZone; import java.io.IOException; @@ -212,7 +212,7 @@ public void testTermQuery() { String date = "2015-10-12T14:10:55"; long instant = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date)).toInstant().toEpochMilli(); Query expected = new IndexOrDocValuesQuery( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( "field", pack(new long[] { instant }).bytes, @@ -237,7 +237,7 @@ protected String toString(int dimension, byte[] value) { ), SortedNumericDocValuesField.newSlowRangeQuery("field", instant, instant + 999) ); - assertEquals(expected.toString(), ft.termQuery(date, context).toString()); + assertEquals(expected, ft.termQuery(date, context)); MappedFieldType unsearchable = new DateFieldType( "field", @@ -284,7 +284,7 @@ public void testRangeQuery() throws IOException { long instant1 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date1)).toInstant().toEpochMilli(); long instant2 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date2)).toInstant().toEpochMilli() + 999; Query expected = new IndexOrDocValuesQuery( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( "field", pack(new long[] { instant1 }).bytes, @@ -310,15 +310,15 @@ protected String toString(int dimension, byte[] value) { SortedNumericDocValuesField.newSlowRangeQuery("field", instant1, instant2) ); assertEquals( - expected.toString(), - ft.rangeQuery(date1, date2, true, true, null, null, null, context).rewrite(new IndexSearcher(new MultiReader())).toString() + expected, + ft.rangeQuery(date1, date2, true, true, null, null, null, context).rewrite(new IndexSearcher(new MultiReader())) ); instant1 = nowInMillis; instant2 = instant1 + 100; expected = new DateRangeIncludingNowQuery( new IndexOrDocValuesQuery( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( "field", pack(new long[] { instant1 }).bytes, @@ -344,7 +344,7 @@ protected String toString(int dimension, byte[] value) { SortedNumericDocValuesField.newSlowRangeQuery("field", instant1, instant2) ) ); - assertEquals(expected.toString(), ft.rangeQuery("now", instant2, true, true, null, null, null, context).toString()); + assertEquals(expected, ft.rangeQuery("now", instant2, true, true, null, null, null, context)); MappedFieldType unsearchable = new DateFieldType( "field", @@ -400,7 +400,7 @@ public void testRangeQueryWithIndexSort() { long instant1 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date1)).toInstant().toEpochMilli(); long instant2 = DateFormatters.from(DateFieldMapper.getDefaultDateTimeFormatter().parse(date2)).toInstant().toEpochMilli() + 999; - Query pointQuery = new ApproximateableQuery( + Query pointQuery = new ApproximateScoreQuery( new PointRangeQuery( "field", pack(new long[] { instant1 }).bytes, @@ -430,7 +430,7 @@ protected String toString(int dimension, byte[] value) { instant2, new IndexOrDocValuesQuery(pointQuery, dvQuery) ); - assertEquals(expected.toString(), ft.rangeQuery(date1, date2, true, true, null, null, null, context).toString()); + assertEquals(expected, ft.rangeQuery(date1, date2, true, true, null, null, null, context)); } public void testDateNanoDocValues() throws IOException { diff --git a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java index 725b6e6ef6238..496ab4370b399 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java @@ -50,7 +50,7 @@ import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.QueryStringQueryBuilder; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.test.AbstractQueryTestCase; import java.io.IOException; @@ -176,7 +176,7 @@ public void testDateRangeQuery() throws Exception { DateFieldMapper.DateFieldType dateType = (DateFieldMapper.DateFieldType) context.fieldMapper(DATE_FIELD_NAME); parser = dateType.dateMathParser; Query queryOnDateField = new QueryStringQueryBuilder(DATE_FIELD_NAME + ":[2010-01-01 TO 2018-01-01]").toQuery(createShardContext()); - Query controlQuery = new ApproximateableQuery( + Query controlQuery = new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { parser.parse(lowerBoundExact, () -> 0).toEpochMilli() }).bytes, @@ -205,7 +205,7 @@ protected String toString(int dimension, byte[] value) { parser.parse(lowerBoundExact, () -> 0).toEpochMilli(), parser.parse(upperBoundExact, () -> 0).toEpochMilli() ); - assertEquals(new IndexOrDocValuesQuery(controlQuery, controlDv).toString(), queryOnDateField.toString()); + assertEquals(new IndexOrDocValuesQuery(controlQuery, controlDv), queryOnDateField); } public void testIPRangeQuery() throws Exception { diff --git a/server/src/test/java/org/opensearch/index/mapper/RangeFieldTypeTests.java b/server/src/test/java/org/opensearch/index/mapper/RangeFieldTypeTests.java index 239b4d4677dfe..c6abca23ceb53 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RangeFieldTypeTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RangeFieldTypeTests.java @@ -57,7 +57,7 @@ import org.opensearch.index.mapper.RangeFieldMapper.RangeFieldType; import org.opensearch.index.query.QueryShardContext; import org.opensearch.index.query.QueryShardException; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.test.IndexSettingsModule; import org.joda.time.DateTime; import org.junit.Before; @@ -288,7 +288,7 @@ public void testDateRangeQueryUsingMappingFormatLegacy() { final Query queryOnDateField = dateFieldType.rangeQuery(from, to, true, true, relation, null, fieldType.dateMathParser(), context); assertEquals( "field:[1465975790000 TO 1466062190999]", - ((ApproximateableQuery) ((IndexOrDocValuesQuery) queryOnDateField).getIndexQuery()).getOriginalQuery().toString() + ((ApproximateScoreQuery) ((IndexOrDocValuesQuery) queryOnDateField).getIndexQuery()).getOriginalQuery().toString() ); } diff --git a/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java index e192b40864fd6..77442cc95c5d8 100644 --- a/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java @@ -78,7 +78,7 @@ import org.opensearch.index.mapper.MapperService; import org.opensearch.index.search.QueryStringQueryParser; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.test.AbstractQueryTestCase; import org.hamcrest.CoreMatchers; import org.hamcrest.Matchers; @@ -860,20 +860,20 @@ public void testToQueryDateWithTimeZone() throws Exception { assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); long lower = 0; // 1970-01-01T00:00:00.999 UTC long upper = 86399999; // 1970-01-01T23:59:59.999 UTC - assertEquals(calculateExpectedDateQuery(lower, upper).toString(), query.toString()); + assertEquals(calculateExpectedDateQuery(lower, upper), query); int msPerHour = 3600000; assertEquals( - calculateExpectedDateQuery(lower - msPerHour, upper - msPerHour).toString(), - qsq.timeZone("+01:00").toQuery(context).toString() + calculateExpectedDateQuery(lower - msPerHour, upper - msPerHour), + qsq.timeZone("+01:00").toQuery(context) ); assertEquals( - calculateExpectedDateQuery(lower + msPerHour, upper + msPerHour).toString(), - qsq.timeZone("-01:00").toQuery(context).toString() + calculateExpectedDateQuery(lower + msPerHour, upper + msPerHour), + qsq.timeZone("-01:00").toQuery(context) ); } private IndexOrDocValuesQuery calculateExpectedDateQuery(long lower, long upper) { - Query query = new ApproximateableQuery( + Query query = new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { lower }).bytes, diff --git a/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java index 0c3e0c4c6bb4c..c414dd27091f5 100644 --- a/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/RangeQueryBuilderTests.java @@ -54,7 +54,7 @@ import org.opensearch.index.mapper.MappedFieldType.Relation; import org.opensearch.index.mapper.MapperService; import org.opensearch.search.approximate.ApproximatePointRangeQuery; -import org.opensearch.search.approximate.ApproximateableQuery; +import org.opensearch.search.approximate.ApproximateScoreQuery; import org.opensearch.test.AbstractQueryTestCase; import org.joda.time.DateTime; import org.joda.time.chrono.ISOChronology; @@ -188,7 +188,11 @@ protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, } else if (expectedFieldName.equals(DATE_FIELD_NAME)) { assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); query = ((IndexOrDocValuesQuery) query).getIndexQuery(); - assertThat(query, instanceOf(ApproximateableQuery.class)); + assertThat(query, instanceOf(ApproximateScoreQuery.class)); + Query originalQuery = ((ApproximateScoreQuery) query).getOriginalQuery(); + assertThat(originalQuery, instanceOf(PointRangeQuery.class)); + Query approximateQuery = ((ApproximateScoreQuery) query).getApproximationQuery(); + assertThat(approximateQuery, instanceOf(ApproximatePointRangeQuery.class)); MapperService mapperService = context.getMapperService(); MappedFieldType mappedFieldType = mapperService.fieldType(expectedFieldName); final Long fromInMillis; @@ -238,7 +242,7 @@ protected void doAssertLuceneQuery(RangeQueryBuilder queryBuilder, Query query, } } assertEquals( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { minLong }).bytes, @@ -260,8 +264,8 @@ protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } } - ).toString(), - query.toString() + ), + query ); } else if (expectedFieldName.equals(INT_FIELD_NAME)) { assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); @@ -329,12 +333,16 @@ public void testDateRangeQueryFormat() throws IOException { Query parsedQuery = parseQuery(query).toQuery(createShardContext()); assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class)); parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); - assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); - + assertThat(parsedQuery, instanceOf(ApproximateScoreQuery.class)); + assertThat(query, instanceOf(ApproximateScoreQuery.class)); + Query originalQuery = ((ApproximateScoreQuery) parsedQuery).getOriginalQuery(); + assertThat(originalQuery, instanceOf(PointRangeQuery.class)); + Query approximateQuery = ((ApproximateScoreQuery) parsedQuery).getApproximationQuery(); + assertThat(approximateQuery, instanceOf(ApproximatePointRangeQuery.class)); long lower = DateTime.parse("2012-01-01T00:00:00.000+00").getMillis(); long upper = DateTime.parse("2030-01-01T00:00:00.000+00").getMillis() - 1; assertEquals( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { lower }).bytes, @@ -356,8 +364,8 @@ protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } } - ).toString(), - parsedQuery.toString() + ), + parsedQuery ); // Test Invalid format @@ -389,12 +397,12 @@ public void testDateRangeBoundaries() throws IOException { Query parsedQuery = parseQuery(query).toQuery(createShardContext()); assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class)); parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); - assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); + assertThat(parsedQuery, instanceOf(ApproximateScoreQuery.class)); long lower = DateTime.parse("2014-11-01T00:00:00.000+00").getMillis(); long upper = DateTime.parse("2014-12-08T23:59:59.999+00").getMillis(); assertEquals( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { lower }).bytes, @@ -433,11 +441,11 @@ protected String toString(int dimension, byte[] value) { parsedQuery = parseQuery(query).toQuery(createShardContext()); assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class)); parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); - assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); + assertThat(parsedQuery, instanceOf(ApproximateScoreQuery.class)); lower = DateTime.parse("2014-11-30T23:59:59.999+00").getMillis() + 1; upper = DateTime.parse("2014-12-08T00:00:00.000+00").getMillis() - 1; assertEquals( - new ApproximateableQuery( + new ApproximateScoreQuery( new PointRangeQuery( DATE_FIELD_NAME, pack(new long[] { lower }).bytes, @@ -482,7 +490,7 @@ public void testDateRangeQueryTimezone() throws IOException { parsedQuery = ((DateRangeIncludingNowQuery) parsedQuery).getQuery(); assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class)); parsedQuery = ((IndexOrDocValuesQuery) parsedQuery).getIndexQuery(); - assertThat(parsedQuery, instanceOf(ApproximateableQuery.class)); + assertThat(parsedQuery, instanceOf(ApproximateScoreQuery.class)); // TODO what else can we assert query = "{\n" 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 a9160e6475405..87bf5568c1c01 100644 --- a/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/approximate/ApproximatePointRangeQueryTests.java @@ -14,19 +14,29 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.LongPoint; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.PointValues; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreMode; +import org.apache.lucene.search.Scorer; +import org.apache.lucene.search.ScorerSupplier; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TotalHits; +import org.apache.lucene.search.Weight; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.index.RandomIndexWriter; +import org.apache.lucene.util.DocIdSetBuilder; import org.opensearch.search.sort.SortOrder; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; +import java.lang.reflect.Method; import static org.apache.lucene.document.LongPoint.pack; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.*; public class ApproximatePointRangeQueryTests extends OpenSearchTestCase { @@ -75,7 +85,7 @@ protected String toString(int dimension, byte[] value) { } } - public void testApproximateRangeWithSize() throws IOException { + public void testApproximateRangeWithDefaultSize() throws IOException { try (Directory directory = newDirectory()) { try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) { int dims = 1; @@ -95,38 +105,107 @@ public void testApproximateRangeWithSize() throws IOException { try (IndexReader reader = iw.getReader()) { try { long lower = 0; - long upper = 100; - Query approximateQuerySmall = new ApproximatePointRangeQuery( - "point", - pack(lower).bytes, - pack(upper).bytes, - dims, - 10 + long upper = 1000; + Query approximateQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }; - Query approximateQueryBig = new ApproximatePointRangeQuery( - "point", - pack(lower).bytes, - pack(upper).bytes, - dims, - 100 + IndexSearcher searcher = new IndexSearcher(reader); + TopDocs topDocs = searcher.search(approximateQuery, 10); + assertEquals(topDocs.totalHits, new TotalHits(1000, TotalHits.Relation.EQUAL_TO)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + } + } + } + + public void testApproximateRangeWithSizeUnderDefault() throws IOException { + try (Directory directory = newDirectory()) { + try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) { + int dims = 1; + + long[] scratch = new long[dims]; + int numPoints = 1000; + for (int i = 0; i < numPoints; i++) { + Document doc = new Document(); + for (int v = 0; v < dims; v++) { + scratch[v] = i; + } + doc.add(new LongPoint("point", scratch)); + iw.addDocument(doc); + if (i % 15 == 0) iw.flush(); + } + iw.flush(); + try (IndexReader reader = iw.getReader()) { + try { + long lower = 0; + long upper = 45; + Query approximateQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 10 ) { protected String toString(int dimension, byte[] value) { return Long.toString(LongPoint.decodeDimension(value, 0)); } }; IndexSearcher searcher = new IndexSearcher(reader); - TopDocs topDocs = searcher.search(approximateQuerySmall, 10); - TopDocs topDocs1 = searcher.search(approximateQueryBig, 10); + TopDocs topDocs = searcher.search(approximateQuery, 10); + assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO)); + } catch (IOException e) { + throw new RuntimeException(e); + } - // the first query with size 10 will produce smaller hits compared to the bigger query - assertNotEquals(topDocs.totalHits, topDocs1.totalHits); - assertEquals(topDocs.totalHits, new TotalHits(11, TotalHits.Relation.EQUAL_TO)); - assertEquals(topDocs1.totalHits, new TotalHits(101, TotalHits.Relation.EQUAL_TO)); + } + } + } + } + public void testApproximateRangeWithSizeOverDefault() throws IOException { + try (Directory directory = newDirectory()) { + try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) { + int dims = 1; + + long[] scratch = new long[dims]; + int numPoints = 15000; + for (int i = 0; i < numPoints; i++) { + Document doc = new Document(); + for (int v = 0; v < dims; v++) { + scratch[v] = i; + } + doc.add(new LongPoint("point", scratch)); + iw.addDocument(doc); + } + iw.flush(); + try (IndexReader reader = iw.getReader()) { + try { + long lower = 0; + long upper = 12000; + Query approximateQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 11_000 + ) { + protected String toString(int dimension, byte[] value) { + return Long.toString(LongPoint.decodeDimension(value, 0)); + } + }; + IndexSearcher searcher = new IndexSearcher(reader); + TopDocs topDocs = searcher.search(approximateQuery, 11000); + assertEquals(topDocs.totalHits, new TotalHits(11001, TotalHits.Relation.GREATER_THAN_OR_EQUAL_TO)); } catch (IOException e) { throw new RuntimeException(e); } @@ -173,7 +252,7 @@ protected String toString(int dimension, byte[] value) { // since we short-circuit from the approx range at the end of size these will not be equal assertNotEquals(topDocs.totalHits, topDocs1.totalHits); - assertEquals(topDocs.totalHits, new TotalHits(11, TotalHits.Relation.EQUAL_TO)); + assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO)); assertEquals(topDocs1.totalHits, new TotalHits(101, TotalHits.Relation.EQUAL_TO)); } catch (IOException e) { @@ -199,7 +278,6 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException { } doc.add(new LongPoint("point", scratch)); iw.addDocument(doc); - // if (i % 10 == 0) iw.flush(); } iw.flush(); try (IndexReader reader = iw.getReader()) { @@ -207,12 +285,12 @@ public void testApproximateRangeShortCircuitAscSort() throws IOException { long lower = 0; long upper = 20; Query approximateQuery = new ApproximatePointRangeQuery( - "point", - pack(lower).bytes, - pack(upper).bytes, - dims, - 10, - SortOrder.ASC + "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)); @@ -229,7 +307,7 @@ protected String toString(int dimension, byte[] value) { // since we short-circuit from the approx range at the end of size these will not be equal assertNotEquals(topDocs.totalHits, topDocs1.totalHits); - assertEquals(topDocs.totalHits, new TotalHits(11, TotalHits.Relation.EQUAL_TO)); + assertEquals(topDocs.totalHits, new TotalHits(10, TotalHits.Relation.EQUAL_TO)); assertEquals(topDocs1.totalHits, new TotalHits(21, TotalHits.Relation.EQUAL_TO)); assertEquals(topDocs.scoreDocs[0].doc, 0); assertEquals(topDocs.scoreDocs[1].doc, 1); @@ -246,4 +324,105 @@ protected String toString(int dimension, byte[] value) { } } } + + public void testIntersectLeft() throws IOException { + try (Directory directory = newDirectory()) { + try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) { + int dims = 1; + + long[] scratch = new long[dims]; + int numPoints = 1000; + for (int i = 0; i < numPoints; i++) { + Document doc = new Document(); + for (int v = 0; v < dims; v++) { + scratch[v] = i; + } + doc.add(new LongPoint("point", scratch)); + iw.addDocument(doc); + } + iw.flush(); + try (IndexReader reader = iw.getReader()) { + try { + long lower = 0; + long upper = 20; + ApproximatePointRangeQuery approximatePointRangeQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 10 + ) { + protected String toString(int dimension, byte[] value) { + return Long.toString(LongPoint.decodeDimension(value, 0)); + } + }; + IndexSearcher searcher = new IndexSearcher(reader); + ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(searcher, ScoreMode.TOP_SCORES, 1.0F); + LeafReaderContext lrc = reader.leaves().get(0); + PointValues values = lrc.reader().getPointValues("point"); + final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, "point"); + PointValues.IntersectVisitor visitor = approximatePointRangeQueryWeight.getIntersectVisitor(result); + long intersectCount = approximatePointRangeQueryWeight.intersectLeft(visitor, values.getPointTree()); + + // Assert + assertEquals(10, intersectCount); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + } + } + + public void testIntersectRight() throws IOException { + try (Directory directory = newDirectory()) { + try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) { + int dims = 1; + + long[] scratch = new long[dims]; + int numPoints = 1000; + for (int i = 0; i < numPoints; i++) { + Document doc = new Document(); + for (int v = 0; v < dims; v++) { + scratch[v] = i; + } + doc.add(new LongPoint("point", scratch)); + iw.addDocument(doc); + } + iw.flush(); + try (IndexReader reader = iw.getReader()) { + try { + long lower = 0; + long upper = 20; + ApproximatePointRangeQuery approximatePointRangeQuery = new ApproximatePointRangeQuery( + "point", + pack(lower).bytes, + pack(upper).bytes, + dims, + 10 + ) { + protected String toString(int dimension, byte[] value) { + return Long.toString(LongPoint.decodeDimension(value, 0)); + } + }; + IndexSearcher searcher = new IndexSearcher(reader); + ApproximateConstantScoreWeight approximatePointRangeQueryWeight = approximatePointRangeQuery.createWeight(searcher, ScoreMode.TOP_SCORES, 1.0F); + LeafReaderContext lrc = reader.leaves().get(0); + PointValues values = lrc.reader().getPointValues("point"); + final DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, "point"); + PointValues.IntersectVisitor visitor = approximatePointRangeQueryWeight.getIntersectVisitor(result); + long intersectCount = approximatePointRangeQueryWeight.intersectRight(visitor, values.getPointTree()); + + // Assert + assertEquals(10, intersectCount); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + } + } + } diff --git a/server/src/test/java/org/opensearch/search/approximate/ApproximateableQueryTests.java b/server/src/test/java/org/opensearch/search/approximate/ApproximateScoreQueryTests.java similarity index 94% rename from server/src/test/java/org/opensearch/search/approximate/ApproximateableQueryTests.java rename to server/src/test/java/org/opensearch/search/approximate/ApproximateScoreQueryTests.java index 15e1c764c206e..d891235b4dec6 100644 --- a/server/src/test/java/org/opensearch/search/approximate/ApproximateableQueryTests.java +++ b/server/src/test/java/org/opensearch/search/approximate/ApproximateScoreQueryTests.java @@ -26,7 +26,7 @@ import static org.apache.lucene.document.LongPoint.pack; -public class ApproximateableQueryTests extends OpenSearchTestCase { +public class ApproximateScoreQueryTests extends OpenSearchTestCase { public void testApproximationScoreSupplier() throws IOException { long l = Long.MIN_VALUE; @@ -53,7 +53,7 @@ protected String toString(int dimension, byte[] value) { } }; - ApproximateableQuery query = new ApproximateableQuery(originalQuery, approximateQuery); + ApproximateScoreQuery query = new ApproximateScoreQuery(originalQuery, approximateQuery); try (Directory directory = newDirectory()) { try (RandomIndexWriter iw = new RandomIndexWriter(random(), directory, new WhitespaceAnalyzer())) {