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