Java Code Examples for org.apache.lucene.queries.BlendedTermQuery#dismaxBlendedQuery()

The following examples show how to use org.apache.lucene.queries.BlendedTermQuery#dismaxBlendedQuery() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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);
}
 
Example 2
Source Project: Elasticsearch   File: MultiMatchQuery.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
public void testNoMatchQueries() throws IOException {
    String userQuery = "brown cow";

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

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

    checkModelWithFeatures(features, null, null);
}
 
Example 4
public void testOnRewrittenQueries() throws IOException {
    String userQuery = "brown cow";

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

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

    checkModelWithFeatures(toPrebuildFeatureWithNoName(features), null, null);
}