I'm trying to accomplish a simple sort using parameters passed to my controller. I'm following the documentation on the Searching & Thinking Sphinx website and I'm met with the following error. What am I doing wrong?
The following @places object is an instance of the think Sphinx class.
@places = Place.search(params[:q], :order => :created_at)
ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found):
You need to add fields on which you want to search. Then to sort by a field you need to mark it as sortable in your model, or you need to add an attribute in the define_index method as explained here.
For your model, something like this:
class Place < ActiveRecord::Base
# ...
define_index do
# fields
indexes subject, :sortable => true
indexes content
indexes author.name, :as => :author, :sortable => true
# attributes
has created_at
end
# ...
end
In that example, subject, author and created_at are sortable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With