tag:support.flying-sphinx.com,2011-01-05:/discussions/questions/53-riddleconnectionerror-not-thrown-consistently-when-search-server-is-downFlying Sphinx: Discussion 2018-10-19T03:09:28Ztag:support.flying-sphinx.com,2011-01-05:Comment/199668702012-10-23T23:04:03Z2012-10-23T23:04:03ZRiddle::ConnectionError not thrown consistently when search server is down<div><p>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.</p>
<p>Is this intentional? The search is not actually performed until
the search result is actually accessed.</p>
<p>At the moment, I am doing something like the code below in my
search controller. Is there a better way to handle this?</p>
<pre>
<code>begin
@search = User.search :conditions => { :name => name}
@search = nil if @search.nil? || @search.emtpy?
rescue Riddle::ConnectionError
@error = true
end</code>
</pre></div>Hemang Pateltag:support.flying-sphinx.com,2011-01-05:Comment/199668702012-10-23T23:46:53Z2012-10-23T23:46:53ZRiddle::ConnectionError not thrown consistently when search server is down<div><p>Hi Hemang</p>
<p>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:</p>
<pre>
<code>User.search :conditions => {:name => name}, :populate => true</code>
</pre>
<p>Cheers</p>
<p>Pat</p></div>Pat Allantag:support.flying-sphinx.com,2011-01-05:Comment/199668702012-10-24T00:27:31Z2012-10-24T00:27:31ZRiddle::ConnectionError not thrown consistently when search server is down<div><p>Cool. Thanks Pat.</p></div>Hemang Patel