forked from sunspot/sunspot
-
Notifications
You must be signed in to change notification settings - Fork 36
Dealing with partial results
Olga Grabek edited this page Apr 22, 2014
·
1 revision
Sometimes it is possible that Solr returns only partial results. It can be caused for example when you perform expensive query on a large index (more about this can be read on Websolr support page). To deal with that, first you have to do is to detect that you got partial results. If so, you may benefit from retrying your search additional time(s). This is effective because Solr caches results of previous searching.
def results
retry_search = true
search_count = 0
# retry the same search if partial results
while retry_search && search_count < 2
search_count += 1
search = Post.search { fulltext 'pizza' }
# Look for partialResults in response:
solr_response = search.instance_eval("@solr_result")
retry_search = solr_response["responseHeader"]["partialResults"] == true
end
search.results
end