Created
August 8, 2011 21:30
-
-
Save nz/1132809 to your computer and use it in GitHub Desktop.
Sunspot - Retry search on partialResults
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample code using Sunspot 1.2.1 to retry a search when partialResults=true | |
# | |
# I hope this code will be somewhat deprecated in Sunspot 1.2.2, since we have to | |
# use instance_eval to access the otherwise inaccessible @solr_response instance variable. | |
# | |
class Post | |
# ... | |
searchable do | |
# your Sunspot search setup | |
end | |
# ... | |
def self.search(params={}) | |
retry_search = true | |
search_count = 0 | |
while retry_search && search_count < 2 | |
search_count = search_count + 1 | |
search = Post.solr_search do | |
# your search code here | |
end | |
solr_response = search.instance_eval("@solr_result") | |
retry_search = solr_response["responseHeader"]["partialResults"] == true | |
search | |
end | |
end | |
end |
Ok, thanks, will do!
robzon, any progress? I also don't get the header at all.
Nope, filed a bug report but no response yet. As our database grew we now get first query with blank results 100% of time. For now I simply retry searching twice if there are no results and that works well (from user perspective). Will let you know when we get the proper fix.
Just updated this gist to correct an error. You should check solr_result
, not solr_response
, as per Sunspot's abstract_search.rb.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should fire up a ticket at http://help.websolr.com/ for something like that (sounds like replication latency to me)