如何对《Using Thinking Sphinx on Rails 3》进行排序?
我正在尝试使用传递给控制器的参数来完成简单的排序。我正在关注有关搜索和搜索的文档。在思考 Sphinx 网站时,我遇到了以下错误。我做错了什么?
以下@places对象是think Sphinx类的实例。
@places = Place.search(params[:q], :order => :created_at)
ThinkingSphinx::SphinxError (index place_core: sort-by attribute 'created_at' not found):
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):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加要搜索的字段。然后,要按字段排序,您需要在模型中将其标记为可排序,或者需要在 define_index 方法中添加一个属性,如 此处解释。
对于您的模型,如下所示:
在该示例中,主题、作者和created_at 是可排序的。
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:
In that example, subject, author and created_at are sortable.