Java Code Examples for org.elasticsearch.common.lucene.search.Queries#applyMinimumShouldMatch()

The following examples show how to use org.elasticsearch.common.lucene.search.Queries#applyMinimumShouldMatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatchQueryBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected Query singleQueryAndApply(MatchQuery.Type type,
                                    String fieldName,
                                    BytesRef queryString,
                                    Float boost) {
    Query query = singleQuery(type, fieldName, queryString);
    if (query instanceof BooleanQuery) {
        Queries.applyMinimumShouldMatch((BooleanQuery) query, options.minimumShouldMatch());
    }
    if (boost != null && query != null) {
        query.setBoost(boost);
    }
    return query;
}
 
Example 2
Source File: MultiMatchQuery.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
    Query query = parse(type, fieldName, value);
    // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
    // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
    // and multiple variations of the same word in the query (synonyms for instance).
    if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
        query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
    }
    if (boostValue != null && query != null) {
        query.setBoost(boostValue);
    }
    return query;
}