You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2026/03/11 23:45:00 UTC

(solr) branch branch_10_0 updated: SOLR-18156: Fix ClassCastException when using join queries with query-limits (like timeAllowed)

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

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


The following commit(s) were added to refs/heads/branch_10_0 by this push:
     new 2904c232c87 SOLR-18156: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
2904c232c87 is described below

commit 2904c232c873bb35f2099b5ca96fd8d14075fe5a
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Wed Mar 11 15:29:17 2026 -0700

    SOLR-18156: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
    
    (cherry picked from commit 7a8b54c55a6711fbd1cc34aea336e1db20737233)
---
 .../SOLR-18156-join-query-time-allowed.yml          |  7 +++++++
 .../org/apache/solr/search/SolrIndexSearcher.java   | 21 ++++++++++++++++-----
 solr/core/src/test/org/apache/solr/TestJoin.java    |  3 +++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/changelog/unreleased/SOLR-18156-join-query-time-allowed.yml b/changelog/unreleased/SOLR-18156-join-query-time-allowed.yml
new file mode 100644
index 00000000000..581d912f878
--- /dev/null
+++ b/changelog/unreleased/SOLR-18156-join-query-time-allowed.yml
@@ -0,0 +1,7 @@
+title: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
+type: fixed
+authors:
+  - name: hossman
+links:
+  - name: SOLR-18156
+    url: https://issues.apache.org/jira/browse/SOLR-18156
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 7868d7688ca..407f478be0a 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -82,6 +82,7 @@ import org.apache.lucene.search.TopScoreDocCollectorManager;
 import org.apache.lucene.search.TotalHitCountCollector;
 import org.apache.lucene.search.TotalHits;
 import org.apache.lucene.search.TotalHits.Relation;
+import org.apache.lucene.search.Weight;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
@@ -798,12 +799,24 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
     return qr;
   }
 
+  /**
+   * Override the default behavior to proxy to an anonymous {@link IndexSearcher} with {@link
+   * IndexSearcher#setTimeout} enabled, if and only if {@link QueryLimits#getCurrentLimits} are
+   * enabled.
+   *
+   * <p>It's important that this logic live in an overriden method that processes a query
+   * <em>after</em> the <code>Weight</code> has been computed, because some customer Solr <code>
+   * Query</code> classes expect a <code>SolrIndexSearcher</code> to be used for query rewrite and
+   * weight creation.
+   */
   @Override
-  public void search(Query query, Collector collector) throws IOException {
+  protected void searchLeaf(
+      LeafReaderContext ctx, int minDocId, int maxDocId, Weight weight, Collector collector)
+      throws IOException {
     QueryLimits queryLimits = QueryLimits.getCurrentLimits();
     if (!queryLimits.isLimitsEnabled()) {
       // no timeout.  Pass through to super class
-      super.search(query, collector);
+      super.searchLeaf(ctx, minDocId, maxDocId, weight, collector);
     } else {
       // Timeout enabled!  This impl is maybe a hack.  Use Lucene's IndexSearcher timeout.
       // But only some queries have it so don't use on "this" (SolrIndexSearcher), not to mention
@@ -814,9 +827,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
           reader, core.getCoreContainer().getIndexSearcherExecutor()) { // cheap, actually!
         void searchWithTimeout() throws IOException {
           setTimeout(queryLimits); // Lucene's method name is less than ideal here...
-          // XXX Deprecated in Lucene 10, we should probably use search(Query, CollectorManager)
-          // instead
-          super.search(query, collector);
+          super.searchLeaf(ctx, minDocId, maxDocId, weight, collector);
           if (timedOut()) {
             throw new QueryLimitsExceededException(
                 "Limits exceeded! (search): " + queryLimits.limitStatusMessage());
diff --git a/solr/core/src/test/org/apache/solr/TestJoin.java b/solr/core/src/test/org/apache/solr/TestJoin.java
index 9ac9e7b271f..14f776610ba 100644
--- a/solr/core/src/test/org/apache/solr/TestJoin.java
+++ b/solr/core/src/test/org/apache/solr/TestJoin.java
@@ -391,6 +391,9 @@ public class TestJoin extends SolrTestCaseJ4 {
 
         SolrQueryRequest req =
             req(
+                // all permutations of using/not using param; and unlimited/limited value
+                (random().nextBoolean() ? "timeAllowed" : "__ignored"),
+                (random().nextBoolean() ? "-1" : "99999999999"),
                 "wt",
                 "json",
                 "indent",