Skip to content
Draft
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
3 changes: 2 additions & 1 deletion 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 tracing support for StreamingRestChannel ([#20361](https://github.com/opensearch-project/OpenSearch/pull/20361))
- Introduce new libs/netty4 module to share common implementation between netty-based plugins and modules (transport-netty4, transport-reactor-netty4) ([#20447](https://github.com/opensearch-project/OpenSearch/pull/20447))
- Add validation to make crypto store settings immutable ([#20123](https://github.com/opensearch-project/OpenSearch/pull/20123))
- Implement gRPC Boosting and SimpleQueryString queries ([#20487](https://github.com/opensearch-project/OpenSearch/pull/20487))

### Changed
- Handle custom metadata files in subdirectory-store ([#20157](https://github.com/opensearch-project/OpenSearch/pull/20157))
Expand Down Expand Up @@ -89,4 +90,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Remove identity-shiro from plugins folder ([#20305](https://github.com/opensearch-project/OpenSearch/pull/20305))

[Unreleased 3.x]: https://github.com/opensearch-project/OpenSearch/compare/3.4...main
[Unreleased 3.x]: https://github.com/opensearch-project/OpenSearch/compare/3.4...main
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.1.0"
opensearchprotobufs = "1.3.0-SNAPSHOT" # temporary for PR review. will use 1.3.0 before
protobuf = "3.25.8"
jakarta_annotation = "1.3.5"
google_http_client = "1.44.1"
Expand Down
5 changes: 5 additions & 0 deletions modules/transport-grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ dependencies {
tasks.named("dependencyLicenses").configure {
mapping from: /grpc-.*/, to: 'grpc'
}
repositories {
maven {
url = 'https://ci.opensearch.org/ci/dbc/snapshots/maven/'
}
}

thirdPartyAudit {
ignoreMissingClasses(
Expand Down
5 changes: 5 additions & 0 deletions modules/transport-grpc/spi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ dependencies {
testImplementation "io.grpc:grpc-stub:${versions.grpc}"
}

repositories {
maven {
url = 'https://ci.opensearch.org/ci/dbc/snapshots/maven/'
}
}
thirdPartyAudit {
ignoreMissingClasses(
'com.google.common.collect.Maps',
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 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,85 @@
/*
* 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) {
// Extract fields in the order they appear in fromXContent
QueryBuilder positiveQuery = null;
QueryBuilder negativeQuery = null;
float negativeBoost = -1;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
String queryName = null;

// Process positive query (required in proto)
QueryContainer positiveContainer = boostingQueryProto.getPositive();
positiveQuery = registry.fromProto(positiveContainer);
if (positiveQuery == null) {
throw new IllegalArgumentException(BoostingQueryBuilder.POSITIVE_QUERY_REQUIRED);
}

// Process negative query (required in proto)
QueryContainer negativeContainer = boostingQueryProto.getNegative();
negativeQuery = registry.fromProto(negativeContainer);
if (negativeQuery == null) {
throw new IllegalArgumentException(BoostingQueryBuilder.NEGATIVE_QUERY_REQUIRED);
}

// Process negative_boost (required in proto, but validate it's positive)
negativeBoost = boostingQueryProto.getNegativeBoost();
if (negativeBoost < 0) {
throw new IllegalArgumentException(BoostingQueryBuilder.NEGATIVE_BOOST_POSITIVE_VALUE_REQUIRED);
}

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

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

// 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