3

如何将多个过滤器应用于刻面(使用轮胎宝石)?我有一个代码:

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

但它似乎只应用最后一个过滤器。但我需要他们两个。

4

2 回答 2

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
于 2013-03-05T04:45:46.873 回答
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
于 2013-08-22T11:23:37.703 回答