• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java AbstractQueryBuilder类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.elasticsearch.index.query.AbstractQueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java AbstractQueryBuilder类的具体用法?Java AbstractQueryBuilder怎么用?Java AbstractQueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

AbstractQueryBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了AbstractQueryBuilder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: assertLuceneQuery

点赞 3

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
/**
 * Checks the result of {@link QueryBuilder#toQuery(QueryShardContext)} given the original {@link QueryBuilder}
 * and {@link QueryShardContext}. Verifies that named queries and boost are properly handled and delegates to
 * {@link #doAssertLuceneQuery(AbstractQueryBuilder, Query, SearchContext)} for query specific checks.
 */
private void assertLuceneQuery(QB queryBuilder, Query query, SearchContext context) throws IOException {
    if (queryBuilder.queryName() != null) {
        Query namedQuery = context.getQueryShardContext().copyNamedQueries().get(queryBuilder.queryName());
        assertThat(namedQuery, equalTo(query));
    }
    if (query != null) {
        if (queryBuilder.boost() != AbstractQueryBuilder.DEFAULT_BOOST) {
            assertThat(query, either(instanceOf(BoostQuery.class)).or(instanceOf(SpanBoostQuery.class)));
            if (query instanceof SpanBoostQuery) {
                SpanBoostQuery spanBoostQuery = (SpanBoostQuery) query;
                assertThat(spanBoostQuery.getBoost(), equalTo(queryBuilder.boost()));
                query = spanBoostQuery.getQuery();
            } else {
                BoostQuery boostQuery = (BoostQuery) query;
                assertThat(boostQuery.getBoost(), equalTo(queryBuilder.boost()));
                query = boostQuery.getQuery();
            }
        }
    }
    doAssertLuceneQuery(queryBuilder, query, context);
}
 

开发者ID:justor,
项目名称:elasticsearch_my,
代码行数:27,
代码来源:AbstractQueryTestCase.java

示例2: phraseBoostTestCaseForClauses

点赞 3

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
private <P extends AbstractQueryBuilder<P>> void
        phraseBoostTestCaseForClauses(String highlighterType, float boost, QueryBuilder terms, P phrase) {
    Matcher<String> highlightedMatcher = Matchers.either(containsString("<em>highlight words together</em>")).or(
            containsString("<em>highlight</em> <em>words</em> <em>together</em>"));
    SearchRequestBuilder search = client().prepareSearch("test").highlighter(
            new HighlightBuilder().field("field1", 100, 1).order("score").highlighterType(highlighterType).requireFieldMatch(true));

    // Try with a bool query
    phrase.boost(boost);
    SearchResponse response = search.setQuery(boolQuery().must(terms).should(phrase)).get();
    assertHighlight(response, 0, "field1", 0, 1, highlightedMatcher);
    phrase.boost(1);
    // Try with a boosting query
    response = search.setQuery(boostingQuery(phrase, terms).boost(boost).negativeBoost(1)).get();
    assertHighlight(response, 0, "field1", 0, 1, highlightedMatcher);
    // Try with a boosting query using a negative boost
    response = search.setQuery(boostingQuery(phrase, terms).boost(1).negativeBoost(1/boost)).get();
    assertHighlight(response, 0, "field1", 0, 1, highlightedMatcher);
}
 

开发者ID:justor,
项目名称:elasticsearch_my,
代码行数:20,
代码来源:HighlighterSearchIT.java

示例3: assertTermOrBoostQuery

点赞 2

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
protected static void assertTermOrBoostQuery(Query query, String field, String value, float fieldBoost) {
    if (fieldBoost != AbstractQueryBuilder.DEFAULT_BOOST) {
        assertThat(query, instanceOf(BoostQuery.class));
        BoostQuery boostQuery = (BoostQuery) query;
        assertThat(boostQuery.getBoost(), equalTo(fieldBoost));
        query = boostQuery.getQuery();
    }
    assertTermQuery(query, field, value);
}
 

开发者ID:justor,
项目名称:elasticsearch_my,
代码行数:10,
代码来源:AbstractQueryTestCase.java

示例4: parseQuery

点赞 2

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
protected QueryBuilder parseQuery(AbstractQueryBuilder<?> builder) throws IOException {
    return parseQuery(createParser(JsonXContent.jsonXContent, builder.buildAsBytes(XContentType.JSON)));
}
 

开发者ID:justor,
项目名称:elasticsearch_my,
代码行数:4,
代码来源:AbstractQueryTestCase.java

示例5: testParseSingleFunction

点赞 2

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
public void testParseSingleFunction() throws IOException {
    String functionScoreQuery = "{\n" +
        "    \"function_score\":{\n" +
        "        \"query\":{\n" +
        "            \"term\":{\n" +
        "                \"field1\":\"value1\"\n" +
        "            }\n" +
        "        },\n" +
        "        \"gauss\":  {\n" +
        "            \"field_name\":  {\n" +
        "                \"origin\":0.5,\n" +
        "                \"scale\":0.6\n" +
        "            }\n" +
        "         },\n" +
        "        \"boost\" : 3,\n" +
        "        \"score_mode\" : \"avg\",\n" +
        "        \"boost_mode\" : \"replace\",\n" +
        "        \"max_boost\" : 10\n" +
        "    }\n" +
        "}";

    QueryBuilder queryBuilder = parseQuery(functionScoreQuery);
    /*
     * given that we copy part of the decay functions as bytes, we test that fromXContent and toXContent both work no matter what the
     * initial format was
     */
    for (int i = 0; i <= XContentType.values().length; i++) {
        assertThat(queryBuilder, instanceOf(FunctionScoreQueryBuilder.class));
        FunctionScoreQueryBuilder functionScoreQueryBuilder = (FunctionScoreQueryBuilder) queryBuilder;
        assertThat(functionScoreQueryBuilder.query(), instanceOf(TermQueryBuilder.class));
        TermQueryBuilder termQueryBuilder = (TermQueryBuilder) functionScoreQueryBuilder.query();
        assertThat(termQueryBuilder.fieldName(), equalTo("field1"));
        assertThat(termQueryBuilder.value(), equalTo("value1"));
        assertThat(functionScoreQueryBuilder.filterFunctionBuilders().length, equalTo(1));
        assertThat(functionScoreQueryBuilder.filterFunctionBuilders()[0].getFilter(), instanceOf(MatchAllQueryBuilder.class));
        assertThat(functionScoreQueryBuilder.filterFunctionBuilders()[0].getScoreFunction(),
                instanceOf(GaussDecayFunctionBuilder.class));
        GaussDecayFunctionBuilder gaussDecayFunctionBuilder = (GaussDecayFunctionBuilder) functionScoreQueryBuilder
                .filterFunctionBuilders()[0].getScoreFunction();
        assertThat(gaussDecayFunctionBuilder.getFieldName(), equalTo("field_name"));
        assertThat(gaussDecayFunctionBuilder.getWeight(), nullValue());
        assertThat(functionScoreQueryBuilder.boost(), equalTo(3f));
        assertThat(functionScoreQueryBuilder.scoreMode(), equalTo(FiltersFunctionScoreQuery.ScoreMode.AVG));
        assertThat(functionScoreQueryBuilder.boostMode(), equalTo(CombineFunction.REPLACE));
        assertThat(functionScoreQueryBuilder.maxBoost(), equalTo(10f));

        if (i < XContentType.values().length) {
            BytesReference bytes = ((AbstractQueryBuilder) queryBuilder).buildAsBytes(XContentType.values()[i]);
            try (XContentParser parser = createParser(XContentType.values()[i].xContent(), bytes)) {
                queryBuilder = parseQuery(parser);
            }
        }
    }
}
 

开发者ID:justor,
项目名称:elasticsearch_my,
代码行数:55,
代码来源:FunctionScoreQueryBuilderTests.java

示例6: fromXContent

点赞 2

import org.elasticsearch.index.query.AbstractQueryBuilder; //导入依赖的package包/类
public static Optional<PhraseCountQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    Object value = null;
    float boost = AbstractQueryBuilder.DEFAULT_BOOST;
    String analyzer = null;
    int slop = MatchQuery.DEFAULT_PHRASE_SLOP;
    boolean inOrder = false;
    boolean weightedCount = false;
    String queryName = null;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (parseContext.isDeprecatedSetting(currentFieldName)) {
            // skip
        } else if (token == XContentParser.Token.START_OBJECT) {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName);
            fieldName = currentFieldName;
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                } else if (token.isValue()) {
                    if (PhraseCountQueryBuilder.QUERY_FIELD.match(currentFieldName)) {
                        value = parser.objectText();
                    } else if (ANALYZER_FIELD.match(currentFieldName)) {
                        analyzer = parser.text();
                    } else if(IN_ORDER_FIELD.match(currentFieldName)) {
                        inOrder = parser.booleanValue();
                    } else if (WEIGHTED_COUNT_FIELD.match(currentFieldName)) {
                        weightedCount = parser.booleanValue();
                    } else if (BOOST_FIELD.match(currentFieldName)) {
                        boost = parser.floatValue();
                    } else if (SLOP_FIELD.match(currentFieldName)) {
                        slop = parser.intValue();
                    } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
                        queryName = parser.text();
                    } else {
                        throw new ParsingException(parser.getTokenLocation(),
                            "[" + NAME + "] query does not support [" + currentFieldName + "]");
                    }
                } else {
                    throw new ParsingException(parser.getTokenLocation(),
                        "[" + NAME + "] unknown token [" + token + "] after [" + currentFieldName + "]");
                }
            }
        } else {
            throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
            fieldName = parser.currentName();
            value = parser.objectText();
        }
    }

    PhraseCountQueryBuilder phraseCountQuery = new PhraseCountQueryBuilder(fieldName, value);
    phraseCountQuery.analyzer(analyzer);
    phraseCountQuery.slop(slop);
    phraseCountQuery.inOrder(inOrder);
    phraseCountQuery.weightedCount(weightedCount);
    phraseCountQuery.queryName(queryName);
    phraseCountQuery.boost(boost);
    return Optional.of(phraseCountQuery);
}
 

开发者ID:cheng-li,
项目名称:pyramid,
代码行数:64,
代码来源:PhraseCountQueryBuilder.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)