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.4.27 app/queries/workarea/search/facet.rb
workarea-core-3.5.4 app/queries/workarea/search/facet.rb
workarea-core-3.4.26 app/queries/workarea/search/facet.rb
workarea-core-3.5.3 app/queries/workarea/search/facet.rb
workarea-core-3.4.25 app/queries/workarea/search/facet.rb
workarea-core-3.5.2 app/queries/workarea/search/facet.rb
workarea-core-3.4.24 app/queries/workarea/search/facet.rb
workarea-core-3.5.1 app/queries/workarea/search/facet.rb
workarea-core-3.4.23 app/queries/workarea/search/facet.rb
workarea-core-3.4.22 app/queries/workarea/search/facet.rb
workarea-core-3.5.0 app/queries/workarea/search/facet.rb
workarea-core-3.4.21 app/queries/workarea/search/facet.rb
workarea-core-3.5.0.beta.1 app/queries/workarea/search/facet.rb
workarea-core-3.4.20 app/queries/workarea/search/facet.rb
workarea-core-3.4.19 app/queries/workarea/search/facet.rb
workarea-core-3.4.18 app/queries/workarea/search/facet.rb
workarea-core-3.4.17 app/queries/workarea/search/facet.rb
workarea-core-3.4.16 app/queries/workarea/search/facet.rb
workarea-core-3.4.15 app/queries/workarea/search/facet.rb
workarea-core-3.4.14 app/queries/workarea/search/facet.rb