太阳黑子:按属性排序/排序小平面结果,例如created_at

时间:2011-06-25 14:02:35

标签: ruby sorting facet sunspot

资产模型:

searchable do
   text :title
   text :description
   time :created_at
   integer :category_ids, :multiple => true, :references => Category
end

控制器:

search = Asset.search() do
   keywords(h(params[:query]), :fields => [:title, :description])
   facet(:category_ids)
   order_by :created_at
end

我不想通过:Category_ides(点击次数)对我的方面:count进行排序。类别应按created_at排序。查看文档facet(:category_ids, :sort => :count || :index),这两个选项都不适用于我。

如何解决方面的此订单问题?

1 个答案:

答案 0 :(得分:8)

您只需加载构面,然后自行对它们进行排序:

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 }