Skip to content

Commit 7a8b54c

Browse files
committed
SOLR-18156: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
1 parent af8afee commit 7a8b54c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Fix ClassCastException when using join queries with query-limits (like timeAllowed)
2+
type: fixed
3+
authors:
4+
- name: hossman
5+
links:
6+
- name: SOLR-18156
7+
url: https://issues.apache.org/jira/browse/SOLR-18156

solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.apache.lucene.search.TotalHitCountCollector;
8383
import org.apache.lucene.search.TotalHits;
8484
import org.apache.lucene.search.TotalHits.Relation;
85+
import org.apache.lucene.search.Weight;
8586
import org.apache.lucene.store.Directory;
8687
import org.apache.lucene.util.Bits;
8788
import org.apache.lucene.util.BytesRef;
@@ -798,12 +799,24 @@ public QueryResult search(QueryResult qr, QueryCommand cmd) throws IOException {
798799
return qr;
799800
}
800801

802+
/**
803+
* Override the default behavior to proxy to an anonymous {@link IndexSearcher} with {@link
804+
* IndexSearcher#setTimeout} enabled, if and only if {@link QueryLimits#getCurrentLimits} are
805+
* enabled.
806+
*
807+
* <p>It's important that this logic live in an overriden method that processes a query
808+
* <em>after</em> the <code>Weight</code> has been computed, because some customer Solr <code>
809+
* Query</code> classes expect a <code>SolrIndexSearcher</code> to be used for query rewrite and
810+
* weight creation.
811+
*/
801812
@Override
802-
public void search(Query query, Collector collector) throws IOException {
813+
protected void searchLeaf(
814+
LeafReaderContext ctx, int minDocId, int maxDocId, Weight weight, Collector collector)
815+
throws IOException {
803816
QueryLimits queryLimits = QueryLimits.getCurrentLimits();
804817
if (!queryLimits.isLimitsEnabled()) {
805818
// no timeout. Pass through to super class
806-
super.search(query, collector);
819+
super.searchLeaf(ctx, minDocId, maxDocId, weight, collector);
807820
} else {
808821
// Timeout enabled! This impl is maybe a hack. Use Lucene's IndexSearcher timeout.
809822
// But only some queries have it so don't use on "this" (SolrIndexSearcher), not to mention
@@ -814,9 +827,7 @@ public void search(Query query, Collector collector) throws IOException {
814827
reader, core.getCoreContainer().getIndexSearcherExecutor()) { // cheap, actually!
815828
void searchWithTimeout() throws IOException {
816829
setTimeout(queryLimits); // Lucene's method name is less than ideal here...
817-
// XXX Deprecated in Lucene 10, we should probably use search(Query, CollectorManager)
818-
// instead
819-
super.search(query, collector);
830+
super.searchLeaf(ctx, minDocId, maxDocId, weight, collector);
820831
if (timedOut()) {
821832
throw new QueryLimitsExceededException(
822833
"Limits exceeded! (search): " + queryLimits.limitStatusMessage());

solr/core/src/test/org/apache/solr/TestJoin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ public void testRandomJoin() throws Exception {
391391

392392
SolrQueryRequest req =
393393
req(
394+
// all permutations of using/not using param; and unlimited/limited value
395+
(random().nextBoolean() ? "timeAllowed" : "__ignored"),
396+
(random().nextBoolean() ? "-1" : "99999999999"),
394397
"wt",
395398
"json",
396399
"indent",

0 commit comments

Comments
 (0)