Mike
Mike

Reputation: 2123

Ruby: Degrading Sunspot searches to SQL

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
  ...
end

Upvotes: 0

Views: 365

Answers (2)

workergnome
workergnome

Reputation: 566

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.

Upvotes: 1

outoftime
outoftime

Reputation: 2200

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.

Upvotes: 1

Related Questions