I have two models, an School model, a Price model. A School has one price.
Here is my School-controller, I eager load the price model with school-model:
def index
@search = School.search(:include => [:price]) do
fulltext params[:search]
paginate :page => params[:page], :per_page => 7
end
@results = @search.results
end
In my School model I do something like this:
searchable do
string :name
text :locality
end
In sunspot you can use a method for sorting and ordering the search result: https://github.com/sunspot/sunspot#ordering
Very easy if you want order the result by the name of a School, you do somehting like this:
@search = School.search(:include => [:price]) do
fulltext params[:search]
order_by(:name, :desc)
paginate :page => params[:page], :per_page => 7
end
But in my case I would like to order by a column in the price model. How do I do that in sunspot?