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;
}
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"));
}
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"));
}
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"));
}
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();
}
Aggregations