As a Sunspot contributor and co-founder of Websolr , I recommend using rescue_from with a minimum timeout.
When it comes to Sunspot, it looks like the option to specify a timeout has recently been added to RSolr, the Sunspot library is used, so if this is the function you need, then you should learn how to submit a request to Sunspot for transmission timeout in RSolr.
Creating a failed Solr request should not be so expensive if you have the right timeouts. If Solr is turned off, you want it to disconnect when you open a TCP connection. A healthy Solr server should open a TCP connection an order of magnitude less than a second and start sending data for no more than a second or two for really expensive requests.
A wait time of 0.1 seconds and a data timeout of 5 seconds should be more than enough here.
The next best option here is to have another local proxy between your application and Solr, which can suppress requests when Solr is down. Perhaps middleware caching or Lac. Of course, I see this as a more complex approach if such a proxy server or cache is no longer part of your application infrastructure.
source share