use of org.opensearch.index.search.MultiMatchQuery in project OpenSearch by opensearch-project.
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, LoggingDeprecationHandler.INSTANCE));
}
if (tieBreaker != null) {
multiMatchQuery.setTieBreaker(tieBreaker);
}
if (cutoffFrequency != null) {
multiMatchQuery.setCommonTermsCutoff(cutoffFrequency);
}
if (lenient != null) {
multiMatchQuery.setLenient(lenient);
}
multiMatchQuery.setZeroTermsQuery(zeroTermsQuery);
multiMatchQuery.setAutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery);
multiMatchQuery.setTranspositions(fuzzyTranspositions);
Map<String, Float> newFieldsBoosts;
boolean isAllField;
if (fieldsBoosts.isEmpty()) {
// no fields provided, defaults to index.query.default_field
List<String> defaultFields = context.defaultFields();
newFieldsBoosts = QueryParserHelper.resolveMappingFields(context, QueryParserHelper.parseFieldsAndWeights(defaultFields));
isAllField = QueryParserHelper.hasAllFieldsWildcard(defaultFields);
} else {
newFieldsBoosts = QueryParserHelper.resolveMappingFields(context, fieldsBoosts);
isAllField = QueryParserHelper.hasAllFieldsWildcard(fieldsBoosts.keySet());
}
if (isAllField && lenient == null) {
// Sets leniency to true if not explicitly
// set in the request
multiMatchQuery.setLenient(true);
}
return multiMatchQuery.parse(type, newFieldsBoosts, value, minimumShouldMatch);
}
Aggregations