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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just updated this gist to correct an error. You should check
solr_result
, notsolr_response
, as per Sunspot's abstract_search.rb.