Sha256: 7f4b56c2ef29c406aeba55dfa00ebef5eca7cdedefebb0e393c29294690c17df

Contents?: true

Size: 620 Bytes

Versions: 1

Compression:

Stored size: 620 Bytes

Contents

module Elastic::Shims
  class Grouping < Base
    def handle_result(_raw)
      groups = []
      group_recursive(super.aggregations, HashWithIndifferentAccess.new, groups)
      Elastic::Results::GroupedResult.new groups
    end

    private

    def group_recursive(_agg_context, _keys, _groups)
      name, agg = _agg_context.first

      if agg.is_a? Elastic::Results::BucketCollection
        agg.each do |bucket|
          group_recursive(bucket, _keys.merge(name => bucket.key), _groups)
        end
      else
        _groups << Elastic::Results::ResultGroup.new(_keys, _agg_context)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-rails-0.5.0 lib/elastic/shims/grouping.rb