Sha256: 3e57f3e7d91f8bb896714ec234e2526afe0adfef999adf68432fab8908a245d0

Contents?: true

Size: 829 Bytes

Versions: 7

Compression:

Stored size: 829 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

7 entries across 7 versions & 1 rubygems

Version Path
search_flip-3.1.0 lib/search_flip/result.rb
search_flip-3.0.0 lib/search_flip/result.rb
search_flip-3.0.0.beta6 lib/search_flip/result.rb
search_flip-3.0.0.beta5 lib/search_flip/result.rb
search_flip-3.0.0.beta4 lib/search_flip/result.rb
search_flip-3.0.0.beta3 lib/search_flip/result.rb
search_flip-3.0.0.beta2 lib/search_flip/result.rb