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


Java BlendedTermQuery.booleanBlendedQuery方法代碼示例

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


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

示例1: testBlendTermsUnsupportedValue

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testBlendTermsUnsupportedValue() {
    FakeFieldType ft1 = new FakeFieldType();
    ft1.setName("foo");
    FakeFieldType ft2 = new FakeFieldType() {
        @Override
        public Query termQuery(Object value, QueryShardContext context) {
            throw new IllegalArgumentException();
        }
    };
    ft2.setName("bar");
    Term[] terms = new Term[] { new Term("foo", "baz") };
    float[] boosts = new float[] {2};
    Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
    Query actual = MultiMatchQuery.blendTerm(
            indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
            new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
    assertEquals(expected, actual);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:MultiMatchQueryTests.java

示例2: testBlendNoTermQuery

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testBlendNoTermQuery() {
    FakeFieldType ft1 = new FakeFieldType();
    ft1.setName("foo");
    FakeFieldType ft2 = new FakeFieldType() {
        @Override
        public Query termQuery(Object value, QueryShardContext context) {
            return new MatchAllDocsQuery();
        }
    };
    ft2.setName("bar");
    Term[] terms = new Term[] { new Term("foo", "baz") };
    float[] boosts = new float[] {2};
    Query expectedClause1 = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
    Query expectedClause2 = new BoostQuery(new MatchAllDocsQuery(), 3);
    Query expected = new BooleanQuery.Builder().setDisableCoord(true)
            .add(expectedClause1, Occur.SHOULD)
            .add(expectedClause2, Occur.SHOULD)
            .build();
    Query actual = MultiMatchQuery.blendTerm(
            indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
            new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
    assertEquals(expected, actual);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:MultiMatchQueryTests.java

示例3: blendTerm

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public Query blendTerm(Term term, MappedFieldType fieldType) {
    if (blendedFields == null) {
        return super.blendTerm(term, fieldType);
    }
    final Term[] terms = new Term[blendedFields.length];
    float[] blendedBoost = new float[blendedFields.length];
    for (int i = 0; i < blendedFields.length; i++) {
        terms[i] = blendedFields[i].newTerm(term.text());
        blendedBoost[i] = blendedFields[i].boost;
    }
    if (options.commonTermsCutoff() != null) {
        return BlendedTermQuery.commonTermsBlendedQuery(
            terms, blendedBoost, false, options.commonTermsCutoff());
    }

    if (tieBreaker == 1.0f) {
        return BlendedTermQuery.booleanBlendedQuery(terms, blendedBoost, false);
    }
    return BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:MultiMatchQueryBuilder.java

示例4: blendTerm

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
@Override
public Query blendTerm(Term term, MappedFieldType fieldType) {
    if (blendedFields == null) {
        return super.blendTerm(term, fieldType);
    }
    final Term[] terms = new Term[blendedFields.length];
    float[] blendedBoost = new float[blendedFields.length];
    for (int i = 0; i < blendedFields.length; i++) {
        terms[i] = blendedFields[i].newTerm(term.text());
        blendedBoost[i] = blendedFields[i].boost;
    }
    if (commonTermsCutoff != null) {
        return BlendedTermQuery.commonTermsBlendedQuery(terms, blendedBoost, false, commonTermsCutoff);
    }

    if (tieBreaker == 1.0f) {
        return BlendedTermQuery.booleanBlendedQuery(terms, blendedBoost, false);
    }
    return BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:MultiMatchQuery.java

示例5: testExtractQueryMetadata_blendedTermQuery

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testExtractQueryMetadata_blendedTermQuery() {
    Term[] termsArr = new Term[]{new Term("_field", "_term1"), new Term("_field", "_term2")};
    BlendedTermQuery commonTermsQuery = BlendedTermQuery.booleanBlendedQuery(termsArr, false);
    Result result = analyze(commonTermsQuery);
    assertThat(result.verified, is(true));
    List<Term> terms = new ArrayList<>(result.terms);
    Collections.sort(terms);
    assertThat(terms.size(), equalTo(2));
    assertThat(terms.get(0).field(), equalTo("_field"));
    assertThat(terms.get(0).text(), equalTo("_term1"));
    assertThat(terms.get(1).field(), equalTo("_field"));
    assertThat(terms.get(1).text(), equalTo("_term2"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:QueryAnalyzerTests.java

示例6: testBlendTerms

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testBlendTerms() {
    FakeFieldType ft1 = new FakeFieldType();
    ft1.setName("foo");
    FakeFieldType ft2 = new FakeFieldType();
    ft2.setName("bar");
    Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
    float[] boosts = new float[] {2, 3};
    Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
    Query actual = MultiMatchQuery.blendTerm(
            indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
            new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
    assertEquals(expected, actual);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:MultiMatchQueryTests.java

示例7: testBlendTermsWithFieldBoosts

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testBlendTermsWithFieldBoosts() {
    FakeFieldType ft1 = new FakeFieldType();
    ft1.setName("foo");
    ft1.setBoost(100);
    FakeFieldType ft2 = new FakeFieldType();
    ft2.setName("bar");
    ft2.setBoost(10);
    Term[] terms = new Term[] { new Term("foo", "baz"), new Term("bar", "baz") };
    float[] boosts = new float[] {200, 30};
    Query expected = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
    Query actual = MultiMatchQuery.blendTerm(
            indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
            new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
    assertEquals(expected, actual);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:MultiMatchQueryTests.java

示例8: testNoMatchQueries

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testNoMatchQueries() throws IOException {
    String userQuery = "brown cow";

    Term[] termsToBlend = new Term[]{new Term("field",  userQuery.split(" ")[0])};

    Query blended = BlendedTermQuery.booleanBlendedQuery(termsToBlend, false);
    List<PrebuiltFeature> features = Arrays.asList(
            new PrebuiltFeature(null, new TermQuery(new Term("field",  "missingterm"))),
            new PrebuiltFeature(null, blended));

    checkModelWithFeatures(features, null);
}
 
開發者ID:o19s,項目名稱:elasticsearch-learning-to-rank,代碼行數:13,代碼來源:LtrQueryTests.java

示例9: testDuelSpecificQueries

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testDuelSpecificQueries() throws Exception {
    List<ParseContext.Document> documents = new ArrayList<>();

    CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128);
    commonTermsQuery.add(new Term("field", "quick"));
    commonTermsQuery.add(new Term("field", "brown"));
    commonTermsQuery.add(new Term("field", "fox"));
    addQuery(commonTermsQuery, documents);

    BlendedTermQuery blendedTermQuery = BlendedTermQuery.booleanBlendedQuery(new Term[]{new Term("field", "quick"),
            new Term("field", "brown"), new Term("field", "fox")}, false);
    addQuery(blendedTermQuery, documents);

    SpanNearQuery spanNearQuery = new SpanNearQuery.Builder("field", true)
            .addClause(new SpanTermQuery(new Term("field", "quick")))
            .addClause(new SpanTermQuery(new Term("field", "brown")))
            .addClause(new SpanTermQuery(new Term("field", "fox")))
            .build();
    addQuery(spanNearQuery, documents);

    SpanNearQuery spanNearQuery2 = new SpanNearQuery.Builder("field", true)
            .addClause(new SpanTermQuery(new Term("field", "the")))
            .addClause(new SpanTermQuery(new Term("field", "lazy")))
            .addClause(new SpanTermQuery(new Term("field", "doc")))
            .build();
    SpanOrQuery spanOrQuery = new SpanOrQuery(
            spanNearQuery,
            spanNearQuery2
    );
    addQuery(spanOrQuery, documents);

    SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, spanNearQuery);
    addQuery(spanNotQuery, documents);

    long lowerLong = randomIntBetween(0, 256);
    long upperLong = lowerLong + randomIntBetween(0, 32);
    addQuery(LongPoint.newRangeQuery("long_field", lowerLong, upperLong), documents);

    indexWriter.addDocuments(documents);
    indexWriter.close();
    directoryReader = DirectoryReader.open(directory);
    IndexSearcher shardSearcher = newSearcher(directoryReader);
    // Disable query cache, because ControlQuery cannot be cached...
    shardSearcher.setQueryCache(null);

    Document document = new Document();
    document.add(new TextField("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO));
    long randomLong = randomIntBetween((int) lowerLong, (int) upperLong);
    document.add(new LongPoint("long_field", randomLong));
    MemoryIndex memoryIndex = MemoryIndex.fromDocument(document, new WhitespaceAnalyzer());
    duelRun(queryStore, memoryIndex, shardSearcher);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:53,代碼來源:CandidateQueryTests.java

示例10: testOnRewrittenQueries

import org.apache.lucene.queries.BlendedTermQuery; //導入方法依賴的package包/類
public void testOnRewrittenQueries() throws IOException {
    String userQuery = "brown cow";

    Term[] termsToBlend = new Term[]{new Term("field",  userQuery.split(" ")[0])};

    Query blended = BlendedTermQuery.booleanBlendedQuery(termsToBlend, false);
    List<Query> features = Arrays.asList(new TermQuery(new Term("field",  userQuery.split(" ")[0])), blended);

    checkModelWithFeatures(toPrebuildFeatureWithNoName(features), null);
}
 
開發者ID:o19s,項目名稱:elasticsearch-learning-to-rank,代碼行數:11,代碼來源:LtrQueryTests.java


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