當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。