8282import org .apache .lucene .search .TotalHitCountCollector ;
8383import org .apache .lucene .search .TotalHits ;
8484import org .apache .lucene .search .TotalHits .Relation ;
85+ import org .apache .lucene .search .Weight ;
8586import org .apache .lucene .store .Directory ;
8687import org .apache .lucene .util .Bits ;
8788import 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 ());
0 commit comments