Sunspot: sort / sort facets by attribute, e.g. created in

The following situation:

Asset Model:

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

Controller:

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

I would like to sort my cell: Category_ides not in: count (number of hits). Categories must be ordered with the created_at command. Look at the documentation facet (: category_ids ,: sort =>: count ||: index). both options will not work for me.

How can I solve this order problem for facets?

+6
source share
1 answer

You can simply load the faces and then sort them yourself:

 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 } 
+8
source

Source: https://habr.com/ru/post/891348/


All Articles