Skip to content

Commit 23a29a4

Browse files
Desc debug
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent cb30055 commit 23a29a4

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* An approximate-able version of {@link PointRangeQuery}. It creates an instance of {@link PointRangeQuery} but short-circuits the intersect logic
3939
* after {@code size} is hit
4040
*/
41-
public class ApproximatePointRangeQuery extends ApproximateQuery {
41+
public class ApproximatePointRangeQuery extends ApproximateQuery {
4242
public static final Function<byte[], String> LONG_FORMAT = bytes -> Long.toString(LongPoint.decodeDimension(bytes, 0));
4343
private int size;
4444

@@ -449,7 +449,7 @@ public boolean canApproximate(SearchContext context) {
449449
if (context.from() + context.size() == 0) {
450450
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);
451451
} else {
452-
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo() + 1));
452+
this.setSize(Math.max(context.from() + context.size(), context.trackTotalHitsUpTo()));
453453
}
454454
if (context.request() != null && context.request().source() != null) {
455455
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());

server/src/main/java/org/opensearch/search/approximate/ApproximateScoreQuery.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.search.IndexSearcher;
1313
import org.apache.lucene.search.Query;
1414
import org.apache.lucene.search.QueryVisitor;
15+
import org.apache.lucene.search.ScoreMode;
1516
import org.apache.lucene.search.Weight;
1617
import org.opensearch.search.internal.SearchContext;
1718

@@ -47,7 +48,11 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
4748
// Default to the original query. This suggests that we were not called from ContextIndexSearcher.
4849
return originalQuery.rewrite(indexSearcher);
4950
}
50-
return resolvedQuery.rewrite(indexSearcher);
51+
Query rewritten = resolvedQuery.rewrite(indexSearcher);
52+
if (rewritten != resolvedQuery) {
53+
resolvedQuery = rewritten;
54+
}
55+
return this;
5156
}
5257

5358
public void setContext(SearchContext context) {
@@ -72,16 +77,23 @@ public void visit(QueryVisitor queryVisitor) {
7277

7378
@Override
7479
public boolean equals(Object o) {
75-
if (!sameClassAs(o)) {
76-
return false;
77-
}
78-
return true;
80+
if (!sameClassAs(o)) return false;
81+
ApproximateScoreQuery other = (ApproximateScoreQuery) o;
82+
return originalQuery.equals(other.originalQuery)
83+
&& resolvedQuery.equals(other.resolvedQuery)
84+
&& approximationQuery.equals(other.approximationQuery);
85+
}
86+
87+
@Override
88+
public Weight createWeight(IndexSearcher s, ScoreMode sm, float boost) throws IOException {
89+
return resolvedQuery.createWeight(s, sm, boost);
7990
}
8091

8192
@Override
8293
public int hashCode() {
8394
int h = classHash();
8495
h = 31 * h + originalQuery.hashCode();
96+
h = 31 * h + resolvedQuery.hashCode();
8597
h = 31 * h + approximationQuery.hashCode();
8698
return h;
8799
}

server/src/main/java/org/opensearch/search/query/TopDocsCollectorContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.opensearch.common.util.CachedSupplier;
7575
import org.opensearch.index.search.OpenSearchToParentBlockJoinQuery;
7676
import org.opensearch.search.DocValueFormat;
77+
import org.opensearch.search.approximate.ApproximateScoreQuery;
7778
import org.opensearch.search.collapse.CollapseContext;
7879
import org.opensearch.search.internal.ScrollContext;
7980
import org.opensearch.search.internal.SearchContext;
@@ -724,6 +725,8 @@ static int shortcutTotalHitCount(IndexReader reader, Query query) throws IOExcep
724725
query = ((ConstantScoreQuery) query).getQuery();
725726
} else if (query instanceof BoostQuery) {
726727
query = ((BoostQuery) query).getQuery();
728+
} else if (query instanceof ApproximateScoreQuery) {
729+
query = ((ApproximateScoreQuery) query).getOriginalQuery();
727730
} else {
728731
break;
729732
}

0 commit comments

Comments
 (0)