Skip to content

Commit 7a878b5

Browse files
Add query shape hash method (#64) (#78)
(cherry picked from commit 1f4c4c6) Signed-off-by: David Zane <davizane@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 8e72a57 commit 7a878b5

File tree

3 files changed

+467
-83
lines changed

3 files changed

+467
-83
lines changed

src/main/java/org/opensearch/plugin/insights/core/service/categorizer/QueryShapeGenerator.java

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.function.Function;
17+
import org.apache.lucene.util.BytesRef;
18+
import org.opensearch.common.hash.MurmurHash3;
1719
import org.opensearch.core.common.io.stream.NamedWriteable;
1820
import org.opensearch.index.query.AbstractGeometryQueryBuilder;
1921
import org.opensearch.index.query.CommonTermsQueryBuilder;
@@ -76,6 +78,18 @@ public class QueryShapeGenerator {
7678
static final Map<Class<?>, List<Function<Object, String>>> AGG_FIELD_DATA_MAP = FieldDataMapHelper.getAggFieldDataMap();
7779
static final Map<Class<?>, List<Function<Object, String>>> SORT_FIELD_DATA_MAP = FieldDataMapHelper.getSortFieldDataMap();
7880

81+
/**
82+
* Method to get query shape hash code given a source
83+
* @param source search request source
84+
* @param showFields whether to include field data in query shape
85+
* @return Hash code of query shape as a MurmurHash3.Hash128 object (128-bit)
86+
*/
87+
public static MurmurHash3.Hash128 getShapeHashCode(SearchSourceBuilder source, Boolean showFields) {
88+
final String shape = buildShape(source, showFields);
89+
final BytesRef shapeBytes = new BytesRef(shape);
90+
return MurmurHash3.hash128(shapeBytes.bytes, 0, shapeBytes.length, 0, new MurmurHash3.Hash128());
91+
}
92+
7993
/**
8094
* Method to build search query shape given a source
8195
* @param source search request source

0 commit comments

Comments
 (0)