You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ju...@apache.org on 2021/07/09 20:01:36 UTC

[lucene] branch master created (now 08e61a2)

This is an automated email from the ASF dual-hosted git repository.

julietibs pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucene.git.


      at 08e61a2  LUCENE-10022: Rewrite empty DisjunctionMaxQuery to MatchNoDocsQuery

This branch includes the following new commits:

     new 08e61a2  LUCENE-10022: Rewrite empty DisjunctionMaxQuery to MatchNoDocsQuery

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[lucene] 01/01: LUCENE-10022: Rewrite empty DisjunctionMaxQuery to MatchNoDocsQuery

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

julietibs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 08e61a22016233fa68caa92f850657a2494bd3a2
Author: Julie Tibshirani <ju...@gmail.com>
AuthorDate: Thu Jul 8 19:08:33 2021 -0700

    LUCENE-10022: Rewrite empty DisjunctionMaxQuery to MatchNoDocsQuery
    
    It's possible to create a DisjunctionMaxQuery with no clauses. This is now
    rewritten to MatchNoDocsQuery, matching the approach we take for BooleanQuery.
---
 lucene/CHANGES.txt                                                | 3 +++
 .../src/java/org/apache/lucene/search/DisjunctionMaxQuery.java    | 4 ++++
 .../test/org/apache/lucene/search/TestDisjunctionMaxQuery.java    | 8 ++++++++
 3 files changed, 15 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index f113085..c55f399 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -379,6 +379,9 @@ Optimizations
   particular in the case of many fields and many indexing threads.
   (Adrien Grand)
 
+* LUCENE-10022: Rewrite empty DisjunctionMaxQuery to MatchNoDocsQuery.
+  (David Harsha via Julie Tibshirani)
+
 Bug Fixes
 ---------------------
 * LUCENE-9988: Fix DrillSideways correctness bug introduced in LUCENE-9944 (Greg Miller)
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 3b2e1e2..2ca6576 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
@@ -207,6 +207,10 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
    */
   @Override
   public Query rewrite(IndexReader reader) throws IOException {
+    if (disjuncts.isEmpty()) {
+      return new MatchNoDocsQuery("empty DisjunctionMaxQuery");
+    }
+
     if (disjuncts.size() == 1) {
       return disjuncts.iterator().next();
     }
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 f55b3a5..e381826 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
@@ -22,6 +22,7 @@ import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -468,6 +469,13 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase {
     assertEquals(expected, rewritten);
   }
 
+  public void testRewriteEmpty() throws Exception {
+    DisjunctionMaxQuery q = new DisjunctionMaxQuery(Collections.emptyList(), 0.0f);
+    Query rewritten = s.rewrite(q);
+    Query expected = new MatchNoDocsQuery();
+    assertEquals(expected, rewritten);
+  }
+
   public void testDisjunctOrderAndEquals() throws Exception {
     // the order that disjuncts are provided in should not matter for equals() comparisons
     Query sub1 = tq("hed", "albino");