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


Java BooleanQuery.Builder方法代码示例

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


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

示例1: combineGrouped

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public Query combineGrouped(List<Query> queries) {
    if (queries == null || queries.isEmpty()) {
        return null;
    }
    if (queries.size() == 1) {
        return queries.get(0);
    }
    if (groupDismax) {
        return new DisjunctionMaxQuery(queries, tieBreaker);
    } else {
        BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
        for (Query query : queries) {
            booleanQuery.add(query, BooleanClause.Occur.SHOULD);
        }
        return booleanQuery.build();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:MultiMatchQueryBuilder.java

示例2: buildMustMatchQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private BooleanQuery buildMustMatchQuery(Map<String,Map<String, Flt>> fieldValues, boolean mustMatch){
    BooleanQuery.Builder qryBuilder = new BooleanQuery.Builder();
    for(Map.Entry<String,Map<String,Flt>> entry: fieldValues.entrySet()){
        String fieldName = entry.getKey();
        for(Map.Entry<String,Flt> fieldValue: entry.getValue().entrySet()){
            String value = fieldValue.getKey();
            TermQuery tq = new TermQuery(new Term(fieldName, value));
            if(mustMatch) {
                qryBuilder.add(tq, BooleanClause.Occur.MUST);
            }
            else{
                qryBuilder.add(tq, BooleanClause.Occur.MUST_NOT);
            }
        }
    }
    return qryBuilder.build();
}
 
开发者ID:DiceTechJobs,项目名称:RelevancyFeedback,代码行数:18,代码来源:RelevancyFeedback.java

示例3: computeQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
/**
 * Creates a {@code BooleanQuery} for loading variations from a lucene index with specified filters
 * @param featureType type of features to find
 * @return a {@code BooleanQuery} to a lucene with specified filters
 */
public BooleanQuery computeQuery(FeatureType featureType) {

    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    addFeatureTypeFilter(featureType, builder);
    addVcfFileFilter(builder);
    addChromosomeFilter(builder);
    addGeneFilter(builder);
    addExonFilter(builder);
    addVariationTypeFilter(builder);
    addFailedFilter(builder);
    addQualityFilter(builder);
    addPositionFilter(builder);
    addAdditionalFilters(builder);
    return builder.build();
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:21,代码来源:VcfFilterForm.java

示例4: newDefaultQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query newDefaultQuery(String text) {
    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    bq.setDisableCoord(true);
    for (Map.Entry<String,Float> entry : weights.entrySet()) {
        try {
            Query q = createBooleanQuery(entry.getKey(), text, super.getDefaultOperator());
            if (q != null) {
                bq.add(wrapWithBoost(q, entry.getValue()), BooleanClause.Occur.SHOULD);
            }
        } catch (RuntimeException e) {
            rethrowUnlessLenient(e);
        }
    }
    return super.simplify(bq.build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SimpleQueryParser.java

示例5: newPhraseQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
@Override
public Query newPhraseQuery(String text, int slop) {
    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    bq.setDisableCoord(true);
    for (Map.Entry<String,Float> entry : weights.entrySet()) {
        try {
            String field = entry.getKey();
            if (settings.quoteFieldSuffix() != null) {
                String quoteField = field + settings.quoteFieldSuffix();
                MappedFieldType quotedFieldType = context.fieldMapper(quoteField);
                if (quotedFieldType != null) {
                    field = quoteField;
                }
            }
            Float boost = entry.getValue();
            Query q = createPhraseQuery(field, text, slop);
            if (q != null) {
                bq.add(wrapWithBoost(q, boost), BooleanClause.Occur.SHOULD);
            }
        } catch (RuntimeException e) {
            rethrowUnlessLenient(e);
        }
    }
    return super.simplify(bq.build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SimpleQueryParser.java

示例6: testExtractQueryMetadata_booleanQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_booleanQuery() {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    builder.add(termQuery1, BooleanClause.Occur.SHOULD);
    PhraseQuery phraseQuery = new PhraseQuery("_field", "_term1", "term2");
    builder.add(phraseQuery, BooleanClause.Occur.SHOULD);

    BooleanQuery.Builder subBuilder = new BooleanQuery.Builder();
    TermQuery termQuery2 = new TermQuery(new Term("_field1", "_term"));
    subBuilder.add(termQuery2, BooleanClause.Occur.MUST);
    TermQuery termQuery3 = new TermQuery(new Term("_field3", "_long_term"));
    subBuilder.add(termQuery3, BooleanClause.Occur.MUST);
    builder.add(subBuilder.build(), BooleanClause.Occur.SHOULD);

    BooleanQuery booleanQuery = builder.build();
    Result result = analyze(booleanQuery);
    assertThat("Should clause with phrase query isn't verified, so entire query can't be verified", result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    Collections.sort(terms);
    assertThat(terms.size(), equalTo(3));
    assertThat(terms.get(0).field(), equalTo(termQuery1.getTerm().field()));
    assertThat(terms.get(0).bytes(), equalTo(termQuery1.getTerm().bytes()));
    assertThat(terms.get(1).field(), equalTo(phraseQuery.getTerms()[0].field()));
    assertThat(terms.get(1).bytes(), equalTo(phraseQuery.getTerms()[0].bytes()));
    assertThat(terms.get(2).field(), equalTo(termQuery3.getTerm().field()));
    assertThat(terms.get(2).bytes(), equalTo(termQuery3.getTerm().bytes()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:QueryAnalyzerTests.java

示例7: testExtractQueryMetadata_booleanQuery_onlyShould

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_booleanQuery_onlyShould() {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term1"));
    builder.add(termQuery1, BooleanClause.Occur.SHOULD);
    TermQuery termQuery2 = new TermQuery(new Term("_field", "_term2"));
    builder.add(termQuery2, BooleanClause.Occur.SHOULD);

    BooleanQuery.Builder subBuilder = new BooleanQuery.Builder();
    TermQuery termQuery3 = new TermQuery(new Term("_field1", "_term"));
    subBuilder.add(termQuery3, BooleanClause.Occur.SHOULD);
    TermQuery termQuery4 = new TermQuery(new Term("_field3", "_long_term"));
    subBuilder.add(termQuery4, BooleanClause.Occur.SHOULD);
    builder.add(subBuilder.build(), BooleanClause.Occur.SHOULD);

    BooleanQuery booleanQuery = builder.build();
    Result result = analyze(booleanQuery);
    assertThat(result.verified, is(true));
    List<Term> terms = new ArrayList<>(result.terms);
    Collections.sort(terms);
    assertThat(terms.size(), equalTo(4));
    assertThat(terms.get(0).field(), equalTo(termQuery1.getTerm().field()));
    assertThat(terms.get(0).bytes(), equalTo(termQuery1.getTerm().bytes()));
    assertThat(terms.get(1).field(), equalTo(termQuery2.getTerm().field()));
    assertThat(terms.get(1).bytes(), equalTo(termQuery2.getTerm().bytes()));
    assertThat(terms.get(2).field(), equalTo(termQuery3.getTerm().field()));
    assertThat(terms.get(2).bytes(), equalTo(termQuery3.getTerm().bytes()));
    assertThat(terms.get(3).field(), equalTo(termQuery4.getTerm().field()));
    assertThat(terms.get(3).bytes(), equalTo(termQuery4.getTerm().bytes()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:QueryAnalyzerTests.java

示例8: testExtractQueryMetadata_booleanQueryWithMustNot

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_booleanQueryWithMustNot() {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    builder.add(termQuery1, BooleanClause.Occur.MUST_NOT);
    PhraseQuery phraseQuery = new PhraseQuery("_field", "_term1", "term2");
    builder.add(phraseQuery, BooleanClause.Occur.SHOULD);

    BooleanQuery booleanQuery = builder.build();
    Result result = analyze(booleanQuery);
    assertThat(result.verified, is(false));
    List<Term> terms = new ArrayList<>(result.terms);
    assertThat(terms.size(), equalTo(1));
    assertThat(terms.get(0).field(), equalTo(phraseQuery.getTerms()[0].field()));
    assertThat(terms.get(0).bytes(), equalTo(phraseQuery.getTerms()[0].bytes()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:QueryAnalyzerTests.java

示例9: testExtractQueryMetadata_unsupportedQuery

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_unsupportedQuery() {
    TermRangeQuery termRangeQuery = new TermRangeQuery("_field", null, null, true, false);
    UnsupportedQueryException e = expectThrows(UnsupportedQueryException.class, () -> analyze(termRangeQuery));
    assertThat(e.getUnsupportedQuery(), sameInstance(termRangeQuery));

    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.SHOULD);
    builder.add(termRangeQuery, BooleanClause.Occur.SHOULD);
    BooleanQuery bq = builder.build();

    e = expectThrows(UnsupportedQueryException.class, () -> analyze(bq));
    assertThat(e.getUnsupportedQuery(), sameInstance(termRangeQuery));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:QueryAnalyzerTests.java

示例10: testExtractQueryMetadata_unsupportedQueryInBoolQueryWithMustClauses

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public void testExtractQueryMetadata_unsupportedQueryInBoolQueryWithMustClauses() {
    TermRangeQuery unsupportedQuery = new TermRangeQuery("_field", null, null, true, false);

    TermQuery termQuery1 = new TermQuery(new Term("_field", "_term"));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    BooleanQuery bq1 = builder.build();

    Result result = analyze(bq1);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, termQuery1.getTerm());

    TermQuery termQuery2 = new TermQuery(new Term("_field", "_longer_term"));
    builder = new BooleanQuery.Builder();
    builder.add(termQuery1, BooleanClause.Occur.MUST);
    builder.add(termQuery2, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    bq1 = builder.build();
    result = analyze(bq1);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, termQuery2.getTerm());

    builder = new BooleanQuery.Builder();
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    builder.add(unsupportedQuery, BooleanClause.Occur.MUST);
    BooleanQuery bq2 = builder.build();
    UnsupportedQueryException e = expectThrows(UnsupportedQueryException.class, () -> analyze(bq2));
    assertThat(e.getUnsupportedQuery(), sameInstance(unsupportedQuery));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:QueryAnalyzerTests.java

示例11: filtered

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
public static BooleanQuery filtered(@Nullable Query query, @Nullable Query filter) {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    if (query != null) {
        builder.add(new BooleanClause(query, Occur.MUST));
    }
    if (filter != null) {
        builder.add(new BooleanClause(filter, Occur.FILTER));
    }
    return builder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:Queries.java

示例12: addVariationTypeFilter

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private void addVariationTypeFilter(BooleanQuery.Builder builder) {
    if (variationTypes != null && !variationTypes.field.isEmpty()) {
        BooleanQuery.Builder typesBuilder = new BooleanQuery.Builder();
        for (int i = 0; i < variationTypes.field.size(); i++) {
            TermQuery termQuery = new TermQuery(new Term(FeatureIndexFields.VARIATION_TYPE.getFieldName(),
                    variationTypes.field.get(i).toString().toLowerCase()));
            typesBuilder.add(termQuery, variationTypes.conjunction ? BooleanClause.Occur.MUST :
                    BooleanClause.Occur.SHOULD);
        }

        builder.add(typesBuilder.build(), BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:14,代码来源:VcfFilterForm.java

示例13: handleExclude

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private static void handleExclude(BooleanQuery.Builder boolQuery, Item[] likeItems) {
    // artificial docs get assigned a random id and should be disregarded
    List<BytesRef> uids = new ArrayList<>();
    for (Item item : likeItems) {
        if (item.doc() != null) {
            continue;
        }
        uids.add(createUidAsBytes(item.type(), item.id()));
    }
    if (!uids.isEmpty()) {
        TermInSetQuery query = new TermInSetQuery(UidFieldMapper.NAME, uids.toArray(new BytesRef[uids.size()]));
        boolQuery.add(query, BooleanClause.Occur.MUST_NOT);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:MoreLikeThisQueryBuilder.java

示例14: addVcfFileFilter

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private void addVcfFileFilter(BooleanQuery.Builder builder) {
    if (vcfFileIds != null && !vcfFileIds.isEmpty()) {
        List<Term> terms = vcfFileIds.stream()
                .map(vcfFileId -> new Term(FeatureIndexFields.FILE_ID.getFieldName(), vcfFileId.toString()))
                .collect(Collectors.toList());
        TermsQuery termsQuery = new TermsQuery(terms);
        builder.add(termsQuery, BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:10,代码来源:VcfFilterForm.java

示例15: tryAddIntegralKeyValueFilter

import org.apache.lucene.search.BooleanQuery; //导入方法依赖的package包/类
private void tryAddIntegralKeyValueFilter(BooleanQuery.Builder builder,
        Map.Entry<String, Object> entry, String key, List list, Object val) {
    if (val instanceof Integer || entry.getValue() instanceof Long) {
        builder.add(IntPoint.newRangeQuery(key,
                list.get(0) != null ? (Integer) list.get(0) : Integer.MIN_VALUE,
                list.get(1) != null ? (Integer) list.get(1) : Integer.MAX_VALUE),
                BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:10,代码来源:VcfFilterForm.java


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