Class: Gummi::Document::Search::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gummi/document/search/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Result



8
9
10
11
12
13
# File 'lib/gummi/document/search/result.rb', line 8

def initialize(result)
  @took = result["took"]
  @total = result["hits"]["total"]
  @hits = result["hits"]["hits"]
  @facets = result["facets"]
end

Instance Attribute Details

#facetsObject (readonly)

Returns the value of attribute facets.



6
7
8
# File 'lib/gummi/document/search/result.rb', line 6

def facets
  @facets
end

#hitsObject (readonly)

Returns the value of attribute hits.



6
7
8
# File 'lib/gummi/document/search/result.rb', line 6

def hits
  @hits
end

#tookObject (readonly)

Returns the value of attribute took.



6
7
8
# File 'lib/gummi/document/search/result.rb', line 6

def took
  @took
end

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'lib/gummi/document/search/result.rb', line 6

def total
  @total
end

Instance Method Details

#recordsObject



15
16
17
18
19
20
21
# File 'lib/gummi/document/search/result.rb', line 15

def records
  hits.map do |hit|
    model = "DB::#{hit["_type"].humanize}".constantize
    doc_hash = {id: hit["_id"]}.merge(hit["_source"])
    model.new(doc_hash)
  end
end