Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add cluster defaults for merge autoThrottle, maxMergeThreads, and maxMergeCount; Add segment size filter to the merged segment warmer ([#19629](https://github.com/opensearch-project/OpenSearch/pull/19629))
- Add build-tooling to run in FIPS environment ([#18921](https://github.com/opensearch-project/OpenSearch/pull/18921))
- Add SMILE/CBOR/YAML document format support to Bulk GRPC endpoint ([#19744](https://github.com/opensearch-project/OpenSearch/pull/19744))
- Implement GRPC ConstantScoreQuery, FuzzyQuery, MatchBoolPrefixQuery, MatchPhrasePrefix, PrefixQuery, MatchQuery ([#19854](https://github.com/opensearch-project/OpenSearch/pull/19854))

### Changed
- Faster `terms` query creation for `keyword` field with index and docValues enabled ([#19350](https://github.com/opensearch-project/OpenSearch/pull/19350))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private OperatorProtoUtils() {
* @param op
* @return
*/
protected static Operator fromEnum(org.opensearch.protobufs.Operator op) {
public static Operator fromEnum(org.opensearch.protobufs.Operator op) {
switch (op) {
case OPERATOR_AND:
return Operator.AND;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.transport.grpc.proto.request.search.query;

import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.QueryContainer;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverter;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverterRegistry;

/**
* Converter for ConstantScore queries.
* This class implements the QueryBuilderProtoConverter interface to provide ConstantScore query support
* for the gRPC transport module.
*/
public class ConstantScoreQueryBuilderProtoConverter implements QueryBuilderProtoConverter {

/**
* Default constructor for ConstantScoreQueryBuilderProtoConverter.
*/
public ConstantScoreQueryBuilderProtoConverter() {}

private QueryBuilderProtoConverterRegistry registry;

@Override
public void setRegistry(QueryBuilderProtoConverterRegistry registry) {
this.registry = registry;
}

@Override
public QueryContainer.QueryContainerCase getHandledQueryCase() {
return QueryContainer.QueryContainerCase.CONSTANT_SCORE;
}

@Override
public QueryBuilder fromProto(QueryContainer queryContainer) {
if (queryContainer == null || queryContainer.getQueryContainerCase() != QueryContainer.QueryContainerCase.CONSTANT_SCORE) {
throw new IllegalArgumentException("QueryContainer does not contain a ConstantScore query");
}

return ConstantScoreQueryBuilderProtoUtils.fromProto(queryContainer.getConstantScore(), registry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.transport.grpc.proto.request.search.query;

import org.opensearch.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.ConstantScoreQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.ConstantScoreQuery;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverterRegistry;

/**
* Utility class for converting ConstantScoreQuery Protocol Buffers to OpenSearch objects.
* This class provides methods to transform Protocol Buffer representations of constant score queries
* into their corresponding OpenSearch ConstantScoreQueryBuilder implementations for search operations.
*/
class ConstantScoreQueryBuilderProtoUtils {

private ConstantScoreQueryBuilderProtoUtils() {
// Utility class, no instances
}

/**
* Converts a Protocol Buffer ConstantScoreQuery to an OpenSearch ConstantScoreQueryBuilder.
* Similar to {@link ConstantScoreQueryBuilder#fromXContent(org.opensearch.core.xcontent.XContentParser)}, this method
* parses the Protocol Buffer representation and creates a properly configured
* ConstantScoreQueryBuilder with the appropriate filter query, boost, and query name.
*
* @param constantScoreQueryProto The Protocol Buffer ConstantScoreQuery object
* @param registry The registry to use for converting the nested filter query
* @return A configured ConstantScoreQueryBuilder instance
*/
static ConstantScoreQueryBuilder fromProto(ConstantScoreQuery constantScoreQueryProto, QueryBuilderProtoConverterRegistry registry) {
if (registry == null) {
throw new IllegalArgumentException("QueryBuilderProtoConverterRegistry cannot be null");
}
String queryName = null;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;

if (!constantScoreQueryProto.hasFilter()) {
throw new IllegalArgumentException("ConstantScore query must have a filter query");
}

QueryBuilder query = registry.fromProto(constantScoreQueryProto.getFilter());
if (query == null) {
throw new IllegalArgumentException("Filter query cannot be null for constant_score query");
}

if (constantScoreQueryProto.hasBoost()) {
boost = constantScoreQueryProto.getBoost();
}

if (constantScoreQueryProto.hasXName()) {
queryName = constantScoreQueryProto.getXName();
}

ConstantScoreQueryBuilder constantScoreBuilder = new ConstantScoreQueryBuilder(query);
constantScoreBuilder.boost(boost);
constantScoreBuilder.queryName(queryName);
return constantScoreBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.transport.grpc.proto.request.search.query;

import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.QueryContainer;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverter;

/**
* Converter for Fuzzy queries.
* This class implements the QueryBuilderProtoConverter interface to provide Fuzzy query support
* for the gRPC transport module.
*/
public class FuzzyQueryBuilderProtoConverter implements QueryBuilderProtoConverter {

/**
* Constructs a new FuzzyQueryBuilderProtoConverter.
*/
public FuzzyQueryBuilderProtoConverter() {
// Default constructor
}

@Override
public QueryContainer.QueryContainerCase getHandledQueryCase() {
return QueryContainer.QueryContainerCase.FUZZY;
}

@Override
public QueryBuilder fromProto(QueryContainer queryContainer) {
if (queryContainer == null || !queryContainer.hasFuzzy()) {
throw new IllegalArgumentException("QueryContainer does not contain a Fuzzy query");
}

return FuzzyQueryBuilderProtoUtils.fromProto(queryContainer.getFuzzy());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.transport.grpc.proto.request.search.query;

import org.opensearch.common.unit.Fuzziness;
import org.opensearch.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.FuzzyQueryBuilder;
import org.opensearch.protobufs.FuzzyQuery;
import org.opensearch.protobufs.MultiTermQueryRewrite;
import org.opensearch.transport.grpc.proto.response.common.FieldValueProtoUtils;
import org.opensearch.transport.grpc.util.ProtobufEnumUtils;

/**
* Utility class for converting FuzzyQuery Protocol Buffers to OpenSearch objects.
* This class provides methods to transform Protocol Buffer representations of fuzzy queries
* into their corresponding OpenSearch FuzzyQueryBuilder implementations for search operations.
*/
class FuzzyQueryBuilderProtoUtils {

private FuzzyQueryBuilderProtoUtils() {
// Utility class, no instances
}

/**
* Converts a Protocol Buffer FuzzyQuery to an OpenSearch FuzzyQueryBuilder.
* Similar to {@link FuzzyQueryBuilder#fromXContent(org.opensearch.core.xcontent.XContentParser)}, this method
* parses the Protocol Buffer representation and creates a properly configured
* FuzzyQueryBuilder with the appropriate field name, value, fuzziness, prefix length,
* max expansions, transpositions, rewrite method, boost, and query name.
*
* @param fuzzyQueryProto The Protocol Buffer FuzzyQuery object
* @return A configured FuzzyQueryBuilder instance
* @throws IllegalArgumentException if the field name or value is null or empty
*/
static FuzzyQueryBuilder fromProto(FuzzyQuery fuzzyQueryProto) {
String fieldName = fuzzyQueryProto.getField();
Object value = FieldValueProtoUtils.fromProto(fuzzyQueryProto.getValue(), false);
Fuzziness fuzziness = FuzzyQueryBuilder.DEFAULT_FUZZINESS;
int prefixLength = FuzzyQueryBuilder.DEFAULT_PREFIX_LENGTH;
int maxExpansions = FuzzyQueryBuilder.DEFAULT_MAX_EXPANSIONS;
boolean transpositions = FuzzyQueryBuilder.DEFAULT_TRANSPOSITIONS;
String rewrite = null;
String queryName = null;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;

if (fuzzyQueryProto.hasBoost()) {
boost = fuzzyQueryProto.getBoost();
}

if (fuzzyQueryProto.hasFuzziness()) {
org.opensearch.protobufs.Fuzziness fuzzinessProto = fuzzyQueryProto.getFuzziness();
if (fuzzinessProto.hasString()) {
fuzziness = Fuzziness.build(fuzzinessProto.getString());
} else if (fuzzinessProto.hasInt32()) {
fuzziness = Fuzziness.fromEdits(fuzzinessProto.getInt32());
}
}

if (fuzzyQueryProto.hasPrefixLength()) {
prefixLength = fuzzyQueryProto.getPrefixLength();
}

if (fuzzyQueryProto.hasMaxExpansions()) {
maxExpansions = fuzzyQueryProto.getMaxExpansions();
}

if (fuzzyQueryProto.hasTranspositions()) {
transpositions = fuzzyQueryProto.getTranspositions();
}

if (fuzzyQueryProto.hasRewrite()) {
MultiTermQueryRewrite rewriteEnum = fuzzyQueryProto.getRewrite();
if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) {
rewrite = ProtobufEnumUtils.convertToString(rewriteEnum);
}
}

if (fuzzyQueryProto.hasXName()) {
queryName = fuzzyQueryProto.getXName();
}

return new FuzzyQueryBuilder(fieldName, value).fuzziness(fuzziness)
.prefixLength(prefixLength)
.maxExpansions(maxExpansions)
.transpositions(transpositions)
.rewrite(rewrite)
.boost(boost)
.queryName(queryName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.transport.grpc.proto.request.search.query;

import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.QueryContainer;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverter;

/**
* Converter for MatchBoolPrefix queries.
* This class implements the QueryBuilderProtoConverter interface to provide MatchBoolPrefix query support
* for the gRPC transport module.
*/
public class MatchBoolPrefixQueryBuilderProtoConverter implements QueryBuilderProtoConverter {

/**
* Constructs a new MatchBoolPrefixQueryBuilderProtoConverter.
*/
public MatchBoolPrefixQueryBuilderProtoConverter() {
// Default constructor
}

@Override
public QueryContainer.QueryContainerCase getHandledQueryCase() {
return QueryContainer.QueryContainerCase.MATCH_BOOL_PREFIX;
}

@Override
public QueryBuilder fromProto(QueryContainer queryContainer) {
if (queryContainer == null || !queryContainer.hasMatchBoolPrefix()) {
throw new IllegalArgumentException("QueryContainer does not contain a MatchBoolPrefix query");
}

return MatchBoolPrefixQueryBuilderProtoUtils.fromProto(queryContainer.getMatchBoolPrefix());
}
}
Loading
Loading