lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jim...@apache.org
Subject lucene-solr:master: LUCENE-7874: DisjunctionMaxQuery rewrites to a BooleanQuery when tiebreaker is set to 1.
Date Fri, 16 Jun 2017 15:07:16 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 0c683305a -> 68d29c9b4


LUCENE-7874: DisjunctionMaxQuery rewrites to a BooleanQuery when tiebreaker is set to 1.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/68d29c9b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/68d29c9b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/68d29c9b

Branch: refs/heads/master
Commit: 68d29c9b4f167b3a350c14db9e7dc35811b52c54
Parents: 0c68330
Author: Jim Ferenczi <jimczi@apache.org>
Authored: Fri Jun 16 17:06:59 2017 +0200
Committer: Jim Ferenczi <jimczi@apache.org>
Committed: Fri Jun 16 17:06:59 2017 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                   |  2 ++
 .../apache/lucene/search/DisjunctionMaxQuery.java    |  8 ++++++++
 .../lucene/search/TestDisjunctionMaxQuery.java       | 15 +++++++++++++++
 3 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/68d29c9b/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f11e8af..595ed12 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/68d29c9b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
index 44cbd52..4ea29d6 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
@@ -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) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/68d29c9b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
index 112d892..79cdf00 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
@@ -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) {


Mime
View raw message