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

krisden pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 2e9031281f9 SOLR-17130: edismax MatchAllDocsQuery (*:*) Optimization 
(#2218)
2e9031281f9 is described below

commit 2e9031281f9aabc64cae82cc6b859fc51b25df2f
Author: Kevin Risden <[email protected]>
AuthorDate: Mon Jun 30 10:02:12 2025 -0400

    SOLR-17130: edismax MatchAllDocsQuery (*:*) Optimization (#2218)
---
 solr/CHANGES.txt                                          |  2 ++
 .../org/apache/solr/search/ExtendedDismaxQParser.java     | 15 ++++++++++++---
 .../org/apache/solr/search/TestExtendedDismaxParser.java  | 14 ++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5bfd78565b0..50b1f67bbbd 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -83,6 +83,8 @@ Optimizations
 
 * SOLR-17801: Use TotalHitCountCollector to collect count when no rows needed 
(Kevin Risden)
 
+* SOLR-17130: edismax MatchAllDocsQuery (*:*) Optimization (Kevin Risden)
+
 Bug Fixes
 ---------------------
 * SOLR-17629: If SQLHandler failed to open the underlying stream (e.g. Solr 
returns an error; could be user/syntax problem),
diff --git 
a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java 
b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
index 139d0d53eff..3281b5073ef 100644
--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
@@ -186,10 +186,19 @@ public class ExtendedDismaxQParser extends QParser {
       query.add(f, BooleanClause.Occur.SHOULD);
     }
 
-    //
-    // create a boosted query (scores multiplied by boosts)
-    //
     Query topQuery = QueryUtils.build(query, this);
+
+    // If topQuery is a boolean query, unwrap the boolean query to check if it 
is just
+    // a MatchAllDocsQuery. Using MatchAllDocsQuery by itself enables later 
optimizations
+    BooleanQuery topQueryBoolean = (BooleanQuery) topQuery;
+    if (topQueryBoolean.clauses().size() == 1) {
+      Query onlyQuery = topQueryBoolean.clauses().get(0).getQuery();
+      if (onlyQuery instanceof MatchAllDocsQuery) {
+        topQuery = onlyQuery;
+      }
+    }
+
+    // create a boosted query (scores multiplied by boosts)
     List<ValueSource> boosts = getMultiplicativeBoosts();
     if (boosts.size() > 1) {
       ValueSource prod = new ProductFloatFunction(boosts.toArray(new 
ValueSource[0]));
diff --git 
a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java 
b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
index df78f80215e..a0a1815d4dc 100644
--- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
@@ -25,6 +25,7 @@ import static org.apache.solr.util.QueryMatchers.termQuery;
 import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.anyOf;
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.isA;
 
 import java.util.Arrays;
 import java.util.HashSet;
@@ -41,6 +42,7 @@ import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.FuzzyQuery;
+import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.TermQuery;
 import org.apache.solr.SolrTestCaseJ4;
@@ -143,6 +145,18 @@ public class TestExtendedDismaxParser extends 
SolrTestCaseJ4 {
     }
   }
 
+  @Test
+  public void testMatchAllDocs() throws Exception {
+    for (String sow : Arrays.asList("true", "false")) {
+      for (String q : Arrays.asList("*:*", "*")) {
+        try (SolrQueryRequest req = req("sow", sow, "qf", "id")) {
+          QParser qParser = QParser.getParser(q, "edismax", req);
+          assertThat(qParser.getQuery(), isA(MatchAllDocsQuery.class));
+        }
+      }
+    }
+  }
+
   public void testTrailingOperators() throws Exception {
     for (String sow : Arrays.asList("true", "false")) {
       // really just test that exceptions aren't thrown by

Reply via email to