![](/img/trans.png)
[英]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.