Chr*_*ris 6 ruby sorting facet sunspot
资产模型:
searchable do
text :title
text :description
time :created_at
integer :category_ids, :multiple => true, :references => Category
end
Run Code Online (Sandbox Code Playgroud)
控制器:
search = Asset.search() do
keywords(h(params[:query]), :fields => [:title, :description])
facet(:category_ids)
order_by :created_at
end
Run Code Online (Sandbox Code Playgroud)
我不想:Category_ides通过:count(点击次数)对我的方面进行排序.类别应按以下顺序排序created_at.查看documentation facet(:category_ids, :sort=> :count || :index),这两个选项对我都不起作用.
如何解决方面的订单问题?
您只需加载facet,然后自己对它们进行排序:
result = Product.solr_search do |s|
s.keywords params[:q]
s.facet :category_id
s.paginate :per_page => 3, :page => @page
end
facet_rows = result.facet(:category_id).rows.sort { |left,right| left.instance.created_at <=> right.instance.created_at }
Run Code Online (Sandbox Code Playgroud)