Getting number of hits without pagination in sunspot 1.2 on ruby on rails 3
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
Answers
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')