Search in sources :

Example 1 with Fuzziness

use of org.opensearch.common.unit.Fuzziness in project OpenSearch by opensearch-project.

the class FuzzyIntervalsSourceProviderTests method mutateInstance.

@Override
protected Fuzzy mutateInstance(Fuzzy instance) throws IOException {
    String term = instance.getTerm();
    int prefixLength = instance.getPrefixLength();
    boolean isTranspositions = instance.isTranspositions();
    Fuzziness fuzziness = instance.getFuzziness();
    String analyzer = instance.getAnalyzer();
    String useField = instance.getUseField();
    switch(between(0, 5)) {
        case 0:
            term = randomAlphaOfLength(5);
            break;
        case 1:
            prefixLength++;
            break;
        case 2:
            isTranspositions = !isTranspositions;
            break;
        case 3:
            if (fuzziness.equals(Fuzziness.ZERO)) {
                fuzziness = Fuzziness.ONE;
            } else {
                fuzziness = Fuzziness.ZERO;
            }
            break;
        case 4:
            analyzer = analyzer == null ? randomAlphaOfLength(5) : null;
            break;
        case 5:
            useField = useField == null ? randomAlphaOfLength(5) : null;
            break;
        default:
            throw new AssertionError("Illegal randomisation branch");
    }
    return new Fuzzy(term, prefixLength, isTranspositions, fuzziness, analyzer, useField);
}
Also used : Fuzziness(org.opensearch.common.unit.Fuzziness) Fuzzy(org.opensearch.index.query.IntervalsSourceProvider.Fuzzy)

Example 2 with Fuzziness

use of org.opensearch.common.unit.Fuzziness in project OpenSearch by opensearch-project.

the class QueryStringQueryBuilderTests method mutateInstance.

@Override
public QueryStringQueryBuilder mutateInstance(QueryStringQueryBuilder instance) throws IOException {
    String query = instance.queryString();
    String defaultField = instance.defaultField();
    Map<String, Float> fields = instance.fields();
    Operator operator = instance.defaultOperator();
    Fuzziness fuzziness = instance.fuzziness();
    String analyzer = instance.analyzer();
    String quoteAnalyzer = instance.quoteAnalyzer();
    Boolean allowLeadingWildCard = instance.allowLeadingWildcard();
    Boolean analyzeWildcard = instance.analyzeWildcard();
    int maxDeterminizedStates = instance.maxDeterminizedStates();
    boolean enablePositionIncrements = instance.enablePositionIncrements();
    boolean escape = instance.escape();
    int phraseSlop = instance.phraseSlop();
    int fuzzyMaxExpansions = instance.fuzzyMaxExpansions();
    int fuzzyPrefixLength = instance.fuzzyPrefixLength();
    String fuzzyRewrite = instance.fuzzyRewrite();
    String rewrite = instance.rewrite();
    String quoteFieldSuffix = instance.quoteFieldSuffix();
    Float tieBreaker = instance.tieBreaker();
    String minimumShouldMatch = instance.minimumShouldMatch();
    String timeZone = instance.timeZone() == null ? null : instance.timeZone().getId();
    boolean autoGenerateSynonymsPhraseQuery = instance.autoGenerateSynonymsPhraseQuery();
    boolean fuzzyTranspositions = instance.fuzzyTranspositions();
    switch(between(0, 23)) {
        case 0:
            query = query + " foo";
            break;
        case 1:
            if (defaultField == null) {
                defaultField = randomAlphaOfLengthBetween(1, 10);
            } else {
                defaultField = defaultField + randomAlphaOfLength(5);
            }
            break;
        case 2:
            fields = new HashMap<>(fields);
            fields.put(randomAlphaOfLength(10), 1.0f);
            break;
        case 3:
            operator = randomValueOtherThan(operator, () -> randomFrom(Operator.values()));
            break;
        case 4:
            fuzziness = randomValueOtherThan(fuzziness, () -> randomFrom(Fuzziness.AUTO, Fuzziness.ZERO, Fuzziness.ONE, Fuzziness.TWO));
            break;
        case 5:
            if (analyzer == null) {
                analyzer = randomAnalyzer();
            } else {
                analyzer = null;
            }
            break;
        case 6:
            if (quoteAnalyzer == null) {
                quoteAnalyzer = randomAnalyzer();
            } else {
                quoteAnalyzer = null;
            }
            break;
        case 7:
            if (allowLeadingWildCard == null) {
                allowLeadingWildCard = randomBoolean();
            } else {
                allowLeadingWildCard = randomBoolean() ? null : (allowLeadingWildCard == false);
            }
            break;
        case 8:
            if (analyzeWildcard == null) {
                analyzeWildcard = randomBoolean();
            } else {
                analyzeWildcard = randomBoolean() ? null : (analyzeWildcard == false);
            }
            break;
        case 9:
            maxDeterminizedStates += 5;
            break;
        case 10:
            enablePositionIncrements = (enablePositionIncrements == false);
            break;
        case 11:
            escape = (escape == false);
            break;
        case 12:
            phraseSlop += 5;
            break;
        case 13:
            fuzzyMaxExpansions += 5;
            break;
        case 14:
            fuzzyPrefixLength += 5;
            break;
        case 15:
            if (fuzzyRewrite == null) {
                fuzzyRewrite = getRandomRewriteMethod();
            } else {
                fuzzyRewrite = null;
            }
            break;
        case 16:
            if (rewrite == null) {
                rewrite = getRandomRewriteMethod();
            } else {
                rewrite = null;
            }
            break;
        case 17:
            if (quoteFieldSuffix == null) {
                quoteFieldSuffix = randomAlphaOfLengthBetween(1, 3);
            } else {
                quoteFieldSuffix = quoteFieldSuffix + randomAlphaOfLength(1);
            }
            break;
        case 18:
            if (tieBreaker == null) {
                tieBreaker = randomFloat();
            } else {
                tieBreaker += 0.05f;
            }
            break;
        case 19:
            if (minimumShouldMatch == null) {
                minimumShouldMatch = randomMinimumShouldMatch();
            } else {
                minimumShouldMatch = null;
            }
            break;
        case 20:
            if (timeZone == null) {
                timeZone = randomZone().getId();
            } else {
                if (randomBoolean()) {
                    timeZone = null;
                } else {
                    timeZone = randomValueOtherThan(timeZone, () -> randomZone().getId());
                }
            }
            break;
        case 21:
            autoGenerateSynonymsPhraseQuery = (autoGenerateSynonymsPhraseQuery == false);
            break;
        case 22:
            fuzzyTranspositions = (fuzzyTranspositions == false);
            break;
        case 23:
            return changeNameOrBoost(instance);
        default:
            throw new AssertionError("Illegal randomisation branch");
    }
    QueryStringQueryBuilder newInstance = new QueryStringQueryBuilder(query);
    if (defaultField != null) {
        newInstance.defaultField(defaultField);
    }
    newInstance.fields(fields);
    newInstance.defaultOperator(operator);
    newInstance.fuzziness(fuzziness);
    if (analyzer != null) {
        newInstance.analyzer(analyzer);
    }
    if (quoteAnalyzer != null) {
        newInstance.quoteAnalyzer(quoteAnalyzer);
    }
    if (allowLeadingWildCard != null) {
        newInstance.allowLeadingWildcard(allowLeadingWildCard);
    }
    if (analyzeWildcard != null) {
        newInstance.analyzeWildcard(analyzeWildcard);
    }
    newInstance.maxDeterminizedStates(maxDeterminizedStates);
    newInstance.enablePositionIncrements(enablePositionIncrements);
    newInstance.escape(escape);
    newInstance.phraseSlop(phraseSlop);
    newInstance.fuzzyMaxExpansions(fuzzyMaxExpansions);
    newInstance.fuzzyPrefixLength(fuzzyPrefixLength);
    if (fuzzyRewrite != null) {
        newInstance.fuzzyRewrite(fuzzyRewrite);
    }
    if (rewrite != null) {
        newInstance.rewrite(rewrite);
    }
    if (quoteFieldSuffix != null) {
        newInstance.quoteFieldSuffix(quoteFieldSuffix);
    }
    if (tieBreaker != null) {
        newInstance.tieBreaker(tieBreaker);
    }
    if (minimumShouldMatch != null) {
        newInstance.minimumShouldMatch(minimumShouldMatch);
    }
    if (timeZone != null) {
        newInstance.timeZone(timeZone);
    }
    newInstance.autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery);
    newInstance.fuzzyTranspositions(fuzzyTranspositions);
    return newInstance;
}
Also used : Fuzziness(org.opensearch.common.unit.Fuzziness) Matchers.containsString(org.hamcrest.Matchers.containsString) LongPoint(org.apache.lucene.document.LongPoint)

Example 3 with Fuzziness

use of org.opensearch.common.unit.Fuzziness in project OpenSearch by opensearch-project.

the class MultiMatchQueryBuilder method fromXContent.

public static MultiMatchQueryBuilder fromXContent(XContentParser parser) throws IOException {
    Object value = null;
    Map<String, Float> fieldsBoosts = new HashMap<>();
    MultiMatchQueryBuilder.Type type = DEFAULT_TYPE;
    String analyzer = null;
    int slop = DEFAULT_PHRASE_SLOP;
    Fuzziness fuzziness = null;
    int prefixLength = DEFAULT_PREFIX_LENGTH;
    int maxExpansions = DEFAULT_MAX_EXPANSIONS;
    Operator operator = DEFAULT_OPERATOR;
    String minimumShouldMatch = null;
    String fuzzyRewrite = null;
    Boolean useDisMax = null;
    Float tieBreaker = null;
    Float cutoffFrequency = null;
    Boolean lenient = null;
    MatchQuery.ZeroTermsQuery zeroTermsQuery = DEFAULT_ZERO_TERMS_QUERY;
    boolean autoGenerateSynonymsPhraseQuery = true;
    boolean fuzzyTranspositions = DEFAULT_FUZZY_TRANSPOSITIONS;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String queryName = null;
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
            if (token == XContentParser.Token.START_ARRAY) {
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    parseFieldAndBoost(parser, fieldsBoosts);
                }
            } else if (token.isValue()) {
                parseFieldAndBoost(parser, fieldsBoosts);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                value = parser.objectText();
            } else if (TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                type = MultiMatchQueryBuilder.Type.parse(parser.text(), parser.getDeprecationHandler());
            } else if (ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                analyzer = parser.text();
            } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                boost = parser.floatValue();
            } else if (SLOP_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                slop = parser.intValue();
            } else if (Fuzziness.FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                fuzziness = Fuzziness.parse(parser);
            } else if (PREFIX_LENGTH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                prefixLength = parser.intValue();
            } else if (MAX_EXPANSIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                maxExpansions = parser.intValue();
            } else if (OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                operator = Operator.fromString(parser.text());
            } else if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                minimumShouldMatch = parser.textOrNull();
            } else if (FUZZY_REWRITE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                fuzzyRewrite = parser.textOrNull();
            } else if (TIE_BREAKER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                tieBreaker = parser.floatValue();
            } else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                cutoffFrequency = parser.floatValue();
            } else if (LENIENT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                lenient = parser.booleanValue();
            } else if (ZERO_TERMS_QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                String zeroTermsValue = parser.text();
                if ("none".equalsIgnoreCase(zeroTermsValue)) {
                    zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE;
                } else if ("all".equalsIgnoreCase(zeroTermsValue)) {
                    zeroTermsQuery = MatchQuery.ZeroTermsQuery.ALL;
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_query value [" + zeroTermsValue + "]");
                }
            } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                queryName = parser.text();
            } else if (GENERATE_SYNONYMS_PHRASE_QUERY.match(currentFieldName, parser.getDeprecationHandler())) {
                autoGenerateSynonymsPhraseQuery = parser.booleanValue();
            } else if (FUZZY_TRANSPOSITIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                fuzzyTranspositions = parser.booleanValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support [" + currentFieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
        }
    }
    if (value == null) {
        throw new ParsingException(parser.getTokenLocation(), "No text specified for multi_match query");
    }
    if (fuzziness != null && (type == Type.CROSS_FIELDS || type == Type.PHRASE || type == Type.PHRASE_PREFIX)) {
        throw new ParsingException(parser.getTokenLocation(), "Fuzziness not allowed for type [" + type.parseField.getPreferredName() + "]");
    }
    if (slop != DEFAULT_PHRASE_SLOP && type == Type.BOOL_PREFIX) {
        throw new ParsingException(parser.getTokenLocation(), "[" + SLOP_FIELD.getPreferredName() + "] not allowed for type [" + type.parseField.getPreferredName() + "]");
    }
    if (cutoffFrequency != null && type == Type.BOOL_PREFIX) {
        throw new ParsingException(parser.getTokenLocation(), "[" + CUTOFF_FREQUENCY_FIELD.getPreferredName() + "] not allowed for type [" + type.parseField.getPreferredName() + "]");
    }
    MultiMatchQueryBuilder builder = new MultiMatchQueryBuilder(value).fields(fieldsBoosts).type(type).analyzer(analyzer).cutoffFrequency(cutoffFrequency).fuzziness(fuzziness).fuzzyRewrite(fuzzyRewrite).maxExpansions(maxExpansions).minimumShouldMatch(minimumShouldMatch).operator(operator).prefixLength(prefixLength).slop(slop).tieBreaker(tieBreaker).zeroTermsQuery(zeroTermsQuery).autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery).boost(boost).queryName(queryName).fuzzyTranspositions(fuzzyTranspositions);
    if (lenient != null) {
        builder.lenient(lenient);
    }
    return builder;
}
Also used : HashMap(java.util.HashMap) Fuzziness(org.opensearch.common.unit.Fuzziness) ParsingException(org.opensearch.common.ParsingException) MultiMatchQuery(org.opensearch.index.search.MultiMatchQuery) MatchQuery(org.opensearch.index.search.MatchQuery) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 4 with Fuzziness

use of org.opensearch.common.unit.Fuzziness in project OpenSearch by opensearch-project.

the class MatchBoolPrefixQueryBuilder method fromXContent.

public static MatchBoolPrefixQueryBuilder fromXContent(XContentParser parser) throws IOException {
    String fieldName = null;
    Object value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String analyzer = null;
    Operator operator = DEFAULT_OPERATOR;
    String minimumShouldMatch = null;
    Fuzziness fuzziness = null;
    int prefixLength = FuzzyQuery.defaultPrefixLength;
    int maxExpansion = FuzzyQuery.defaultMaxExpansions;
    boolean fuzzyTranspositions = FuzzyQuery.defaultTranspositions;
    String fuzzyRewrite = null;
    String queryName = null;
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token.isValue()) {
                    if (MatchQueryBuilder.QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        value = parser.objectText();
                    } else if (MatchQueryBuilder.ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        analyzer = parser.text();
                    } else if (OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        operator = Operator.fromString(parser.text());
                    } else if (MatchQueryBuilder.MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        minimumShouldMatch = parser.textOrNull();
                    } else if (Fuzziness.FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzziness = Fuzziness.parse(parser);
                    } else if (PREFIX_LENGTH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        prefixLength = parser.intValue();
                    } else if (MAX_EXPANSIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        maxExpansion = parser.intValue();
                    } else if (FUZZY_TRANSPOSITIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzzyTranspositions = parser.booleanValue();
                    } else if (FUZZY_REWRITE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzzyRewrite = parser.textOrNull();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        boost = parser.floatValue();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support [" + currentFieldName + "]");
                    }
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectText();
        }
    }
    MatchBoolPrefixQueryBuilder queryBuilder = new MatchBoolPrefixQueryBuilder(fieldName, value);
    queryBuilder.analyzer(analyzer);
    queryBuilder.operator(operator);
    queryBuilder.minimumShouldMatch(minimumShouldMatch);
    queryBuilder.boost(boost);
    queryBuilder.queryName(queryName);
    if (fuzziness != null) {
        queryBuilder.fuzziness(fuzziness);
    }
    queryBuilder.prefixLength(prefixLength);
    queryBuilder.maxExpansions(maxExpansion);
    queryBuilder.fuzzyTranspositions(fuzzyTranspositions);
    queryBuilder.fuzzyRewrite(fuzzyRewrite);
    return queryBuilder;
}
Also used : Fuzziness(org.opensearch.common.unit.Fuzziness) ParsingException(org.opensearch.common.ParsingException) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 5 with Fuzziness

use of org.opensearch.common.unit.Fuzziness in project OpenSearch by opensearch-project.

the class MatchQueryBuilder method fromXContent.

public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOException {
    String fieldName = null;
    Object value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String minimumShouldMatch = null;
    String analyzer = null;
    Operator operator = MatchQueryBuilder.DEFAULT_OPERATOR;
    Fuzziness fuzziness = null;
    int prefixLength = FuzzyQuery.defaultPrefixLength;
    int maxExpansion = FuzzyQuery.defaultMaxExpansions;
    boolean fuzzyTranspositions = FuzzyQuery.defaultTranspositions;
    String fuzzyRewrite = null;
    boolean lenient = MatchQuery.DEFAULT_LENIENCY;
    Float cutOffFrequency = null;
    ZeroTermsQuery zeroTermsQuery = MatchQuery.DEFAULT_ZERO_TERMS_QUERY;
    boolean autoGenerateSynonymsPhraseQuery = true;
    String queryName = null;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token.isValue()) {
                    if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        value = parser.objectText();
                    } else if (ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        analyzer = parser.text();
                    } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        boost = parser.floatValue();
                    } else if (Fuzziness.FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzziness = Fuzziness.parse(parser);
                    } else if (PREFIX_LENGTH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        prefixLength = parser.intValue();
                    } else if (MAX_EXPANSIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        maxExpansion = parser.intValue();
                    } else if (OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        operator = Operator.fromString(parser.text());
                    } else if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        minimumShouldMatch = parser.textOrNull();
                    } else if (FUZZY_REWRITE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzzyRewrite = parser.textOrNull();
                    } else if (FUZZY_TRANSPOSITIONS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        fuzzyTranspositions = parser.booleanValue();
                    } else if (LENIENT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        lenient = parser.booleanValue();
                    } else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        cutOffFrequency = parser.floatValue();
                    } else if (ZERO_TERMS_QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        String zeroTermsValue = parser.text();
                        if ("none".equalsIgnoreCase(zeroTermsValue)) {
                            zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE;
                        } else if ("all".equalsIgnoreCase(zeroTermsValue)) {
                            zeroTermsQuery = MatchQuery.ZeroTermsQuery.ALL;
                        } else {
                            throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_query value [" + zeroTermsValue + "]");
                        }
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
                        queryName = parser.text();
                    } else if (GENERATE_SYNONYMS_PHRASE_QUERY.match(currentFieldName, parser.getDeprecationHandler())) {
                        autoGenerateSynonymsPhraseQuery = parser.booleanValue();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support [" + currentFieldName + "]");
                    }
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectText();
        }
    }
    if (value == null) {
        throw new ParsingException(parser.getTokenLocation(), "No text specified for text query");
    }
    MatchQueryBuilder matchQuery = new MatchQueryBuilder(fieldName, value);
    matchQuery.operator(operator);
    matchQuery.analyzer(analyzer);
    matchQuery.minimumShouldMatch(minimumShouldMatch);
    if (fuzziness != null) {
        matchQuery.fuzziness(fuzziness);
    }
    matchQuery.fuzzyRewrite(fuzzyRewrite);
    matchQuery.prefixLength(prefixLength);
    matchQuery.fuzzyTranspositions(fuzzyTranspositions);
    matchQuery.maxExpansions(maxExpansion);
    matchQuery.lenient(lenient);
    if (cutOffFrequency != null) {
        matchQuery.cutoffFrequency(cutOffFrequency);
    }
    matchQuery.zeroTermsQuery(zeroTermsQuery);
    matchQuery.autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery);
    matchQuery.queryName(queryName);
    matchQuery.boost(boost);
    return matchQuery;
}
Also used : Fuzziness(org.opensearch.common.unit.Fuzziness) ZeroTermsQuery(org.opensearch.index.search.MatchQuery.ZeroTermsQuery) ParsingException(org.opensearch.common.ParsingException) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

Fuzziness (org.opensearch.common.unit.Fuzziness)7 ParsingException (org.opensearch.common.ParsingException)5 XContentParser (org.opensearch.common.xcontent.XContentParser)5 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 LongPoint (org.apache.lucene.document.LongPoint)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Fuzzy (org.opensearch.index.query.IntervalsSourceProvider.Fuzzy)1 MatchQuery (org.opensearch.index.search.MatchQuery)1 ZeroTermsQuery (org.opensearch.index.search.MatchQuery.ZeroTermsQuery)1 MultiMatchQuery (org.opensearch.index.search.MultiMatchQuery)1