Search in sources :

Example 1 with MultiMatchQuery

use of org.elasticsearch.index.search.MultiMatchQuery in project crate by crate.

the class MatchQueries method multiMatch.

public static Query multiMatch(QueryShardContext queryShardContext, @Nullable String matchType, Map<String, Float> fieldNames, String queryString, Map<String, Object> options) {
    MultiMatchQueryType type = MatchQueries.getType(matchType);
    ParsedOptions parsedOptions = OptionParser.parse(type, options);
    MultiMatchQuery multiMatchQuery = new MultiMatchQuery(queryShardContext);
    Float tieBreaker = parsedOptions.tieBreaker();
    if (tieBreaker != null) {
        multiMatchQuery.setTieBreaker(tieBreaker);
    }
    String analyzer = parsedOptions.analyzer();
    if (analyzer != null) {
        multiMatchQuery.setAnalyzer(analyzer);
    }
    multiMatchQuery.setCommonTermsCutoff(parsedOptions.commonTermsCutoff());
    multiMatchQuery.setFuzziness(parsedOptions.fuzziness());
    multiMatchQuery.setFuzzyPrefixLength(parsedOptions.prefixLength());
    multiMatchQuery.setFuzzyRewriteMethod(parsedOptions.rewriteMethod());
    multiMatchQuery.setMaxExpansions(parsedOptions.maxExpansions());
    multiMatchQuery.setPhraseSlop(parsedOptions.phraseSlop());
    multiMatchQuery.setTranspositions(parsedOptions.transpositions());
    multiMatchQuery.setZeroTermsQuery(parsedOptions.zeroTermsQuery());
    multiMatchQuery.setOccur(parsedOptions.operator());
    return multiMatchQuery.parse(type, fieldNames, queryString, parsedOptions.minimumShouldMatch());
}
Also used : MultiMatchQuery(org.elasticsearch.index.search.MultiMatchQuery) MultiMatchQueryType(org.elasticsearch.index.query.MultiMatchQueryType)

Example 2 with MultiMatchQuery

use of org.elasticsearch.index.search.MultiMatchQuery in project elasticsearch by elastic.

the class MultiMatchQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    MultiMatchQuery multiMatchQuery = new MultiMatchQuery(context);
    if (analyzer != null) {
        if (context.getIndexAnalyzers().get(analyzer) == null) {
            throw new QueryShardException(context, "[" + NAME + "] analyzer [" + analyzer + "] not found");
        }
        multiMatchQuery.setAnalyzer(analyzer);
    }
    multiMatchQuery.setPhraseSlop(slop);
    if (fuzziness != null) {
        multiMatchQuery.setFuzziness(fuzziness);
    }
    multiMatchQuery.setFuzzyPrefixLength(prefixLength);
    multiMatchQuery.setMaxExpansions(maxExpansions);
    multiMatchQuery.setOccur(operator.toBooleanClauseOccur());
    if (fuzzyRewrite != null) {
        multiMatchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(fuzzyRewrite, null));
    }
    if (tieBreaker != null) {
        multiMatchQuery.setTieBreaker(tieBreaker);
    }
    if (cutoffFrequency != null) {
        multiMatchQuery.setCommonTermsCutoff(cutoffFrequency);
    }
    multiMatchQuery.setLenient(lenient);
    multiMatchQuery.setZeroTermsQuery(zeroTermsQuery);
    if (useDisMax != null) {
        // backwards foobar
        boolean typeUsesDismax = type.tieBreaker() != 1.0f;
        if (typeUsesDismax != useDisMax) {
            if (useDisMax && tieBreaker == null) {
                multiMatchQuery.setTieBreaker(0.0f);
            } else {
                multiMatchQuery.setTieBreaker(1.0f);
            }
        }
    }
    Map<String, Float> newFieldsBoosts = handleFieldsMatchPattern(context.getMapperService(), fieldsBoosts);
    return multiMatchQuery.parse(type, newFieldsBoosts, value, minimumShouldMatch);
}
Also used : MultiMatchQuery(org.elasticsearch.index.search.MultiMatchQuery)

Aggregations

MultiMatchQuery (org.elasticsearch.index.search.MultiMatchQuery)2 MultiMatchQueryType (org.elasticsearch.index.query.MultiMatchQueryType)1