Take the 2-minute tour ×

I have 3 Rails apps running:

  1. Local development (with Sunspot installed)
  2. Staging on Heroku (running the "production" Rails environment)
  3. Production on Heroku (running the "production" Rails environment)

Using Solr on Heroku costs money and I'll be adding it to my production app. I don't want to add Solr to my staging app as performance isn't critical.

I'm wondering if there's a decent way to degrade my Sunspot/Solr calls to SQL queries.

Sunspot calls in my controller look as follows:

@search = Search.find(params[:id])
@results = Listing.search do |query|
  query.with(:city).any_of @search.cities if @search.cities
  query.with(:county).any_of @search.counties if @search.counties
share|improve this question
check if Rails.env.production? to distinguish between using Records.where("blah like 'that%'") and Records.search{ fulltext 'that' } –  nurettin Sep 15 '12 at 6:29
add comment

2 Answers

If you're not using Solr's fulltext search, and you're using Rails 2, record_filter has a very similar syntax: https://github.com/aub/record_filter

That said, your best bet would probably be to define two adapter classes that present the same interface but use Solr and SQL under the hood respectively.

share|improve this answer
Thanks so much for this answer! Unfortunately, I'm using Rails 3. Sorry I forgot to mention that. I guess my issue now is distinguishing whether Sunspot is supported at the time of code execution. Any tips on this? (The real difficulty here is because both Heroku apps are running the production environment) –  Mike Jan 28 '11 at 17:27
add comment

Additionally, if you're using the WebSolr addon, they actually provide you with two indexes—if you log into the websolr console it will allow you to create a second index there, and you can point to that index from your staging site.

share|improve this answer
We <3 staging environments. –  Nick Zadrozny Mar 17 '11 at 5:33
add comment

Your Answer


