-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[GRPC] Implement Boosting and SimpleQueryString queries #20487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karenyrx
wants to merge
2
commits into
opensearch-project:main
Choose a base branch
from
karenyrx:boostingsimplequery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a141d00a9de80085436c648502d1b015fd89b9f6 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a141d00a9de80085436c648502d1b015fd89b9f6 |
47 changes: 47 additions & 0 deletions
47
...nsearch/transport/grpc/proto/request/search/query/BoostingQueryBuilderProtoConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
.../opensearch/transport/grpc/proto/request/search/query/BoostingQueryBuilderProtoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...rch/transport/grpc/proto/request/search/query/SimpleQueryStringBuilderProtoConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.