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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.