Ruby on rails - 使用 Elasticsearch 的多面过滤器



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

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

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

试试这个

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
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

相关内容

  • 没有找到相关文章

最新更新