Apache Solr open-source search software
SOLR-18156: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
Chris Hostetter7a8b54c55a67
diff --git a/changelog/unreleased/SOLR-18156-join-query-time-allowed.yml b/changelog/unreleased/SOLR-18156-join-query-time-allowed.ymlnew file mode 100644index 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-18156diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.javaindex 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, SolrIreturn 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, SolrIreader, 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.javaindex 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",