-
Notifications
You must be signed in to change notification settings - Fork 98
feat: add OpenSearch distance operations and selectors #1335
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
mmiguerodriguez
wants to merge
11
commits into
master
Choose a base branch
from
feature/os-distance-operations
base: master
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
11 commits
Select commit
Hold shift + click to select a range
14c53c2
feat: add OpenSearch distance operations and selectors
mmiguerodriguez df6ffe6
Merge branch 'master' into feature/os-distance-operations
mmiguerodriguez a356951
feature: added new integration test
mmiguerodriguez 9da8da8
Merge remote-tracking branch 'origin/master' into feature/os-distance…
mmiguerodriguez 54f1eac
remove invalid assertions
mmiguerodriguez 23b7b20
fix tests
mmiguerodriguez b529331
more test fixes...
mmiguerodriguez b461a0f
fix test by using default constructor
mmiguerodriguez bec8eb7
Merge branch 'master' into feature/os-distance-operations
mmiguerodriguez 41fae1f
tests: add PR recommendations
mmiguerodriguez ae37f6a
Merge remote-tracking branch 'origin/master' into feature/os-distance…
mmiguerodriguez 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
670 changes: 659 additions & 11 deletions
670
.../java/org/evomaster/client/java/controller/opensearch/OpenSearchHeuristicsCalculator.java
Large diffs are not rendered by default.
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
59 changes: 59 additions & 0 deletions
59
...c/main/java/org/evomaster/client/java/controller/opensearch/operations/BoolOperation.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,59 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Represents Bool operation. | ||
| * A Boolean query can combine several query clauses into one advanced query. The clauses are combined | ||
| * with Boolean logic to find matching documents returned in the results. | ||
| * <p> | ||
| * <a href="https://docs.opensearch.org/latest/query-dsl/compound/bool/">OpenSearch Bool Operation</a> | ||
| */ | ||
| public class BoolOperation extends QueryOperation { | ||
| private final List<QueryOperation> must; | ||
| private final List<QueryOperation> mustNot; | ||
| private final List<QueryOperation> should; | ||
| private final List<QueryOperation> filter; | ||
| private final Integer minimumShouldMatch; | ||
| private final Float boost; | ||
|
|
||
| public BoolOperation(List<QueryOperation> must, List<QueryOperation> mustNot, | ||
| List<QueryOperation> should, List<QueryOperation> filter) { | ||
| this(must, mustNot, should, filter, null, null); | ||
| } | ||
|
|
||
| public BoolOperation(List<QueryOperation> must, List<QueryOperation> mustNot, | ||
| List<QueryOperation> should, List<QueryOperation> filter, | ||
| Integer minimumShouldMatch, Float boost) { | ||
| this.must = must; | ||
| this.mustNot = mustNot; | ||
| this.should = should; | ||
| this.filter = filter; | ||
| this.minimumShouldMatch = minimumShouldMatch; | ||
| this.boost = boost; | ||
| } | ||
|
|
||
| public List<QueryOperation> getMust() { | ||
| return must; | ||
| } | ||
|
|
||
| public List<QueryOperation> getMustNot() { | ||
| return mustNot; | ||
| } | ||
|
|
||
| public List<QueryOperation> getShould() { | ||
| return should; | ||
| } | ||
|
|
||
| public List<QueryOperation> getFilter() { | ||
| return filter; | ||
| } | ||
|
|
||
| public Integer getMinimumShouldMatch() { | ||
| return minimumShouldMatch; | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return boost; | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...ava/org/evomaster/client/java/controller/opensearch/operations/CommonQueryParameters.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,77 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| /** | ||
| * Common parameters shared across multiple OpenSearch query operations. | ||
| */ | ||
| public class CommonQueryParameters { | ||
| private final Float boost; | ||
| private final String name; | ||
| private final String rewrite; | ||
| private final Boolean caseInsensitive; | ||
|
|
||
| public CommonQueryParameters(Float boost, String name, String rewrite, Boolean caseInsensitive) { | ||
| this.boost = boost; | ||
| this.name = name; | ||
| this.rewrite = rewrite; | ||
| this.caseInsensitive = caseInsensitive; | ||
| } | ||
|
|
||
| public static CommonQueryParameters empty() { | ||
| return new CommonQueryParameters(null, null, null, null); | ||
| } | ||
|
|
||
| public static CommonQueryParameters withBoost(Float boost) { | ||
| return new CommonQueryParameters(boost, null, null, null); | ||
| } | ||
|
|
||
| public static CommonQueryParameters withCaseInsensitive(Boolean caseInsensitive) { | ||
| return new CommonQueryParameters(null, null, null, caseInsensitive); | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return boost; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getRewrite() { | ||
| return rewrite; | ||
| } | ||
|
|
||
| public Boolean getCaseInsensitive() { | ||
| return caseInsensitive; | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private Float boost; | ||
| private String name; | ||
| private String rewrite; | ||
| private Boolean caseInsensitive; | ||
|
|
||
| public Builder boost(Float boost) { | ||
| this.boost = boost; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder name(String name) { | ||
| this.name = name; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder rewrite(String rewrite) { | ||
| this.rewrite = rewrite; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder caseInsensitive(Boolean caseInsensitive) { | ||
| this.caseInsensitive = caseInsensitive; | ||
| return this; | ||
| } | ||
|
|
||
| public CommonQueryParameters build() { | ||
| return new CommonQueryParameters(boost, name, rewrite, caseInsensitive); | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...main/java/org/evomaster/client/java/controller/opensearch/operations/ExistsOperation.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,29 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| /** | ||
| * Represents Exists operation. | ||
| * Searches for documents that contain a specific field. | ||
| * <p> | ||
| * <a href="https://docs.opensearch.org/latest/query-dsl/term/exists/">OpenSearch Exists Operation</a> | ||
| */ | ||
| public class ExistsOperation extends QueryOperation { | ||
| private final String field; | ||
| private final Float boost; | ||
|
|
||
| public ExistsOperation(String field) { | ||
| this(field, null); | ||
| } | ||
|
|
||
| public ExistsOperation(String field, Float boost) { | ||
| this.field = field; | ||
| this.boost = boost; | ||
| } | ||
|
|
||
| public String getField() { | ||
| return field; | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return boost; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
.../java/org/evomaster/client/java/controller/opensearch/operations/FieldValueOperation.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,45 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| /** | ||
| * Abstract base class for OpenSearch operations that operate on a specific field with a value. | ||
| * This includes operations like Term, Prefix, Wildcard, Fuzzy, and Regexp. | ||
| */ | ||
| public abstract class FieldValueOperation extends QueryOperation { | ||
| private final String fieldName; | ||
| private final String value; | ||
| private final CommonQueryParameters commonParams; | ||
|
|
||
| protected FieldValueOperation(String fieldName, String value, CommonQueryParameters commonParams) { | ||
| this.fieldName = fieldName; | ||
| this.value = value; | ||
| this.commonParams = commonParams != null ? commonParams : CommonQueryParameters.empty(); | ||
| } | ||
|
|
||
| public String getFieldName() { | ||
| return fieldName; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return commonParams.getBoost(); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return commonParams.getName(); | ||
| } | ||
|
|
||
| public String getRewrite() { | ||
| return commonParams.getRewrite(); | ||
| } | ||
|
|
||
| public Boolean getCaseInsensitive() { | ||
| return commonParams.getCaseInsensitive(); | ||
| } | ||
|
|
||
| protected CommonQueryParameters getCommonParams() { | ||
| return commonParams; | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
.../main/java/org/evomaster/client/java/controller/opensearch/operations/FuzzyOperation.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,68 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| /** | ||
| * Represents Fuzzy operation. | ||
| * Searches for documents containing terms that are similar to the search term within the maximum allowed | ||
| * Damerau-Levenshtein distance. The Damerau-Levenshtein distance measures the number of one-character | ||
| * changes needed to change one term to another term. | ||
| * <p> | ||
| * <a href="https://docs.opensearch.org/latest/query-dsl/term/fuzzy/">OpenSearch Fuzzy Operation</a> | ||
| */ | ||
| public class FuzzyOperation extends QueryOperation { | ||
| private final String fieldName; | ||
| private final String value; | ||
| private final Float boost; | ||
| private final Integer fuzziness; | ||
| private final Integer maxExpansions; | ||
| private final Integer prefixLength; | ||
| private final Boolean transpositions; | ||
| private final String rewrite; | ||
|
|
||
| public FuzzyOperation(String fieldName, String value) { | ||
| this(fieldName, value, null, null, null, null, null, null); | ||
| } | ||
|
|
||
| public FuzzyOperation(String fieldName, String value, Float boost, Integer fuzziness, | ||
| Integer maxExpansions, Integer prefixLength, Boolean transpositions, String rewrite) { | ||
| this.fieldName = fieldName; | ||
| this.value = value; | ||
| this.boost = boost; | ||
| this.fuzziness = fuzziness; | ||
| this.maxExpansions = maxExpansions; | ||
| this.prefixLength = prefixLength; | ||
| this.transpositions = transpositions; | ||
| this.rewrite = rewrite; | ||
| } | ||
|
|
||
| public String getFieldName() { | ||
| return fieldName; | ||
| } | ||
|
|
||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return boost; | ||
| } | ||
|
|
||
| public Integer getFuzziness() { | ||
| return fuzziness; | ||
| } | ||
|
|
||
| public Integer getMaxExpansions() { | ||
| return maxExpansions; | ||
| } | ||
|
|
||
| public Integer getPrefixLength() { | ||
| return prefixLength; | ||
| } | ||
|
|
||
| public Boolean getTranspositions() { | ||
| return transpositions; | ||
| } | ||
|
|
||
| public String getRewrite() { | ||
| return rewrite; | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...rc/main/java/org/evomaster/client/java/controller/opensearch/operations/IdsOperation.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,31 @@ | ||
| package org.evomaster.client.java.controller.opensearch.operations; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Represents IDs operation. | ||
| * Searches for documents with one or more specific document ID values in the _id field. | ||
| * <p> | ||
| * <a href="https://docs.opensearch.org/latest/query-dsl/term/ids/">OpenSearch IDs Operation</a> | ||
| */ | ||
| public class IdsOperation extends QueryOperation { | ||
| private final List<String> values; | ||
| private final Float boost; | ||
|
|
||
| public IdsOperation(List<String> values) { | ||
| this(values, null); | ||
| } | ||
|
|
||
| public IdsOperation(List<String> values, Float boost) { | ||
| this.values = values; | ||
| this.boost = boost; | ||
| } | ||
|
|
||
| public List<String> getValues() { | ||
| return values; | ||
| } | ||
|
|
||
| public Float getBoost() { | ||
| return boost; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need tests for OpenSearchQueryParser to check that the JSON is correctly parsed into its corresponding OpenSearch operation.