diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/FunctionParameterRepository.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/FunctionParameterRepository.java index f21d343e3c..373df4e5fc 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/FunctionParameterRepository.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/FunctionParameterRepository.java @@ -10,50 +10,191 @@ import java.util.Arrays; import java.util.Map; import java.util.stream.Collectors; +import lombok.experimental.UtilityClass; import org.opensearch.common.unit.Fuzziness; import org.opensearch.common.xcontent.LoggingDeprecationHandler; +import org.opensearch.index.query.MatchBoolPrefixQueryBuilder; +import org.opensearch.index.query.MatchPhrasePrefixQueryBuilder; +import org.opensearch.index.query.MatchPhraseQueryBuilder; +import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.index.query.MultiMatchQueryBuilder; import org.opensearch.index.query.Operator; +import org.opensearch.index.query.QueryStringQueryBuilder; +import org.opensearch.index.query.SimpleQueryStringBuilder; import org.opensearch.index.query.SimpleQueryStringFlag; import org.opensearch.index.query.support.QueryParsers; import org.opensearch.index.search.MatchQuery; import org.opensearch.sql.data.model.ExprValue; +@UtilityClass public class FunctionParameterRepository { - private FunctionParameterRepository() { - } - public static final Map ArgumentLimitations; - - static { - ArgumentLimitations = ImmutableMap.builder() - .put("boost", "Accepts only floating point values greater than 0.") - .put("tie_breaker", "Accepts only floating point values in range 0 to 1.") - .put("rewrite", "Available values are: constant_score, " - + "scoring_boolean, constant_score_boolean, top_terms_X, top_terms_boost_X, " - + "top_terms_blended_freqs_X, where X is an integer value.") - .put("flags", String.format( - "Available values are: %s and any combinations of these separated by '|'.", - Arrays.stream(SimpleQueryStringFlag.class.getEnumConstants()) - .map(Enum::toString).collect(Collectors.joining(", ")))) - .put("time_zone", "For more information, follow this link: " - + "https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#of-java.lang.String-") - .put("fuzziness", "Available values are: " - + "'AUTO', 'AUTO:x,y' or z, where x, y, z - integer values.") - .put("operator", String.format("Available values are: %s.", - Arrays.stream(Operator.class.getEnumConstants()) - .map(Enum::toString).collect(Collectors.joining(", ")))) - .put("type", String.format("Available values are: %s.", - Arrays.stream(MultiMatchQueryBuilder.Type.class.getEnumConstants()) - .map(Enum::toString).collect(Collectors.joining(", ")))) - .put("zero_terms_query", String.format("Available values are: %s.", - Arrays.stream(MatchQuery.ZeroTermsQuery.class.getEnumConstants()) - .map(Enum::toString).collect(Collectors.joining(", ")))) - .put("int", "Accepts only integer values.") - .put("float", "Accepts only floating point values.") - .put("bool", "Accepts only boolean values: 'true' or 'false'.") - .build(); - } + public static final Map> + MatchBoolPrefixQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("fuzziness", (b, v) -> b.fuzziness(convertFuzziness(v))) + .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite(checkRewrite(v, "fuzzy_rewrite"))) + .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( + convertBoolValue(v, "fuzzy_transpositions"))) + .put("max_expansions", (b, v) -> b.maxExpansions(convertIntValue(v, "max_expansions"))) + .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) + .put("operator", (b, v) -> b.operator(convertOperator(v, "operator"))) + .put("prefix_length", (b, v) -> b.prefixLength(convertIntValue(v, "prefix_length"))) + .build(); + + public static final Map> + MatchPhrasePrefixQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("max_expansions", (b, v) -> b.maxExpansions(convertIntValue(v, "max_expansions"))) + .put("slop", (b, v) -> b.slop(convertIntValue(v, "slop"))) + .put("zero_terms_query", (b, v) -> b.zeroTermsQuery(convertZeroTermsQuery(v))) + .build(); + + public static final Map> + MatchPhraseQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("slop", (b, v) -> b.slop(convertIntValue(v, "slop"))) + .put("zero_terms_query", (b, v) -> b.zeroTermsQuery(convertZeroTermsQuery(v))) + .build(); + + public static final Map> + MatchQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( + convertBoolValue(v, "auto_generate_synonyms_phrase_query"))) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("fuzziness", (b, v) -> b.fuzziness(convertFuzziness(v))) + .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite(checkRewrite(v, "fuzzy_rewrite"))) + .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( + convertBoolValue(v, "fuzzy_transpositions"))) + .put("lenient", (b, v) -> b.lenient(convertBoolValue(v, "lenient"))) + .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) + .put("max_expansions", (b, v) -> b.maxExpansions(convertIntValue(v, "max_expansions"))) + .put("operator", (b, v) -> b.operator(convertOperator(v, "operator"))) + .put("prefix_length", (b, v) -> b.prefixLength(convertIntValue(v, "prefix_length"))) + .put("zero_terms_query", (b, v) -> b.zeroTermsQuery(convertZeroTermsQuery(v))) + .build(); + + @SuppressWarnings("deprecation") // cutoffFrequency is deprecated + public static final Map> + MultiMatchQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( + convertBoolValue(v, "auto_generate_synonyms_phrase_query"))) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("cutoff_frequency", (b, v) -> b.cutoffFrequency( + convertFloatValue(v, "cutoff_frequency"))) + .put("fuzziness", (b, v) -> b.fuzziness(convertFuzziness(v))) + .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( + convertBoolValue(v, "fuzzy_transpositions"))) + .put("lenient", (b, v) -> b.lenient(convertBoolValue(v, "lenient"))) + .put("max_expansions", (b, v) -> b.maxExpansions(convertIntValue(v, "max_expansions"))) + .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) + .put("operator", (b, v) -> b.operator(convertOperator(v, "operator"))) + .put("prefix_length", (b, v) -> b.prefixLength(convertIntValue(v, "prefix_length"))) + .put("slop", (b, v) -> b.slop(convertIntValue(v, "slop"))) + .put("tie_breaker", (b, v) -> b.tieBreaker(convertFloatValue(v, "tie_breaker"))) + .put("type", (b, v) -> b.type(convertType(v))) + .put("zero_terms_query", (b, v) -> b.zeroTermsQuery(convertZeroTermsQuery(v))) + .build(); + + public static final Map> + QueryStringQueryBuildActions = ImmutableMap.>builder() + .put("allow_leading_wildcard", (b, v) -> b.allowLeadingWildcard( + convertBoolValue(v, "allow_leading_wildcard"))) + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("analyze_wildcard", (b, v) -> b.analyzeWildcard( + convertBoolValue(v, "analyze_wildcard"))) + .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( + convertBoolValue(v, "auto_generate_synonyms_phrase_query"))) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("default_operator", (b, v) -> b.defaultOperator( + convertOperator(v, "default_operator"))) + .put("enable_position_increments", (b, v) -> b.enablePositionIncrements( + convertBoolValue(v, "enable_position_increments"))) + .put("escape", (b, v) -> b.escape(convertBoolValue(v, "escape"))) + .put("fuzziness", (b, v) -> b.fuzziness(convertFuzziness(v))) + .put("fuzzy_max_expansions", (b, v) -> b.fuzzyMaxExpansions( + convertIntValue(v, "fuzzy_max_expansions"))) + .put("fuzzy_prefix_length", (b, v) -> b.fuzzyPrefixLength( + convertIntValue(v, "fuzzy_prefix_length"))) + .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite(checkRewrite(v, "fuzzy_rewrite"))) + .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( + convertBoolValue(v, "fuzzy_transpositions"))) + .put("lenient", (b, v) -> b.lenient(convertBoolValue(v, "lenient"))) + .put("max_determinized_states", (b, v) -> b.maxDeterminizedStates( + convertIntValue(v, "max_determinized_states"))) + .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) + .put("phrase_slop", (b, v) -> b.phraseSlop(convertIntValue(v, "phrase_slop"))) + .put("quote_analyzer", (b, v) -> b.quoteAnalyzer(v.stringValue())) + .put("quote_field_suffix", (b, v) -> b.quoteFieldSuffix(v.stringValue())) + .put("rewrite", (b, v) -> b.rewrite(checkRewrite(v, "rewrite"))) + .put("tie_breaker", (b, v) -> b.tieBreaker(convertFloatValue(v, "tie_breaker"))) + .put("time_zone", (b, v) -> b.timeZone(checkTimeZone(v))) + .put("type", (b, v) -> b.type(convertType(v))) + .build(); + + public static final Map> + SimpleQueryStringQueryBuildActions = ImmutableMap.>builder() + .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) + .put("analyze_wildcard", (b, v) -> b.analyzeWildcard( + convertBoolValue(v, "analyze_wildcard"))) + .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( + convertBoolValue(v, "auto_generate_synonyms_phrase_query"))) + .put("boost", (b, v) -> b.boost(convertFloatValue(v, "boost"))) + .put("default_operator", (b, v) -> b.defaultOperator( + convertOperator(v, "default_operator"))) + .put("flags", (b, v) -> b.flags(convertFlags(v))) + .put("fuzzy_max_expansions", (b, v) -> b.fuzzyMaxExpansions( + convertIntValue(v, "fuzzy_max_expansions"))) + .put("fuzzy_prefix_length", (b, v) -> b.fuzzyPrefixLength( + convertIntValue(v, "fuzzy_prefix_length"))) + .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( + convertBoolValue(v, "fuzzy_transpositions"))) + .put("lenient", (b, v) -> b.lenient(convertBoolValue(v, "lenient"))) + .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) + .put("quote_field_suffix", (b, v) -> b.quoteFieldSuffix(v.stringValue())) + .build(); + + public static final Map ArgumentLimitations = + ImmutableMap.builder() + .put("boost", "Accepts only floating point values greater than 0.") + .put("tie_breaker", "Accepts only floating point values in range 0 to 1.") + .put("rewrite", "Available values are: constant_score, " + + "scoring_boolean, constant_score_boolean, top_terms_X, top_terms_boost_X, " + + "top_terms_blended_freqs_X, where X is an integer value.") + .put("flags", String.format( + "Available values are: %s and any combinations of these separated by '|'.", + Arrays.stream(SimpleQueryStringFlag.class.getEnumConstants()) + .map(Enum::toString).collect(Collectors.joining(", ")))) + .put("time_zone", "For more information, follow this link: " + + "https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#of-java.lang.String-") + .put("fuzziness", "Available values are: " + + "'AUTO', 'AUTO:x,y' or z, where x, y, z - integer values.") + .put("operator", String.format("Available values are: %s.", + Arrays.stream(Operator.class.getEnumConstants()) + .map(Enum::toString).collect(Collectors.joining(", ")))) + .put("type", String.format("Available values are: %s.", + Arrays.stream(MultiMatchQueryBuilder.Type.class.getEnumConstants()) + .map(Enum::toString).collect(Collectors.joining(", ")))) + .put("zero_terms_query", String.format("Available values are: %s.", + Arrays.stream(MatchQuery.ZeroTermsQuery.class.getEnumConstants()) + .map(Enum::toString).collect(Collectors.joining(", ")))) + .put("int", "Accepts only integer values.") + .put("float", "Accepts only floating point values.") + .put("bool", "Accepts only boolean values: 'true' or 'false'.") + .build(); + private static String formatErrorMessage(String name, String value) { return formatErrorMessage(name, value, name); diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchBoolPrefixQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchBoolPrefixQuery.java index 1c67916c36..7044a56035 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchBoolPrefixQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchBoolPrefixQuery.java @@ -5,9 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; -import com.google.common.collect.ImmutableMap; import org.opensearch.index.query.MatchBoolPrefixQueryBuilder; -import org.opensearch.index.query.Operator; import org.opensearch.index.query.QueryBuilders; /** @@ -20,23 +18,7 @@ public class MatchBoolPrefixQuery * with support of optional parameters. */ public MatchBoolPrefixQuery() { - super(ImmutableMap.>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("fuzziness", (b, v) -> b.fuzziness(FunctionParameterRepository.convertFuzziness(v))) - .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite( - FunctionParameterRepository.checkRewrite(v, "fuzzy_rewrite"))) - .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( - FunctionParameterRepository.convertBoolValue(v, "fuzzy_transpositions"))) - .put("max_expansions", (b, v) -> b.maxExpansions( - FunctionParameterRepository.convertIntValue(v, "max_expansions"))) - .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) - .put("operator", (b, v) -> b.operator( - FunctionParameterRepository.convertOperator(v, "operator"))) - .put("prefix_length", (b, v) -> b.prefixLength( - FunctionParameterRepository.convertIntValue(v, "prefix_length"))) - .build()); + super(FunctionParameterRepository.MatchBoolPrefixQueryBuildActions); } /** diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhrasePrefixQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhrasePrefixQuery.java index 7f62b9b706..8ee9ae299e 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhrasePrefixQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhrasePrefixQuery.java @@ -5,30 +5,19 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; -import com.google.common.collect.ImmutableMap; import org.opensearch.index.query.MatchPhrasePrefixQueryBuilder; import org.opensearch.index.query.QueryBuilders; /** * Lucene query that builds a match_phrase_prefix query. */ -public class MatchPhrasePrefixQuery extends SingleFieldQuery { +public class MatchPhrasePrefixQuery extends SingleFieldQuery { /** * Default constructor for MatchPhrasePrefixQuery configures how RelevanceQuery.build() handles * named arguments. */ public MatchPhrasePrefixQuery() { - super(ImmutableMap.>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("max_expansions", (b, v) -> b.maxExpansions( - FunctionParameterRepository.convertIntValue(v, "max_expansions"))) - .put("slop", (b, v) -> b.slop( - FunctionParameterRepository.convertIntValue(v, "slop"))) - .put("zero_terms_query", (b, v) -> b.zeroTermsQuery( - FunctionParameterRepository.convertZeroTermsQuery(v))) - .build()); + super(FunctionParameterRepository.MatchPhrasePrefixQueryBuildActions); } @Override diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhraseQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhraseQuery.java index 2a93fe4657..2afaca1a7a 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhraseQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchPhraseQuery.java @@ -5,20 +5,8 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; -import com.google.common.collect.ImmutableMap; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.function.BiFunction; import org.opensearch.index.query.MatchPhraseQueryBuilder; -import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilders; -import org.opensearch.sql.data.model.ExprValue; -import org.opensearch.sql.exception.SemanticCheckException; -import org.opensearch.sql.expression.Expression; -import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.NamedArgumentExpression; -import org.opensearch.sql.opensearch.storage.script.filter.lucene.LuceneQuery; /** * Lucene query that builds a match_phrase query. @@ -29,15 +17,7 @@ public class MatchPhraseQuery extends SingleFieldQuery * named arguments. */ public MatchPhraseQuery() { - super(ImmutableMap.>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("slop", (b, v) -> b.slop( - FunctionParameterRepository.convertIntValue(v, "slop"))) - .put("zero_terms_query", (b, v) -> b.zeroTermsQuery( - FunctionParameterRepository.convertZeroTermsQuery(v))) - .build()); + super(FunctionParameterRepository.MatchPhraseQueryBuildActions); } @Override diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchQuery.java index 67e583052c..a4de1c0831 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MatchQuery.java @@ -5,9 +5,7 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; -import com.google.common.collect.ImmutableMap; import org.opensearch.index.query.MatchQueryBuilder; -import org.opensearch.index.query.Operator; import org.opensearch.index.query.QueryBuilders; /** @@ -19,29 +17,7 @@ public class MatchQuery extends SingleFieldQuery { * named arguments. */ public MatchQuery() { - super(ImmutableMap.>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( - FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query"))) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("fuzziness", (b, v) -> b.fuzziness(FunctionParameterRepository.convertFuzziness(v))) - .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite( - FunctionParameterRepository.checkRewrite(v, "fuzzy_rewrite"))) - .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( - FunctionParameterRepository.convertBoolValue(v, "fuzzy_transpositions"))) - .put("lenient", (b, v) -> b.lenient( - FunctionParameterRepository.convertBoolValue(v, "lenient"))) - .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) - .put("max_expansions", (b, v) -> b.maxExpansions( - FunctionParameterRepository.convertIntValue(v, "max_expansions"))) - .put("operator", (b, v) -> b.operator( - FunctionParameterRepository.convertOperator(v, "operator"))) - .put("prefix_length", (b, v) -> b.prefixLength( - FunctionParameterRepository.convertIntValue(v, "prefix_length"))) - .put("zero_terms_query", (b, v) -> b.zeroTermsQuery( - FunctionParameterRepository.convertZeroTermsQuery(v))) - .build()); + super(FunctionParameterRepository.MatchQueryBuildActions); } @Override diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiMatchQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiMatchQuery.java index 00e35bd061..a791bf756b 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiMatchQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/MultiMatchQuery.java @@ -15,35 +15,7 @@ public class MultiMatchQuery extends MultiFieldQuery { * named arguments. */ public MultiMatchQuery() { - super(ImmutableMap.>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("auto_generate_synonyms_phrase_query", (b, v) -> - b.autoGenerateSynonymsPhraseQuery(FunctionParameterRepository - .convertBoolValue(v, "auto_generate_synonyms_phrase_query"))) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("cutoff_frequency", (b, v) -> b.cutoffFrequency( - FunctionParameterRepository.convertFloatValue(v, "cutoff_frequency"))) - .put("fuzziness", (b, v) -> b.fuzziness(FunctionParameterRepository.convertFuzziness(v))) - .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( - FunctionParameterRepository.convertBoolValue(v, "fuzzy_transpositions"))) - .put("lenient", (b, v) -> b.lenient( - FunctionParameterRepository.convertBoolValue(v, "lenient"))) - .put("max_expansions", (b, v) -> b.maxExpansions( - FunctionParameterRepository.convertIntValue(v, "max_expansions"))) - .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) - .put("operator", (b, v) -> b.operator( - FunctionParameterRepository.convertOperator(v, "operator"))) - .put("prefix_length", (b, v) -> b.prefixLength( - FunctionParameterRepository.convertIntValue(v, "prefix_length"))) - .put("slop", (b, v) -> b.slop( - FunctionParameterRepository.convertIntValue(v, "slop"))) - .put("tie_breaker", (b, v) -> b.tieBreaker( - FunctionParameterRepository.convertFloatValue(v, "tie_breaker"))) - .put("type", (b, v) -> b.type(FunctionParameterRepository.convertType(v))) - .put("zero_terms_query", (b, v) -> b.zeroTermsQuery( - FunctionParameterRepository.convertZeroTermsQuery(v))) - .build()); + super(FunctionParameterRepository.MultiMatchQueryBuildActions); } @Override diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryStringQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryStringQuery.java index b1e6063d22..43131baa3e 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryStringQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/QueryStringQuery.java @@ -6,19 +6,8 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; import com.google.common.collect.ImmutableMap; -import java.util.Iterator; -import java.util.Objects; -import org.opensearch.common.unit.Fuzziness; -import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.index.query.MultiMatchQueryBuilder; -import org.opensearch.index.query.Operator; -import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.query.QueryStringQueryBuilder; -import org.opensearch.sql.exception.SemanticCheckException; -import org.opensearch.sql.expression.Expression; -import org.opensearch.sql.expression.FunctionExpression; -import org.opensearch.sql.expression.NamedArgumentExpression; /** * Class for Lucene query that builds the query_string query. @@ -29,50 +18,9 @@ public class QueryStringQuery extends MultiFieldQuery { * named arguments. */ public QueryStringQuery() { - super(ImmutableMap.>builder() - .put("allow_leading_wildcard", (b, v) -> b.allowLeadingWildcard( - FunctionParameterRepository.convertBoolValue(v, "allow_leading_wildcard"))) - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("analyze_wildcard", (b, v) -> b.analyzeWildcard( - FunctionParameterRepository.convertBoolValue(v, "analyze_wildcard"))) - .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( - FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query"))) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("default_operator", (b, v) -> b.defaultOperator( - FunctionParameterRepository.convertOperator(v, "default_operator"))) - .put("enable_position_increments", (b, v) -> b.enablePositionIncrements( - FunctionParameterRepository.convertBoolValue(v, "enable_position_increments"))) - .put("escape", (b, v) -> b.escape( - FunctionParameterRepository.convertBoolValue(v, "escape"))) - .put("fuzziness", (b, v) -> b.fuzziness(FunctionParameterRepository.convertFuzziness(v))) - .put("fuzzy_max_expansions", (b, v) -> b.fuzzyMaxExpansions( - FunctionParameterRepository.convertIntValue(v, "fuzzy_max_expansions"))) - .put("fuzzy_prefix_length", (b, v) -> b.fuzzyPrefixLength( - FunctionParameterRepository.convertIntValue(v, "fuzzy_prefix_length"))) - .put("fuzzy_rewrite", (b, v) -> b.fuzzyRewrite( - FunctionParameterRepository.checkRewrite(v, "fuzzy_rewrite"))) - .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( - FunctionParameterRepository.convertBoolValue(v, "fuzzy_transpositions"))) - .put("lenient", (b, v) -> b.lenient( - FunctionParameterRepository.convertBoolValue(v, "lenient"))) - .put("max_determinized_states", (b, v) -> b.maxDeterminizedStates( - FunctionParameterRepository.convertIntValue(v, "max_determinized_states"))) - .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) - .put("phrase_slop", (b, v) -> b.phraseSlop( - FunctionParameterRepository.convertIntValue(v, "phrase_slop"))) - .put("quote_analyzer", (b, v) -> b.quoteAnalyzer(v.stringValue())) - .put("quote_field_suffix", (b, v) -> b.quoteFieldSuffix(v.stringValue())) - .put("rewrite", (b, v) -> b.rewrite( - FunctionParameterRepository.checkRewrite(v, "rewrite"))) - .put("tie_breaker", (b, v) -> b.tieBreaker( - FunctionParameterRepository.convertFloatValue(v, "tie_breaker"))) - .put("time_zone", (b, v) -> b.timeZone(FunctionParameterRepository.checkTimeZone(v))) - .put("type", (b, v) -> b.type(FunctionParameterRepository.convertType(v))) - .build()); + super(FunctionParameterRepository.QueryStringQueryBuildActions); } - /** * Builds QueryBuilder with query value and other default parameter values set. * diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SimpleQueryStringQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SimpleQueryStringQuery.java index 6e8b7352a7..157921572a 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SimpleQueryStringQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/relevance/SimpleQueryStringQuery.java @@ -6,13 +6,8 @@ package org.opensearch.sql.opensearch.storage.script.filter.lucene.relevance; import com.google.common.collect.ImmutableMap; -import java.util.Arrays; -import java.util.Iterator; -import java.util.Objects; -import org.opensearch.index.query.Operator; import org.opensearch.index.query.QueryBuilders; import org.opensearch.index.query.SimpleQueryStringBuilder; -import org.opensearch.index.query.SimpleQueryStringFlag; public class SimpleQueryStringQuery extends MultiFieldQuery { /** @@ -20,28 +15,7 @@ public class SimpleQueryStringQuery extends MultiFieldQuery>builder() - .put("analyzer", (b, v) -> b.analyzer(v.stringValue())) - .put("analyze_wildcard", (b, v) -> b.analyzeWildcard( - FunctionParameterRepository.convertBoolValue(v, "analyze_wildcard"))) - .put("auto_generate_synonyms_phrase_query", (b, v) -> b.autoGenerateSynonymsPhraseQuery( - FunctionParameterRepository.convertBoolValue(v,"auto_generate_synonyms_phrase_query"))) - .put("boost", (b, v) -> b.boost( - FunctionParameterRepository.convertFloatValue(v, "boost"))) - .put("default_operator", (b, v) -> b.defaultOperator( - FunctionParameterRepository.convertOperator(v, "default_operator"))) - .put("flags", (b, v) -> b.flags(FunctionParameterRepository.convertFlags(v))) - .put("fuzzy_max_expansions", (b, v) -> b.fuzzyMaxExpansions( - FunctionParameterRepository.convertIntValue(v, "fuzzy_max_expansions"))) - .put("fuzzy_prefix_length", (b, v) -> b.fuzzyPrefixLength( - FunctionParameterRepository.convertIntValue(v, "fuzzy_prefix_length"))) - .put("fuzzy_transpositions", (b, v) -> b.fuzzyTranspositions( - FunctionParameterRepository.convertBoolValue(v, "fuzzy_transpositions"))) - .put("lenient", (b, v) -> b.lenient( - FunctionParameterRepository.convertBoolValue(v, "lenient"))) - .put("minimum_should_match", (b, v) -> b.minimumShouldMatch(v.stringValue())) - .put("quote_field_suffix", (b, v) -> b.quoteFieldSuffix(v.stringValue())) - .build()); + super(FunctionParameterRepository.SimpleQueryStringQueryBuildActions); } @Override