Class: Slingshot::Results::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/slingshot/results/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Collection

Returns a new instance of Collection.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slingshot/results/collection.rb', line 8

def initialize(response)
  @time    = response['took']
  @total   = response['hits']['total']
  @results = response['hits']['hits'].map do |h|
               if Configuration.wrapper == Hash
                 h
               else
                 document = h['_source'] ? h['_source'] : h['fields']
                 document['highlight'] = h['highlight'] if h['highlight']
                 h.update document if document
                 Configuration.wrapper.new(h)
               end
             end
  @facets  = response['facets']
end

Instance Attribute Details

#facetsObject (readonly)

Returns the value of attribute facets.



6
7
8
# File 'lib/slingshot/results/collection.rb', line 6

def facets
  @facets
end

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/slingshot/results/collection.rb', line 6

def results
  @results
end

#timeObject (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/slingshot/results/collection.rb', line 6

def time
  @time
end

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'lib/slingshot/results/collection.rb', line 6

def total
  @total
end

Instance Method Details

#each(&block) ⇒ Object



24
25
26
# File 'lib/slingshot/results/collection.rb', line 24

def each(&block)
  @results.each(&block)
end