use of org.apache.lucene.search.DisjunctionMaxQuery in project lucene-solr by apache.
the class TestCoreParser method testDisjunctionMaxQueryXML.
public void testDisjunctionMaxQueryXML() throws ParserException, IOException {
Query q = parse("DisjunctionMaxQuery.xml");
assertTrue(q instanceof DisjunctionMaxQuery);
DisjunctionMaxQuery d = (DisjunctionMaxQuery) q;
assertEquals(0.0f, d.getTieBreakerMultiplier(), 0.0001f);
assertEquals(2, d.getDisjuncts().size());
DisjunctionMaxQuery ndq = (DisjunctionMaxQuery) d.getDisjuncts().get(1);
assertEquals(1.2f, ndq.getTieBreakerMultiplier(), 0.0001f);
assertEquals(1, ndq.getDisjuncts().size());
}
use of org.apache.lucene.search.DisjunctionMaxQuery in project Anserini by castorini.
the class DisjunctionMaxQueryGeneratorTest method testMultipleFields.
@Test
public void testMultipleFields() {
float tiebreaker = 0.5f;
QueryGenerator queryGenerator = new DisjunctionMaxQueryGenerator(tiebreaker);
Map<String, Float> fields = Map.of("field1", 3.14f, "field2", 2.718f, "field3", 42.0f);
Query query = queryGenerator.buildQuery(fields, IndexCollection.DEFAULT_ANALYZER, "sample query");
assertTrue(query instanceof DisjunctionMaxQuery);
DisjunctionMaxQuery combinedQuery = (DisjunctionMaxQuery) query;
assertEquals(tiebreaker, combinedQuery.getTieBreakerMultiplier(), 1e-6);
assertEquals(3, combinedQuery.getDisjuncts().size());
assertTrue(combinedQuery.getDisjuncts().get(0) instanceof BoostQuery);
BoostQuery boostQuery = (BoostQuery) combinedQuery.getDisjuncts().get(0);
assertTrue(boostQuery.getBoost() > 1.0f);
assertTrue(boostQuery.getQuery() instanceof BooleanQuery);
BooleanQuery booleanQuery = (BooleanQuery) boostQuery.getQuery();
assertEquals(2, booleanQuery.clauses().size());
}
use of org.apache.lucene.search.DisjunctionMaxQuery in project Anserini by castorini.
the class DisjunctionMaxQueryGenerator method buildQuery.
@Override
public Query buildQuery(Map<String, Float> fields, Analyzer analyzer, String queryText) {
List<Query> clauses = new ArrayList<>(fields.size());
for (Map.Entry<String, Float> entry : fields.entrySet()) {
String field = entry.getKey();
float boost = entry.getValue();
Query clause = buildQuery(field, analyzer, queryText);
clauses.add(new BoostQuery(clause, boost));
}
return new DisjunctionMaxQuery(clauses, tiebreaker);
}
use of org.apache.lucene.search.DisjunctionMaxQuery in project crate by crate.
the class BlendedTermQuery method dismaxBlendedQuery.
public static BlendedTermQuery dismaxBlendedQuery(Term[] terms, final float[] boosts, final float tieBreakerMultiplier) {
return new BlendedTermQuery(terms, boosts) {
@Override
protected Query topLevelQuery(Term[] terms, TermStates[] ctx, int[] docFreqs, int maxDoc) {
List<Query> queries = new ArrayList<>(ctx.length);
for (int i = 0; i < terms.length; i++) {
Query query = new TermQuery(terms[i], ctx[i]);
if (boosts != null && boosts[i] != 1f) {
query = new BoostQuery(query, boosts[i]);
}
queries.add(query);
}
return new DisjunctionMaxQuery(queries, tieBreakerMultiplier);
}
};
}
Aggregations