if (analyzer == null) {
analyzer = parseContext.mapperService().searchAnalyzer();
}
FuzzyLikeThisQuery query = new FuzzyLikeThisQuery(maxNumTerms, analyzer);
if (fields == null) {
fields = Lists.newArrayList(parseContext.defaultField());
} else if (fields.isEmpty()) {
throw new QueryParsingException(parseContext.index(), "fuzzy_like_this requires 'fields' to be non-empty");
}
for (Iterator<String> it = fields.iterator(); it.hasNext(); ) {
final String fieldName = it.next();
if (!Analysis.generatesCharacterTokenStream(analyzer, fieldName)) {
if (failOnUnsupportedField) {
throw new ElasticsearchIllegalArgumentException("more_like_this doesn't support binary/numeric fields: [" + fieldName + "]");
} else {
it.remove();
}
}
}
if (fields.isEmpty()) {
return null;
}
float minSimilarity = fuzziness.asFloat();
if (minSimilarity >= 1.0f && minSimilarity != (int)minSimilarity) {
throw new ElasticsearchIllegalArgumentException("fractional edit distances are not allowed");
}
if (minSimilarity < 0.0f) {
throw new ElasticsearchIllegalArgumentException("minimumSimilarity cannot be less than 0");
}
for (String field : fields) {
query.addTerms(likeText, field, minSimilarity, prefixLength);
}
query.setBoost(boost);
query.setIgnoreTF(ignoreTF);
if (queryName != null) {
parseContext.addNamedQuery(queryName, query);
}
return query;