Class: SearchFlip::Result

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/search_flip/result.rb

Overview

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

Class Method Summary collapse

Class Method Details

.disable_warnings?(*args) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/search_flip/result.rb', line 6

def self.disable_warnings?(*args)
  true
end

.from_hit(hit) ⇒ Object

Creates a SearchFlip::Result object from a raw hit. Useful for e.g. top hits aggregations.

Examples:

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)


19
20
21
22
23
24
25
26
27
# File 'lib/search_flip/result.rb', line 19

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