I've successfully installed Sunspot for my Ruby On Rails 3 project, but I can't seem to find a way to get the total hits for a search query.
this is my search request
@search = Sunspot.search(Job) do
fulltext params[:job]
paginate(:page => params[:offset], :per_page => 25)
end
It works well except I need to get total number of real hits, not the total results returned (in this case 25 because of :per_page => 25)
In other words, I want to be able to display: Showing 1 to 25 out of 883 jobs found
Any help would be appreciated!
thanks
The method total
works here.
query_results = Sunspot.search(Recipe) do
keywords(params[:qs])
paginate(:page=>params[:page], :per_page=>30)
end
@search_results = query_result.results
@search_total = @search_results.total
Or, in your view, total_entries works on the results object.
%div
Your search for
= params[:qs]
returned
= pluralize(@search_results.total_entries, 'result')
Never used Sunspot, but have you tried this in your view:
Showing #{@search.hits.page} to #{@search.hits.per_page} out of #{@search.total} jobs found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With