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')

Need Your Help

Cassandra Time-Series data modelling

database-design cassandra data-modeling

I've been working on a data model for an analytics system for a little while now, but I just can't seem to get the right setup for my primary keys. I've watched a bunch of videos

How to cmake, make and compile C++14 on Windows

c++ windows gcc compilation c++14

I'm trying to compile, on Windows 10, a C++ project that is using C++14 features such as std::make_unique<> and things like that.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.