如何将多个滤镜应用于刻面(带有轮胎宝石)?我有一个代码:
facet "packages" do
terms :package
facet_filter :terms, producer: [*params[:producer]] if params[:producer].present?
facet_filter :terms, category_id: [*params[:category_id]] if params[:category_id].present?
end
但它似乎只适用于最后一个过滤器。但我需要他们两个。
答案 0 :(得分:9)
试试这个
my_filter = []
my_filter << {:terms => {:producer => [*params[:producer]] }} if params[:producer].present?
my_filter << {:terms => { :producer => [*params[:category_id]] }} if params[:category_id].present?
facet "packages" do
terms :package
facet_filter :and, my_filter
end
答案 1 :(得分:1)
my_filter = []
my_filter << {:term => {:producer => params[:producer] }} if params[:producer].present?
my_filter << {:term => {:category_id => params[:category_id] }} if params[:category_id].present?
facet "packages" do
terms :package
facet_filter(:and, my_filter) if my_filter.present?
end