[英]When thinking-sphinx finds data how do you then pull data out of the hash in ruby on rails?
[英]How do you sort Using Thinking Sphinx on Rails 3?
我正在尝试使用传递给我的控制器的参数来完成一个简单的排序。 我正在关注Searching&Thinking Sphinx网站上的文档 ,我遇到了以下错误。 我究竟做错了什么?
以下@places对象是think Sphinx类的一个实例。
@places = Place.search(params[:q], :order => :created_at)
ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found):
您需要添加要搜索的字段。 然后,通过一个字段进行排序,你需要将其标记为可排序的模型,或者您需要在define_index方法添加属性为这里解释 。
对于您的模型,这样的事情:
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
在该示例中,subject,author和created_at是可排序的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.