当前位置: 首页>>代码示例>>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;未经允许,请勿转载。