Sha256: b9c1edcfde4c80676f75a8f5c0a64eeb89e603c16498a1ccfc9fab106f622413

Contents?: true

Size: 1.6 KB

Versions: 62

Compression:

Stored size: 1.6 KB

Contents

module Workarea
  module Search
    class Facet < Filter

      def selections
        Array(params[system_name]).reject(&:blank?)
      end

      def aggregation_filter
        {
          bool: {
            must: search
                    .facets
                    .reject { |f| f.system_name == system_name }
                    .map(&:post_filter_clause)
                    .reject(&:blank?)
          }
        }
      end

      def useless?
        selections.blank? &&
          (results.empty? || (results.one? && results.first.last == total))
      end

      def selected?(value = nil)
        return false if selections.blank?
        value.blank? || selections.include?(value_to_param(value))
      end

      def params_for(value)
        value = value_to_param(value)
        result = valid_params

        if selected?(value) && result[system_name].present?
          result[system_name].delete(value)
        else
          result[system_name] = Array(result[system_name])
          result[system_name] << value
        end

        result.delete_if { |_, v| v.blank? }
      end

      def query_clause
        # no op, facets will be applied in post_filter to allow aggregation
        # to display all options without being affected by selections.
      end

      def type
        raise NotImplementedError
      end

      def aggregation
        raise NotImplementedError
      end

      def post_filter_clause
        raise NotImplementedError
      end

      def results
        raise NotImplementedError
      end

      def value_to_param(value)
        raise NotImplementedError
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/queries/workarea/search/facet.rb
workarea-core-3.4.36 app/queries/workarea/search/facet.rb
workarea-core-3.5.14 app/queries/workarea/search/facet.rb
workarea-core-3.4.35 app/queries/workarea/search/facet.rb
workarea-core-3.5.13 app/queries/workarea/search/facet.rb
workarea-core-3.4.34 app/queries/workarea/search/facet.rb
workarea-core-3.5.12 app/queries/workarea/search/facet.rb
workarea-core-3.4.33 app/queries/workarea/search/facet.rb
workarea-core-3.5.11 app/queries/workarea/search/facet.rb
workarea-core-3.5.10 app/queries/workarea/search/facet.rb
workarea-core-3.4.32 app/queries/workarea/search/facet.rb
workarea-core-3.5.9 app/queries/workarea/search/facet.rb
workarea-core-3.4.31 app/queries/workarea/search/facet.rb
workarea-core-3.5.8 app/queries/workarea/search/facet.rb
workarea-core-3.4.30 app/queries/workarea/search/facet.rb
workarea-core-3.5.7 app/queries/workarea/search/facet.rb
workarea-core-3.4.29 app/queries/workarea/search/facet.rb
workarea-core-3.5.6 app/queries/workarea/search/facet.rb
workarea-core-3.4.28 app/queries/workarea/search/facet.rb
workarea-core-3.5.5 app/queries/workarea/search/facet.rb