Skip to content

Commit

Permalink
Fix date histogram test
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Aug 22, 2024
1 parent 15fd737 commit ff8a2fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.opensearch.common.lucene.search.function.FunctionScoreQuery;
import org.opensearch.index.mapper.DateFieldMapper;
import org.opensearch.index.query.DateRangeIncludingNowQuery;
import org.opensearch.search.approximate.ApproximatePointRangeQuery;
import org.opensearch.search.approximate.ApproximateScoreQuery;
import org.opensearch.search.internal.SearchContext;

import java.io.IOException;
Expand Down Expand Up @@ -123,6 +125,18 @@ public static long[] getDateHistoAggBounds(final SearchContext context, final St
final long[] indexBounds = getShardBounds(leaves, fieldName);
if (indexBounds == null) return null;
return getBoundsWithRangeQuery(prq, fieldName, indexBounds);
} else if (cq instanceof ApproximateScoreQuery) {
final ApproximateScoreQuery asq = (ApproximateScoreQuery) cq;
final long[] indexBounds = getShardBounds(leaves, fieldName);
if (indexBounds == null) return null;
if ((asq.getApproximationQuery() instanceof ApproximatePointRangeQuery)) {
ApproximatePointRangeQuery aprq = (ApproximatePointRangeQuery) asq.getApproximationQuery();
if (aprq.canApproximate(context)) {
return getBoundsWithRangeQuery(aprq.pointRangeQuery, fieldName, indexBounds);
}
final PointRangeQuery prq = (PointRangeQuery) asq.getOriginalQuery();
return getBoundsWithRangeQuery(prq, fieldName, indexBounds);
}
} else if (cq instanceof MatchAllDocsQuery) {
return getShardBounds(leaves, fieldName);
} else if (cq instanceof FieldExistsQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class ApproximatePointRangeQuery extends ApproximateableQuery {

private long[] docCount = { 0 };

private final PointRangeQuery pointRangeQuery;
public final PointRangeQuery pointRangeQuery;

protected ApproximatePointRangeQuery(String field, byte[] lowerPoint, byte[] upperPoint, int numDims) {
this(field, lowerPoint, upperPoint, numDims, 10_000, null);
Expand Down Expand Up @@ -427,6 +427,9 @@ public boolean canApproximate(SearchContext context) {
if (context == null) {
return false;
}
if (context.aggregations() != null) {
return false;
}
if (!(context.query() instanceof IndexOrDocValuesQuery
&& ((IndexOrDocValuesQuery) context.query()).getIndexQuery() instanceof ApproximateScoreQuery
&& ((ApproximateScoreQuery) ((IndexOrDocValuesQuery) context.query()).getIndexQuery())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public Scorer scorer(LeafReaderContext leafReaderContext) throws IOException {
public boolean isCacheable(LeafReaderContext leafReaderContext) {
return originalQueryWeight.isCacheable(leafReaderContext);
}

@Override
public int count(LeafReaderContext leafReaderContext) throws IOException {
if (approximationQuery.canApproximate(context)) {
return approximationQueryWeight.count(leafReaderContext);
}
return originalQueryWeight.count(leafReaderContext);
}
};
}

Expand Down

0 comments on commit ff8a2fd

Please sign in to comment.