Java 类org.elasticsearch.index.query.support.QueryParsers 实例源码

项目:elasticsearch_my    文件:MatchQueryBuilder.java   
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    // validate context specific fields
    if (analyzer != null && context.getIndexAnalyzers().get(analyzer) == null) {
        throw new QueryShardException(context, "[" + NAME + "] analyzer [" + analyzer + "] not found");
    }

    MatchQuery matchQuery = new MatchQuery(context);
    matchQuery.setOccur(operator.toBooleanClauseOccur());
    matchQuery.setAnalyzer(analyzer);
    matchQuery.setPhraseSlop(slop);
    matchQuery.setFuzziness(fuzziness);
    matchQuery.setFuzzyPrefixLength(prefixLength);
    matchQuery.setMaxExpansions(maxExpansions);
    matchQuery.setTranspositions(fuzzyTranspositions);
    matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(fuzzyRewrite, null));
    matchQuery.setLenient(lenient);
    matchQuery.setCommonTermsCutoff(cutoffFrequency);
    matchQuery.setZeroTermsQuery(zeroTermsQuery);

    Query query = matchQuery.parse(type, fieldName, value);
    return Queries.maybeApplyMinimumShouldMatch(query, minimumShouldMatch);
}
项目:elasticsearch_my    文件:AbstractQueryTestCase.java   
/**
 * Helper method to return a random rewrite method
 */
protected static String getRandomRewriteMethod() {
    String rewrite;
    if (randomBoolean()) {
        rewrite = randomFrom(QueryParsers.CONSTANT_SCORE,
                QueryParsers.SCORING_BOOLEAN,
                QueryParsers.CONSTANT_SCORE_BOOLEAN).getPreferredName();
    } else {
        rewrite = randomFrom(QueryParsers.TOP_TERMS,
                QueryParsers.TOP_TERMS_BOOST,
                QueryParsers.TOP_TERMS_BLENDED_FREQS).getPreferredName() + "1";
    }
    return rewrite;
}
项目:elasticsearch_my    文件:MapperQueryParser.java   
@Override
protected Query newFuzzyQuery(Term term, float minimumSimilarity, int prefixLength) {
    String text = term.text();
    int numEdits = FuzzyQuery.floatToEdits(minimumSimilarity, text.codePointCount(0, text.length()));
    FuzzyQuery query = new FuzzyQuery(term, numEdits, prefixLength,
        settings.fuzzyMaxExpansions(), FuzzyQuery.defaultTranspositions);
    QueryParsers.setRewriteMethod(query, settings.fuzzyRewriteMethod());
    return query;
}
项目:Elasticsearch    文件:MapperQueryParser.java   
@Override
protected Query newFuzzyQuery(Term term, float minimumSimilarity, int prefixLength) {
    String text = term.text();
    int numEdits = FuzzyQuery.floatToEdits(minimumSimilarity, text.codePointCount(0, text.length()));
    FuzzyQuery query = new FuzzyQuery(term, numEdits, prefixLength, settings.fuzzyMaxExpansions(), FuzzyQuery.defaultTranspositions);
    QueryParsers.setRewriteMethod(query, settings.fuzzyRewriteMethod());
    return query;
}
项目:elasticsearch_my    文件:MultiMatchQueryBuilder.java   
@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);
}