Java Code Examples for org.elasticsearch.index.search.MatchQuery#Type

The following examples show how to use org.elasticsearch.index.search.MatchQuery#Type . 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: MatchQueries.java    From crate with Apache License 2.0 6 votes vote down vote up
public static Query singleMatch(QueryShardContext queryShardContext,
                                String fieldName,
                                String queryString,
                                @Nullable String matchType,
                                @Nullable Map<String, Object> options) throws IOException {
    MultiMatchQueryType type = getType(matchType);
    ParsedOptions parsedOptions = OptionParser.parse(type, options);

    MatchQuery matchQuery = new MatchQuery(queryShardContext);

    if (parsedOptions.analyzer() != null) {
        matchQuery.setAnalyzer(parsedOptions.analyzer());
    }
    matchQuery.setCommonTermsCutoff(parsedOptions.commonTermsCutoff());
    matchQuery.setFuzziness(parsedOptions.fuzziness());
    matchQuery.setFuzzyPrefixLength(parsedOptions.prefixLength());
    matchQuery.setFuzzyRewriteMethod(parsedOptions.rewriteMethod());
    matchQuery.setMaxExpansions(parsedOptions.maxExpansions());
    matchQuery.setPhraseSlop(parsedOptions.phraseSlop());
    matchQuery.setTranspositions(parsedOptions.transpositions());
    matchQuery.setZeroTermsQuery(parsedOptions.zeroTermsQuery());
    matchQuery.setOccur(parsedOptions.operator());

    MatchQuery.Type matchQueryType = type.matchQueryType();
    return matchQuery.parse(matchQueryType, fieldName, queryString);
}
 
Example 2
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 3
Source File: MatchQueryBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
protected Query singleQuery(MatchQuery.Type type, String fieldName, BytesRef queryString) {
    String field;
    MappedFieldType fieldType = mapperService.smartNameFieldType(fieldName);
    if (fieldType == null) {
        field = fieldName;
    } else {
        field = fieldType.names().indexName();
    }

    if (fieldType != null && fieldType.useTermQueryWithQueryString() && !forceAnalyzeQueryString()) {
        try {
           return fieldType.termQuery(queryString, null);
        } catch (RuntimeException e) {
            return null;
        }
    }

    Analyzer analyzer = getAnalyzer(fieldType);
    InnerQueryBuilder builder = new InnerQueryBuilder(analyzer, fieldType);

    Query query;
    switch (type) {
        case BOOLEAN:
            if (options.commonTermsCutoff() == null) {
                query = builder.createBooleanQuery(field, BytesRefs.toString(queryString), options.operator());
            } else {
                query = builder.createCommonTermsQuery(
                        field,
                        BytesRefs.toString(queryString),
                        options.operator(),
                        options.operator(),
                        options.commonTermsCutoff(),
                        fieldType
                );
            }
            break;
        case PHRASE:
            query = builder.createPhraseQuery(field, BytesRefs.toString(queryString), options.phraseSlop());
            break;
        case PHRASE_PREFIX:
            query = builder.createPhrasePrefixQuery(
                    field,
                    BytesRefs.toString(queryString),
                    options.phraseSlop(),
                    options.maxExpansions()
            );
            break;
        default:
            throw new IllegalArgumentException("invalid type: " + type.toString());
    }

    if (query == null) {
        return zeroTermsQuery();
    } else {
        return query;
    }
}
 
Example 4
Source File: MultiMatchQueryBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
Type (MatchQuery.Type matchQueryType, float tieBreaker, ParseField parseField) {
    this.matchQueryType = matchQueryType;
    this.tieBreaker = tieBreaker;
    this.parseField = parseField;
}
 
Example 5
Source File: MultiMatchQueryBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public MatchQuery.Type matchQueryType() {
    return matchQueryType;
}