Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add range validations in query builder and field mapper ([#20497](https://github.com/opensearch-project/OpenSearch/issues/20497))
- [Workload Management] Enhance Scroll API support for autotagging ([#20151](https://github.com/opensearch-project/OpenSearch/pull/20151))
- Add indices to search request slowlog ([#20588](https://github.com/opensearch-project/OpenSearch/pull/20588))
- Implement gRPC Boosting and SimpleQueryString queries ([#20487](https://github.com/opensearch-project/OpenSearch/pull/20487))


### Changed
- Move Randomness from server to libs/common ([#20570](https://github.com/opensearch-project/OpenSearch/pull/20570))
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin = "1.7.10"
antlr4 = "4.13.1"
guava = "33.2.1-jre"
gson = "2.13.2"
opensearchprotobufs = "1.2.0"
opensearchprotobufs = "1.3.0"
Comment thread
karenyrx marked this conversation as resolved.
protobuf = "3.25.8"
jakarta_annotation = "1.3.5"
google_http_client = "1.44.1"
Expand Down
1 change: 0 additions & 1 deletion modules/transport-grpc/licenses/protobufs-1.2.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions modules/transport-grpc/licenses/protobufs-1.3.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a141d00a9de80085436c648502d1b015fd89b9f6

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a141d00a9de80085436c648502d1b015fd89b9f6
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 Boosting queries.
* This class implements the QueryBuilderProtoConverter interface to provide Boosting query support
* for the gRPC transport module.
*/
public class BoostingQueryBuilderProtoConverter implements QueryBuilderProtoConverter {

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

private QueryBuilderProtoConverterRegistry registry;

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

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

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

return BoostingQueryBuilderProtoUtils.fromProto(queryContainer.getBoosting(), registry);
}
}
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.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.BoostingQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.BoostingQuery;
import org.opensearch.protobufs.QueryContainer;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverterRegistry;

/**
* Utility class for converting BoostingQuery Protocol Buffers to OpenSearch query objects.
* This class provides methods to transform Protocol Buffer representations of boosting queries
* into their corresponding OpenSearch BoostingQueryBuilder implementations for search operations.
*/
class BoostingQueryBuilderProtoUtils {

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

/**
* Converts a Protocol Buffer BoostingQuery to an OpenSearch BoostingQueryBuilder.
* Similar to {@link BoostingQueryBuilder#fromXContent(org.opensearch.core.xcontent.XContentParser)}, this method
* parses the Protocol Buffer representation and creates a properly configured
* BoostingQueryBuilder with the appropriate positive, negative, negative_boost, boost, and name settings.
*
* @param boostingQueryProto The Protocol Buffer BoostingQuery to convert
* @param registry The registry to use for converting nested queries
* @return A configured BoostingQueryBuilder instance
* @throws IllegalArgumentException if required fields are missing
*/
static BoostingQueryBuilder fromProto(BoostingQuery boostingQueryProto, QueryBuilderProtoConverterRegistry registry) {
// Variables mirror fromXContent exactly
QueryBuilder positiveQuery = null;
boolean positiveQueryFound = false;
QueryBuilder negativeQuery = null;
boolean negativeQueryFound = false;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
float negativeBoost = -1;
String queryName = null;

// Process positive query
if (boostingQueryProto.hasPositive()) {
QueryContainer positiveContainer = boostingQueryProto.getPositive();
positiveQuery = registry.fromProto(positiveContainer);
positiveQueryFound = true;
}

// Process negative query
if (boostingQueryProto.hasNegative()) {
QueryContainer negativeContainer = boostingQueryProto.getNegative();
negativeQuery = registry.fromProto(negativeContainer);
negativeQueryFound = true;
}

// Process negative_boost
negativeBoost = boostingQueryProto.getNegativeBoost();

// Process boost (optional)
if (boostingQueryProto.hasBoost()) {
boost = boostingQueryProto.getBoost();
}

// Process queryName (optional)
if (boostingQueryProto.hasXName()) {
queryName = boostingQueryProto.getXName();
}

// Validation matches fromXContent exactly
if (!positiveQueryFound) {
throw new IllegalArgumentException(BoostingQueryBuilder.POSITIVE_QUERY_REQUIRED);
}
if (!negativeQueryFound) {
throw new IllegalArgumentException(BoostingQueryBuilder.NEGATIVE_QUERY_REQUIRED);
}
if (negativeBoost < 0) {
throw new IllegalArgumentException(BoostingQueryBuilder.NEGATIVE_BOOST_POSITIVE_VALUE_REQUIRED);
}

// Build the query in the same order as fromXContent
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder(positiveQuery, negativeQuery);
boostingQuery.negativeBoost(negativeBoost);
boostingQuery.boost(boost);
boostingQuery.queryName(queryName);

return boostingQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected void registerBuiltInConverters() {
delegate.registerConverter(new MatchBoolPrefixQueryBuilderProtoConverter());
delegate.registerConverter(new MatchPhrasePrefixQueryBuilderProtoConverter());
delegate.registerConverter(new FunctionScoreQueryBuilderProtoConverter());
delegate.registerConverter(new BoostingQueryBuilderProtoConverter());
delegate.registerConverter(new SimpleQueryStringBuilderProtoConverter());

// Set the registry on all converters so they can access each other
delegate.setRegistryOnAllConverters(this);
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 SimpleQueryString queries.
* This class implements the QueryBuilderProtoConverter interface to provide SimpleQueryString query support
* for the gRPC transport module.
*/
public class SimpleQueryStringBuilderProtoConverter implements QueryBuilderProtoConverter {

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

private QueryBuilderProtoConverterRegistry registry;

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

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

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

return SimpleQueryStringBuilderProtoUtils.fromProto(queryContainer.getSimpleQueryString());
}
}
Loading
Loading