Riddle::ConnectionError not thrown consistently when search server is down
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?
begin
@search = User.search :conditions => { :name => name}
@search = nil if @search.nil? || @search.emtpy?
rescue Riddle::ConnectionError
@error = true
end
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | 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
Support Staff 1 Posted by Pat Allan on 23 Oct, 2012 11:46 PM
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
Cheers
Pat
2 Posted by Hemang Patel on 24 Oct, 2012 12:27 AM
Cool. Thanks Pat.
Hemang Patel closed this discussion on 24 Oct, 2012 12:27 AM.