Class: Tire::Search
- Inherits:
-
Object
- Object
- Tire::Search
- Defined in:
- lib/tire/search.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#indices ⇒ Object
readonly
Returns the value of attribute indices.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#payload_hash ⇒ Object
readonly
Returns the value of attribute payload_hash.
Instance Method Summary collapse
-
#initialize(indices, types, payload) ⇒ Search
constructor
A new instance of Search.
- #logged(error = nil) ⇒ Object
- #perform ⇒ Object
- #response ⇒ Object
- #results ⇒ Object
- #to_curl ⇒ Object
- #to_hash ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(indices, types, payload) ⇒ Search
Returns a new instance of Search.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tire/search.rb', line 9 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(','), '_search'].compact.join('/').squeeze('/') if indices == 'blog' @path += '?preference=_local' end end |
Instance Attribute Details
#indices ⇒ Object (readonly)
Returns the value of attribute indices.
7 8 9 |
# File 'lib/tire/search.rb', line 7 def indices @indices end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/tire/search.rb', line 7 def payload @payload end |
#payload_hash ⇒ Object (readonly)
Returns the value of attribute payload_hash.
7 8 9 |
# File 'lib/tire/search.rb', line 7 def payload_hash @payload_hash end |
Instance Method Details
#logged(error = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tire/search.rb', line 60 def logged(error=nil) if Configuration.logger Configuration.logger.log_request '_search', indices, to_curl code = @response.code rescue nil if Configuration.logger.level.to_s == 'debug' # FIXME: Depends on RestClient implementation body = if @json defined?(Yajl) ? Yajl::Encoder.encode(@json, :pretty => true) : MultiJson.encode(@json) else @response.body rescue nil end else body = '' end Configuration.logger.log_response code || 'N/A', "N/A", body || 'N/A' end end |
#perform ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tire/search.rb', line 36 def perform @response = Configuration.client.get(self.url, self.payload) if @response.failure? STDERR.puts "[REQUEST FAILED] #{self.to_curl}\n" raise SearchRequestFailed, @response.to_s end @json = MultiJson.decode(@response.body) return @json ensure logged end |
#response ⇒ Object
28 29 30 |
# File 'lib/tire/search.rb', line 28 def response @response || (perform; @response) end |
#results ⇒ Object
24 25 26 |
# File 'lib/tire/search.rb', line 24 def results @json || (perform; @json) end |
#to_curl ⇒ Object
48 49 50 |
# File 'lib/tire/search.rb', line 48 def to_curl %Q|curl -X GET #{url} -d '#{payload}'| end |
#to_hash ⇒ Object
56 57 58 |
# File 'lib/tire/search.rb', line 56 def to_hash @hash_payload ||= MultiJson.decode(payload) end |
#url ⇒ Object
32 33 34 |
# File 'lib/tire/search.rb', line 32 def url Configuration.url + @path end |