Class: Tire::Count

Inherits:
Search show all
Defined in:
lib/tire/count.rb

Instance Attribute Summary

Attributes inherited from Search

#indices, #payload, #payload_hash

Instance Method Summary collapse

Methods inherited from Search

#logged, #perform, #response, #to_curl, #to_hash, #url

Constructor Details

#initialize(indices, types, payload) ⇒ Count

Returns a new instance of Count.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tire/count.rb', line 7

def initialize(indices, types, payload)
  @indices = Array(indices)
  @types   = Array(types).map { |type| Utils.escape(type) }
  if payload.is_a?(String)
    @payload = payload
  else
    @payload_hash = payload
  end

  @path    = ['/', @indices.join(','), @types.join(','), '_count'].compact.join('/').squeeze('/')
  if indices == 'blog'
    @path += '?preference=_local'
  end
end

Instance Method Details

#resultsObject



22
23
24
25
# File 'lib/tire/count.rb', line 22

def results
  perform
  return @json["totalHits"]
end