Sha256: c06a01b4b221b4cca2b15785b105beec675bc8455d112b8e3603b0a9458aa7c4

Contents?: true

Size: 837 Bytes

Versions: 13

Compression:

Stored size: 837 Bytes

Contents

module SearchFlip
  # The SearchFlip::Result class basically is a hash wrapper that uses
  # Hashie::Mash to provide convenient method access to the hash attributes.

  class Result < Hashie::Mash
    def self.disable_warnings?(*args)
      true
    end

    # Creates a SearchFlip::Result object from a raw hit. Useful for e.g.
    # top hits aggregations.
    #
    # @example
    #   query = ProductIndex.aggregate(top_sales: { top_hits: "..." })
    #   top_sales_hits = query.aggregations(:top_sales).top_hits.hits.hits
    #
    #   SearchFlip::Result.from_hit(top_sales_hits.first)

    def self.from_hit(hit)
      raw_result = (hit["_source"] || {}).dup

      raw_result["_hit"] = hit.each_with_object({}) do |(key, value), hash|
        hash[key] = value if key != "_source"
      end

      new(raw_result)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
search_flip-3.9.0 lib/search_flip/result.rb
search_flip-3.8.0 lib/search_flip/result.rb
search_flip-3.7.2 lib/search_flip/result.rb
search_flip-3.7.1 lib/search_flip/result.rb
search_flip-3.7.0 lib/search_flip/result.rb
search_flip-3.6.0 lib/search_flip/result.rb
search_flip-3.5.0 lib/search_flip/result.rb
search_flip-3.4.0 lib/search_flip/result.rb
search_flip-3.3.0 lib/search_flip/result.rb
search_flip-3.2.1 lib/search_flip/result.rb
search_flip-3.2.0 lib/search_flip/result.rb
search_flip-3.1.2 lib/search_flip/result.rb
search_flip-3.1.1 lib/search_flip/result.rb