From a4cc433ccbf2b71e274dc2cc37c0e441dcb6ae8d Mon Sep 17 00:00:00 2001 From: Kieran Hayes Date: Wed, 16 Nov 2016 15:44:04 +0100 Subject: [PATCH 1/2] enable multi-value facets --- app/controllers/redsun_search_controller.rb | 27 +++++--- app/helpers/redsun_search_helper.rb | 2 +- app/views/redsun_search/_facet.html.erb | 77 +++++++++++---------- app/views/redsun_search/index.html.erb | 15 ++-- init.rb | 4 +- 5 files changed, 70 insertions(+), 55 deletions(-) diff --git a/app/controllers/redsun_search_controller.rb b/app/controllers/redsun_search_controller.rb index a7db017..6d0a446 100644 --- a/app/controllers/redsun_search_controller.rb +++ b/app/controllers/redsun_search_controller.rb @@ -90,20 +90,27 @@ def index priority_id tracker_id status_id - filetype - category_id).each do |easy_facet| - facet easy_facet, minimum_count: 1 - if params.key?(:search_form) && params[:search_form][easy_facet].present? - with(easy_facet, params[:search_form][easy_facet]) - end + category_id + filetype).each do |easy_facet| + facet_filter = if params[:search_form].key?(easy_facet) + Rails.logger.info "#{easy_facet} is in facet_filter" + with(easy_facet).any_of(params[:search_form][easy_facet]) + else + all_of {} # not necessary for searching, but object is needed to set exclude option + end + facet easy_facet, minimum_count: 1, exclude: facet_filter + #if params.key?(:search_form) && params[:search_form][easy_facet].present? + # with(easy_facet).any_of(params[:search_form][easy_facet]) + #end + end # class filter class_filter = if params[:search_form].key?(:class_name) - with(:class_name).any_of(params[:search_form][:class_name]) - else - all_of {} # not necessary for searching, but object is needed to set exclude option - end + with(:class_name).any_of(params[:search_form][:class_name]) + else + all_of {} # not necessary for searching, but object is needed to set exclude option + end facet :class_name, minimum_count: 1, exclude: class_filter # exclude option gives access to full list of items %w(created_on updated_on).each do |date_facet| diff --git a/app/helpers/redsun_search_helper.rb b/app/helpers/redsun_search_helper.rb index e7d001c..60b3da5 100644 --- a/app/helpers/redsun_search_helper.rb +++ b/app/helpers/redsun_search_helper.rb @@ -6,7 +6,7 @@ def facet(name, results, attribute = nil, partial = 'facet') def selected_attr_for(facet, val) if params[:search_form] && params[:search_form][facet.to_sym] - "selected" if params[:search_form][facet.to_sym] == val.to_s + "selected" if val.to_s.in?(params[:search_form][facet.to_sym]) end end diff --git a/app/views/redsun_search/_facet.html.erb b/app/views/redsun_search/_facet.html.erb index f76ee8e..90baa65 100644 --- a/app/views/redsun_search/_facet.html.erb +++ b/app/views/redsun_search/_facet.html.erb @@ -1,42 +1,45 @@ <% if results.facet(facet).present? && results.facet(facet).rows && results.facet(facet).rows.count > 1 || params[:search_form][facet].present? %>

<%= t("redsun.facet.#{facet}")%>

-<% if search2_enabled? %> - - <% else %> -