mirror of https://github.com/apache/lucene.git
LUCENE-7874: DisjunctionMaxQuery rewrites to a BooleanQuery when tiebreaker is set to 1.
This commit is contained in:
parent
0c683305a4
commit
68d29c9b4f
|
@ -112,6 +112,8 @@ Optimizations
|
|||
query is a point (for 2D) or a is a simple date interval (e.g. 1 month). When
|
||||
the strategy is marked as pointsOnly, the results is a TermQuery. (David Smiley)
|
||||
|
||||
* LUCENE-7874: DisjunctionMaxQuery rewrites to a BooleanQuery when tiebreaker is set to 1. (Jim Ferenczi)
|
||||
|
||||
Other
|
||||
|
||||
* LUCENE-7328: Remove LegacyNumericEncoding from GeoPointField. (Nick Knize)
|
||||
|
|
|
@ -178,6 +178,14 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
|
|||
return disjuncts[0];
|
||||
}
|
||||
|
||||
if (tieBreakerMultiplier == 1.0f) {
|
||||
BooleanQuery.Builder builder = new BooleanQuery.Builder();
|
||||
for (Query sub : disjuncts) {
|
||||
builder.add(sub, BooleanClause.Occur.SHOULD);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
boolean actuallyRewritten = false;
|
||||
List<Query> rewrittenDisjuncts = new ArrayList<>();
|
||||
for (Query sub : disjuncts) {
|
||||
|
|
|
@ -523,6 +523,21 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase {
|
|||
assertTrue("score should be negative", h[i].score < 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testRewriteBoolean() throws Exception {
|
||||
Query sub1 = tq("hed", "albino");
|
||||
Query sub2 = tq("hed", "elephant");
|
||||
DisjunctionMaxQuery q = new DisjunctionMaxQuery(
|
||||
Arrays.asList(
|
||||
sub1, sub2
|
||||
), 1.0f);
|
||||
Query rewritten = s.rewrite(q);
|
||||
assertTrue(rewritten instanceof BooleanQuery);
|
||||
BooleanQuery bq = (BooleanQuery) rewritten;
|
||||
assertEquals(bq.clauses().size(), 2);
|
||||
assertEquals(bq.clauses().get(0), new BooleanClause(sub1, BooleanClause.Occur.SHOULD));
|
||||
assertEquals(bq.clauses().get(1), new BooleanClause(sub2, BooleanClause.Occur.SHOULD));
|
||||
}
|
||||
|
||||
/** macro */
|
||||
protected Query tq(String f, String t) {
|
||||
|
|
Loading…
Reference in New Issue