当前位置: 首页>>代码示例>>Java>>正文


Java BoostQuery.getQuery方法代码示例

本文整理汇总了Java中org.apache.lucene.search.BoostQuery.getQuery方法的典型用法代码示例。如果您正苦于以下问题:Java BoostQuery.getQuery方法的具体用法?Java BoostQuery.getQuery怎么用?Java BoostQuery.getQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.BoostQuery的用法示例。


在下文中一共展示了BoostQuery.getQuery方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertLuceneQuery

import org.apache.lucene.search.BoostQuery; //导入方法依赖的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: testToQueryWithStringField

import org.apache.lucene.search.BoostQuery; //导入方法依赖的package包/类
public void testToQueryWithStringField() throws IOException {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    String query = "{\n" +
            "    \"fuzzy\":{\n" +
            "        \"" + STRING_FIELD_NAME + "\":{\n" +
            "            \"value\":\"sh\",\n" +
            "            \"fuzziness\": \"AUTO\",\n" +
            "            \"prefix_length\":1,\n" +
            "            \"boost\":2.0\n" +
            "        }\n" +
            "    }\n" +
            "}";
    Query parsedQuery = parseQuery(query).toQuery(createShardContext());
    assertThat(parsedQuery, instanceOf(BoostQuery.class));
    BoostQuery boostQuery = (BoostQuery) parsedQuery;
    assertThat(boostQuery.getBoost(), equalTo(2.0f));
    assertThat(boostQuery.getQuery(), instanceOf(FuzzyQuery.class));
    FuzzyQuery fuzzyQuery = (FuzzyQuery) boostQuery.getQuery();
    assertThat(fuzzyQuery.getTerm(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
    assertThat(fuzzyQuery.getMaxEdits(), equalTo(Fuzziness.AUTO.asDistance("sh")));
    assertThat(fuzzyQuery.getPrefixLength(), equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:FuzzyQueryBuilderTests.java

示例3: testToQueryPhraseQueryBoostAndSlop

import org.apache.lucene.search.BoostQuery; //导入方法依赖的package包/类
public void testToQueryPhraseQueryBoostAndSlop() throws IOException {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    QueryStringQueryBuilder queryStringQueryBuilder =
        new QueryStringQueryBuilder("\"test phrase\"~2").field(STRING_FIELD_NAME, 5f);
    Query query = queryStringQueryBuilder.toQuery(createShardContext());
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
    DisjunctionMaxQuery disjunctionMaxQuery = (DisjunctionMaxQuery) query;
    assertThat(disjunctionMaxQuery.getDisjuncts().size(), equalTo(1));
    assertThat(disjunctionMaxQuery.getDisjuncts().get(0), instanceOf(BoostQuery.class));
    BoostQuery boostQuery = (BoostQuery) disjunctionMaxQuery.getDisjuncts().get(0);
    assertThat(boostQuery.getBoost(), equalTo(5f));
    assertThat(boostQuery.getQuery(), instanceOf(PhraseQuery.class));
    PhraseQuery phraseQuery = (PhraseQuery) boostQuery.getQuery();
    assertThat(phraseQuery.getSlop(), Matchers.equalTo(2));
    assertThat(phraseQuery.getTerms().length, equalTo(2));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:QueryStringQueryBuilderTests.java

示例4: assertTermOrBoostQuery

import org.apache.lucene.search.BoostQuery; //导入方法依赖的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

示例5: testToQueryBooleanQueryMultipleBoosts

import org.apache.lucene.search.BoostQuery; //导入方法依赖的package包/类
public void testToQueryBooleanQueryMultipleBoosts() throws Exception {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    int numBoosts = randomIntBetween(2, 10);
    float[] boosts = new float[numBoosts + 1];
    String queryStringPrefix = "";
    String queryStringSuffix = "";
    for (int i = 0; i < boosts.length - 1; i++) {
        float boost = 2.0f / randomIntBetween(3, 20);
        boosts[i] = boost;
        queryStringPrefix += "(";
        queryStringSuffix += ")^" + boost;
    }
    String queryString = queryStringPrefix + "foo bar" + queryStringSuffix;

    float mainBoost = 2.0f / randomIntBetween(3, 20);
    boosts[boosts.length - 1] = mainBoost;
    QueryStringQueryBuilder queryStringQueryBuilder =
        new QueryStringQueryBuilder(queryString).field(STRING_FIELD_NAME)
            .minimumShouldMatch("2").boost(mainBoost);
    Query query = queryStringQueryBuilder.toQuery(createShardContext());

    for (int i = boosts.length - 1; i >= 0; i--) {
        assertThat(query, instanceOf(BoostQuery.class));
        BoostQuery boostQuery = (BoostQuery) query;
        assertThat(boostQuery.getBoost(), equalTo(boosts[i]));
        query = boostQuery.getQuery();
    }

    assertThat(query, instanceOf(BooleanQuery.class));
    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertThat(booleanQuery.getMinimumNumberShouldMatch(), equalTo(2));
    assertThat(booleanQuery.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.SHOULD));
    assertThat(booleanQuery.clauses().get(0).getQuery(),
        equalTo(new TermQuery(new Term(STRING_FIELD_NAME, "foo"))));
    assertThat(booleanQuery.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.SHOULD));
    assertThat(booleanQuery.clauses().get(1).getQuery(),
        equalTo(new TermQuery(new Term(STRING_FIELD_NAME, "bar"))));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:QueryStringQueryBuilderTests.java

示例6: testToQueryInnerPrefixQuery

import org.apache.lucene.search.BoostQuery; //导入方法依赖的package包/类
public void testToQueryInnerPrefixQuery() throws Exception {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    String queryAsString = "{\n" +
            "    \"dis_max\":{\n" +
            "        \"queries\":[\n" +
            "            {\n" +
            "                \"prefix\":{\n" +
            "                    \"" + STRING_FIELD_NAME + "\":{\n" +
            "                        \"value\":\"sh\",\n" +
            "                        \"boost\":1.2\n" +
            "                    }\n" +
            "                }\n" +
            "            }\n" +
            "        ]\n" +
            "    }\n" +
            "}";
    Query query = parseQuery(queryAsString).toQuery(createShardContext());
    assertThat(query, instanceOf(DisjunctionMaxQuery.class));
    DisjunctionMaxQuery disjunctionMaxQuery = (DisjunctionMaxQuery) query;

    List<Query> disjuncts = disjunctionMaxQuery.getDisjuncts();
    assertThat(disjuncts.size(), equalTo(1));

    assertThat(disjuncts.get(0), instanceOf(BoostQuery.class));
    BoostQuery boostQuery = (BoostQuery) disjuncts.get(0);
    assertThat((double) boostQuery.getBoost(), closeTo(1.2, 0.00001));
    assertThat(boostQuery.getQuery(), instanceOf(PrefixQuery.class));
    PrefixQuery firstQ = (PrefixQuery) boostQuery.getQuery();
    // since age is automatically registered in data, we encode it as numeric
    assertThat(firstQ.getPrefix(), equalTo(new Term(STRING_FIELD_NAME, "sh")));

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

示例7: flatten

import org.apache.lucene.search.BoostQuery; //导入方法依赖的package包/类
@Override
void flatten(Query sourceQuery, IndexReader reader, Collection<Query> flatQueries, float boost) throws IOException {
    if (sourceQuery instanceof BoostQuery) {
        BoostQuery bq = (BoostQuery) sourceQuery;
        sourceQuery = bq.getQuery();
        boost *= bq.getBoost();
        flatten(sourceQuery, reader, flatQueries, boost);
    } else if (sourceQuery instanceof SpanTermQuery) {
        super.flatten(new TermQuery(((SpanTermQuery) sourceQuery).getTerm()), reader, flatQueries, boost);
    } else if (sourceQuery instanceof ConstantScoreQuery) {
        flatten(((ConstantScoreQuery) sourceQuery).getQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FunctionScoreQuery) {
        flatten(((FunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhrasePrefixQuery) {
        flatten(sourceQuery.rewrite(reader), reader, flatQueries, boost);
    } else if (sourceQuery instanceof FiltersFunctionScoreQuery) {
        flatten(((FiltersFunctionScoreQuery) sourceQuery).getSubQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof MultiPhraseQuery) {
        MultiPhraseQuery q = ((MultiPhraseQuery) sourceQuery);
        convertMultiPhraseQuery(0, new int[q.getTermArrays().length], q, q.getTermArrays(), q.getPositions(), reader, flatQueries);
    } else if (sourceQuery instanceof BlendedTermQuery) {
        final BlendedTermQuery blendedTermQuery = (BlendedTermQuery) sourceQuery;
        flatten(blendedTermQuery.rewrite(reader), reader, flatQueries, boost);
    } else if (sourceQuery instanceof ESToParentBlockJoinQuery) {
        ESToParentBlockJoinQuery blockJoinQuery = (ESToParentBlockJoinQuery) sourceQuery;
        flatten(blockJoinQuery.getChildQuery(), reader, flatQueries, boost);
    } else if (sourceQuery instanceof BoostingQuery) {
        BoostingQuery boostingQuery = (BoostingQuery) sourceQuery;
        //flatten positive query with query boost
        flatten(boostingQuery.getMatch(), reader, flatQueries, boost);
        //flatten negative query with negative boost
        flatten(boostingQuery.getContext(), reader, flatQueries, boostingQuery.getBoost());
    } else if (sourceQuery instanceof SynonymQuery) {
        // SynonymQuery should be handled by the parent class directly.
        // This statement should be removed when https://issues.apache.org/jira/browse/LUCENE-7484 is merged.
        SynonymQuery synQuery = (SynonymQuery) sourceQuery;
        for (Term term : synQuery.getTerms()) {
            flatten(new TermQuery(term), reader, flatQueries, boost);
        }
    } else {
        super.flatten(sourceQuery, reader, flatQueries, boost);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:CustomFieldQuery.java


注:本文中的org.apache.lucene.search.BoostQuery.getQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。