I have no experience with thinking_sphinx (I take pride in the fact I even got it working).
I would like to sort my results based on relevance to the search and how recent they are. Maybe, 5X for relevance, 1X for time. (I’d have to play with that to get it right). Obviously if there’s no search criteria, I’d like it to sort just by time.
I know I need to add the created_at column to the search model, but not as indexes (what term do I use?)
Report controller:
def index
@reports = Report.search params[:search]
# unknown sorting code here
end
Report model:
define_index do
indexes apparatus
indexes body
indexes comments.body, as => :comment_body
????? created_at
end
You would just do:
By using
hasyou just denote whatever fields it needs but isn’t indexing onFor search sorting, you need to read the Sphinx docs for how you think you’d want them weighted and sorted:
http://freelancing-god.github.com/ts/en/searching.html#sorting
http://freelancing-god.github.com/ts/en/searching.html#fieldweights
By default, Sphinx sorts based on how relevant it thinks the results are to the given inputs.