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


Java BooleanClause.getQuery方法代码示例

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


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

示例1: testMinShouldMatchFilterWithoutShouldClauses

import org.apache.lucene.search.BooleanClause; //导入方法依赖的package包/类
public void testMinShouldMatchFilterWithoutShouldClauses() throws Exception {
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.filter(new BoolQueryBuilder().must(new MatchAllQueryBuilder()));
    Query query = boolQueryBuilder.toQuery(createShardContext());
    assertThat(query, instanceOf(BooleanQuery.class));
    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertThat(booleanQuery.getMinimumNumberShouldMatch(), equalTo(0));
    assertThat(booleanQuery.clauses().size(), equalTo(1));
    BooleanClause booleanClause = booleanQuery.clauses().get(0);
    assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.FILTER));
    assertThat(booleanClause.getQuery(), instanceOf(BooleanQuery.class));
    BooleanQuery innerBooleanQuery = (BooleanQuery) booleanClause.getQuery();
    //we didn't set minimum should match initially, there are no should clauses so it should be 0
    assertThat(innerBooleanQuery.getMinimumNumberShouldMatch(), equalTo(0));
    assertThat(innerBooleanQuery.clauses().size(), equalTo(1));
    BooleanClause innerBooleanClause = innerBooleanQuery.clauses().get(0);
    assertThat(innerBooleanClause.getOccur(), equalTo(BooleanClause.Occur.MUST));
    assertThat(innerBooleanClause.getQuery(), instanceOf(MatchAllDocsQuery.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:BoolQueryBuilderTests.java

示例2: testMinShouldMatchFilterWithShouldClauses

import org.apache.lucene.search.BooleanClause; //导入方法依赖的package包/类
public void testMinShouldMatchFilterWithShouldClauses() throws Exception {
    BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
    boolQueryBuilder.filter(new BoolQueryBuilder().must(new MatchAllQueryBuilder()).should(new MatchAllQueryBuilder()));
    Query query = boolQueryBuilder.toQuery(createShardContext());
    assertThat(query, instanceOf(BooleanQuery.class));
    BooleanQuery booleanQuery = (BooleanQuery) query;
    assertThat(booleanQuery.getMinimumNumberShouldMatch(), equalTo(0));
    assertThat(booleanQuery.clauses().size(), equalTo(1));
    BooleanClause booleanClause = booleanQuery.clauses().get(0);
    assertThat(booleanClause.getOccur(), equalTo(BooleanClause.Occur.FILTER));
    assertThat(booleanClause.getQuery(), instanceOf(BooleanQuery.class));
    BooleanQuery innerBooleanQuery = (BooleanQuery) booleanClause.getQuery();
    //we didn't set minimum should match initially, but there are should clauses so it should be 1
    assertThat(innerBooleanQuery.getMinimumNumberShouldMatch(), equalTo(1));
    assertThat(innerBooleanQuery.clauses().size(), equalTo(2));
    BooleanClause innerBooleanClause1 = innerBooleanQuery.clauses().get(0);
    assertThat(innerBooleanClause1.getOccur(), equalTo(BooleanClause.Occur.MUST));
    assertThat(innerBooleanClause1.getQuery(), instanceOf(MatchAllDocsQuery.class));
    BooleanClause innerBooleanClause2 = innerBooleanQuery.clauses().get(1);
    assertThat(innerBooleanClause2.getOccur(), equalTo(BooleanClause.Occur.SHOULD));
    assertThat(innerBooleanClause2.getQuery(), instanceOf(MatchAllDocsQuery.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BoolQueryBuilderTests.java

示例3: attach

import org.apache.lucene.search.BooleanClause; //导入方法依赖的package包/类
private static void attach (final BooleanQuery query, final TermCollector collector) {
    for (BooleanClause clause : query.getClauses()) {
        final Query q = clause.getQuery();
        if (!(q instanceof TermCollector.TermCollecting)) {
            throw new IllegalArgumentException();
        }
        ((TermCollector.TermCollecting)q).attach(collector);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Queries.java

示例4: boolToExtendedCommonTermsQuery

import org.apache.lucene.search.BooleanClause; //导入方法依赖的package包/类
private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, Occur highFreqOccur, Occur lowFreqOccur, float
    maxTermFrequency, MappedFieldType fieldType) {
    ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency,
        bq.isCoordDisabled(), fieldType);
    for (BooleanClause clause : bq.clauses()) {
        if (!(clause.getQuery() instanceof TermQuery)) {
            return bq;
        }
        query.add(((TermQuery) clause.getQuery()).getTerm());
    }
    return query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:MatchQuery.java


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