Search results cannot be an ActiveRecord::Relation
, because you're querying against Sphinx, not a database. What you actually get back is not an array, but an instance of ThinkingSphinx::Search
which behaves very similarly to an array.
However, search calls are lazily evaluated, and page
and per
are methods that are available on ThinkingSphinx::Search
, so you can use those. As for includes
, you'll need to do the following instead:
@products = @products.search(:sql => {:include => :category})
There's nothing like maximum
though. But if you do want an aggregation from the database based on Sphinx search results, this should do the trick:
Product.where(id: Product.search_for_ids(params[:query]).to_a).maximum(:cost)