Search in sources :

Example 26 with BoostQuery

use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.

the class FastVectorHighlighterTest method clause.

private Query clause(String field, float boost, String... terms) {
    Query q;
    if (terms.length == 1) {
        q = new TermQuery(new Term(field, terms[0]));
    } else {
        q = new PhraseQuery(field, terms);
    }
    q = new BoostQuery(q, boost);
    return q;
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) CommonTermsQuery(org.apache.lucene.queries.CommonTermsQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) CustomScoreQuery(org.apache.lucene.queries.CustomScoreQuery) TermQuery(org.apache.lucene.search.TermQuery) SynonymQuery(org.apache.lucene.search.SynonymQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) Term(org.apache.lucene.index.Term) BoostQuery(org.apache.lucene.search.BoostQuery)

Example 27 with BoostQuery

use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.

the class FieldQueryTest method testFlattenConstantScoreQuery.

public void testFlattenConstantScoreQuery() throws Exception {
    initBoost();
    Query query = new ConstantScoreQuery(pqF("A"));
    query = new BoostQuery(query, boost);
    FieldQuery fq = new FieldQuery(query, true, true);
    Set<Query> flatQueries = new HashSet<>();
    fq.flatten(query, reader, flatQueries, 1f);
    assertCollectionQueries(flatQueries, tq(boost, "A"));
}
Also used : Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) BoostQuery(org.apache.lucene.search.BoostQuery) HashSet(java.util.HashSet)

Example 28 with BoostQuery

use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.

the class FieldQueryTest method testFlattenDisjunctionMaxQuery.

public void testFlattenDisjunctionMaxQuery() throws Exception {
    initBoost();
    Query query = dmq(tq("A"), tq("B"), pqF("C", "D"));
    query = new BoostQuery(query, boost);
    FieldQuery fq = new FieldQuery(query, true, true);
    Set<Query> flatQueries = new HashSet<>();
    fq.flatten(query, reader, flatQueries, 1f);
    assertCollectionQueries(flatQueries, tq(boost, "A"), tq(boost, "B"), pqF(boost, "C", "D"));
}
Also used : Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) BoostQuery(org.apache.lucene.search.BoostQuery) HashSet(java.util.HashSet)

Example 29 with BoostQuery

use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.

the class FieldQueryTest method testFlattenBoolean.

public void testFlattenBoolean() throws Exception {
    initBoost();
    BooleanQuery.Builder booleanQueryB = new BooleanQuery.Builder();
    booleanQueryB.add(tq("A"), Occur.MUST);
    booleanQueryB.add(tq("B"), Occur.MUST);
    booleanQueryB.add(tq("C"), Occur.SHOULD);
    BooleanQuery.Builder innerQuery = new BooleanQuery.Builder();
    innerQuery.add(tq("D"), Occur.MUST);
    innerQuery.add(tq("E"), Occur.MUST);
    booleanQueryB.add(innerQuery.build(), Occur.MUST_NOT);
    Query booleanQuery = booleanQueryB.build();
    booleanQuery = new BoostQuery(booleanQuery, boost);
    FieldQuery fq = new FieldQuery(booleanQuery, true, true);
    Set<Query> flatQueries = new HashSet<>();
    fq.flatten(booleanQuery, reader, flatQueries, 1f);
    assertCollectionQueries(flatQueries, tq(boost, "A"), tq(boost, "B"), tq(boost, "C"));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) PrefixQuery(org.apache.lucene.search.PrefixQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) TermQuery(org.apache.lucene.search.TermQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) BoostQuery(org.apache.lucene.search.BoostQuery) HashSet(java.util.HashSet)

Example 30 with BoostQuery

use of org.apache.lucene.search.BoostQuery in project lucene-solr by apache.

the class MoreLikeThis method createQuery.

/**
   * Create the More like query from a PriorityQueue
   */
private Query createQuery(PriorityQueue<ScoreTerm> q) {
    BooleanQuery.Builder query = new BooleanQuery.Builder();
    ScoreTerm scoreTerm;
    float bestScore = -1;
    while ((scoreTerm = q.pop()) != null) {
        Query tq = new TermQuery(new Term(scoreTerm.topField, scoreTerm.word));
        if (boost) {
            if (bestScore == -1) {
                bestScore = (scoreTerm.score);
            }
            float myScore = (scoreTerm.score);
            tq = new BoostQuery(tq, boostFactor * myScore / bestScore);
        }
        try {
            query.add(tq, BooleanClause.Occur.SHOULD);
        } catch (BooleanQuery.TooManyClauses ignore) {
            break;
        }
    }
    return query.build();
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) Term(org.apache.lucene.index.Term) BoostQuery(org.apache.lucene.search.BoostQuery)

Aggregations

BoostQuery (org.apache.lucene.search.BoostQuery)109 Query (org.apache.lucene.search.Query)91 BooleanQuery (org.apache.lucene.search.BooleanQuery)80 TermQuery (org.apache.lucene.search.TermQuery)71 Term (org.apache.lucene.index.Term)48 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)43 PhraseQuery (org.apache.lucene.search.PhraseQuery)32 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)27 PrefixQuery (org.apache.lucene.search.PrefixQuery)27 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)25 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)22 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)21 MultiPhraseQuery (org.apache.lucene.search.MultiPhraseQuery)20 SynonymQuery (org.apache.lucene.search.SynonymQuery)19 WildcardQuery (org.apache.lucene.search.WildcardQuery)19 BooleanClause (org.apache.lucene.search.BooleanClause)18 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)17 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)16 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)16 ArrayList (java.util.ArrayList)14