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