當前位置: 首頁>>代碼示例>>Java>>正文


Java BooleanQuery.clauses方法代碼示例

本文整理匯總了Java中org.apache.lucene.search.BooleanQuery.clauses方法的典型用法代碼示例。如果您正苦於以下問題:Java BooleanQuery.clauses方法的具體用法?Java BooleanQuery.clauses怎麽用?Java BooleanQuery.clauses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.search.BooleanQuery的用法示例。


在下文中一共展示了BooleanQuery.clauses方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyMinimumShouldMatch

import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
    if (minimumShouldMatch == null) {
        return query;
    }
    int optionalClauses = 0;
    for (BooleanClause c : query.clauses()) {
        if (c.getOccur() == BooleanClause.Occur.SHOULD) {
            optionalClauses++;
        }
    }

    int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
    if (0 < msm) {
        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.setDisableCoord(query.isCoordDisabled());
        for (BooleanClause clause : query) {
            builder.add(clause);
        }
        builder.setMinimumNumberShouldMatch(msm);
        return builder.build();
    } else {
        return query;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:Queries.java

示例2: boolToExtendedCommonTermsQuery

import org.apache.lucene.search.BooleanQuery; //導入方法依賴的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

示例3: shouldClauses

import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
private static int shouldClauses(BooleanQuery query) {
    int result = 0;
    for (BooleanClause c : query.clauses()) {
        if (c.getOccur() == BooleanClause.Occur.SHOULD) {
            result++;
        }
    }
    return result;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:10,代碼來源:SimpleQueryStringBuilderTests.java

示例4: doAssertLuceneQuery

import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
@Override
protected void doAssertLuceneQuery(BoolQueryBuilder queryBuilder, Query query, SearchContext searchContext) throws IOException {
    if (!queryBuilder.hasClauses()) {
        assertThat(query, instanceOf(MatchAllDocsQuery.class));
    } else {
        QueryShardContext context = searchContext.getQueryShardContext();
        List<BooleanClause> clauses = new ArrayList<>();
        clauses.addAll(getBooleanClauses(queryBuilder.must(), BooleanClause.Occur.MUST, context));
        clauses.addAll(getBooleanClauses(queryBuilder.mustNot(), BooleanClause.Occur.MUST_NOT, context));
        clauses.addAll(getBooleanClauses(queryBuilder.should(), BooleanClause.Occur.SHOULD, context));
        clauses.addAll(getBooleanClauses(queryBuilder.filter(), BooleanClause.Occur.FILTER, context));

        if (clauses.isEmpty()) {
            assertThat(query, instanceOf(MatchAllDocsQuery.class));
        } else {
            assertThat(query, instanceOf(BooleanQuery.class));
            BooleanQuery booleanQuery = (BooleanQuery) query;
            assertThat(booleanQuery.isCoordDisabled(), equalTo(queryBuilder.disableCoord()));
            if (queryBuilder.adjustPureNegative()) {
                boolean isNegative = true;
                for (BooleanClause clause : clauses) {
                    if (clause.isProhibited() == false) {
                        isNegative = false;
                        break;
                    }
                }
                if (isNegative) {
                    clauses.add(new BooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST));
                }
            }
            assertThat(booleanQuery.clauses().size(), equalTo(clauses.size()));
            Iterator<BooleanClause> clauseIterator = clauses.iterator();
            for (BooleanClause booleanClause : booleanQuery.clauses()) {
                assertThat(booleanClause, instanceOf(clauseIterator.next().getClass()));
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:39,代碼來源:BoolQueryBuilderTests.java


注:本文中的org.apache.lucene.search.BooleanQuery.clauses方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。