Riddle::ConnectionError not thrown consistently when search server is down

Hemang Patel's Avatar

Hemang Patel

23 Oct, 2012 11:04 PM

I am implementing a rescue Riddle::ConnectionError for my search results page. But, the Riddle::ConnectionError exception doesn't seem to be thrown until the search result is actually checked with empty? in the view page.

Is this intentional? The search is not actually performed until the search result is actually accessed.

At the moment, I am doing something like the code below in my search controller. Is there a better way to handle this?

 @search =  User.search :conditions => { :name => name}
 @search = nil if @search.nil? || @search.emtpy?

  rescue Riddle::ConnectionError
      @error = true
  1. Support Staff 1 Posted by Pat Allan on 23 Oct, 2012 11:46 PM

    Pat Allan's Avatar

    Hi Hemang

    That behaviour is intentional - Thinking Sphinx lazily loads search results for the same reason Arel does: so you can chain scopes without making unnecessary queries to Sphinx. That said, you can have the query populate immediately by passing in the :populate => true option in your search call:

        User.search :conditions => {:name => name}, :populate => true



  2. 2 Posted by Hemang Patel on 24 Oct, 2012 12:27 AM

    Hemang Patel's Avatar

    Cool. Thanks Pat.

  3. Hemang Patel closed this discussion on 24 Oct, 2012 12:27 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac