ruby-on-rails – 你如何在Rails 3上使用Thinking Sphinx进行排
发布时间:2020-12-17 03:27:32 所属栏目:百科 来源:网络整理
导读:我正在尝试使用传递给我的控制器的参数来完成一个简单的排序.我正在追踪 documentation的Searching思考Sphinx网站,我遇到了以下错误.我究竟做错了什么? 以下@places对象是think Sphinx类的一个实例. @places = Place.search(params[:q],:order = :created_a
我正在尝试使用传递给我的控制器的参数来完成一个简单的排序.我正在追踪
documentation的Searching&思考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方法中将属性添加为
explained here.
对于您的模型,这样的事情: 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是可排序的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |