Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Feb 8, 2024
1 parent fe20a6b commit 2baa3fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.aggregations.bucket;

public class FilterRewriteIT {
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ public static boolean tryFastFilterAggregation(
return false;
}
Weight[] filters = fastFilterContext.filters;
boolean filtersBuiltAtSegmentLevel = false;
if (filters == null) {
logger.debug(
"Shard {} segment {} functionally match all documents. Build the fast filter",
Expand All @@ -451,6 +452,8 @@ public static boolean tryFastFilterAggregation(
filters = fastFilterContext.filters;
if (filters == null) {
return false;
} else {
filtersBuiltAtSegmentLevel = true;
}
}

Expand All @@ -477,25 +480,25 @@ public static boolean tryFastFilterAggregation(
NumericUtils.sortableBytesToLong(((PointRangeQuery) filters[i].getQuery()).getLowerPoint(), 0)
);
}
// TODO remove
logger.info("Shard {} segment {} increase bucket key {} by count {}", fastFilterContext.context.indexShard().shardId(), ctx.ord, bucketKey, counts[i]);
incrementDocCount.accept(bucketKey, counts[i]);
s++;
if (s > size) {
logger.debug("Fast filter optimization applied to composite aggregation with size {}", size);
return true;
break;
}
}
}

logger.debug("Fast filter optimization applied");
// each segment computes its own filters, so reset
if (filtersBuiltAtSegmentLevel) {
fastFilterContext.filters = null;
}

logger.debug("Fast filter optimization applied to shard {} segment {}", fastFilterContext.context.indexShard().shardId(), ctx.ord);
return true;
}

private static boolean segmentMatchAll(SearchContext ctx, LeafReaderContext leafCtx) throws IOException {
Weight weight = ctx.searcher().createWeight(ctx.query(), ScoreMode.COMPLETE_NO_SCORES, 1f);
assert weight != null;
int count = weight.count(leafCtx);
return count > 0 && count == leafCtx.reader().numDocs();
return weight != null && weight.count(leafCtx) == leafCtx.reader().numDocs();
}
}

0 comments on commit 2baa3fc

Please sign in to comment.