Sha256: 2e91e22492c308a4f6cb3a3cfd23377455bb55e86da1efb962443bfa8e271c9b

Contents?: true

Size: 1.28 KB

Versions: 62

Compression:

Stored size: 1.28 KB

Contents

module Workarea
  module Search
    class RangeFacet < Facet
      def type
        :range
      end

      def post_filter_clause
        return unless selections.present?

        {
          bool: {
            should: selections
                      .map { |s| RangeParameter.new(s).to_filter }
                      .map { |f| { range: { "numeric.#{system_name}" => f } } }
          }
        }
      end

      def aggregation
        {
          system_name => {
            filter: aggregation_filter,
            aggs: {
              system_name => {
                range: { field: "numeric.#{system_name}", ranges: options }
              }
            }
          }
        }
      end

      def results
        results = search.response.dig(
          'aggregations',
          system_name,
          system_name,
          'buckets'
        )

        results ||= []

        results.reduce({}) do |memo, result|
          if result['doc_count'] > 0
            key = {}
            key[:from] = result['from'] if result['from'].present?
            key[:to] = result['to'] if result['to'].present?
            memo[key] = result['doc_count']
          end

          memo
        end
      end

      def value_to_param(value)
        RangeParameter.to_param(value)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.26 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.45 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.25 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.23 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.44 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.22 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.43 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.21 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.42 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.20 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.41 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.19 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.40 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.18 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.39 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.17 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.38 app/queries/workarea/search/range_facet.rb
workarea-core-3.5.16 app/queries/workarea/search/range_facet.rb
workarea-core-3.4.37 app/queries/workarea/search/range_facet.rb