stretcher 1.21.0 → 1.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85bcaf96526c898dbcdf9787e6ae41fbf8d88be5
4
- data.tar.gz: 668a0bbe9a04ec5e69c2b3d62b771449d59f4588
3
+ metadata.gz: 68796baf58beb2f78fd3383919e0cd94d824aff8
4
+ data.tar.gz: 2d3bdb627625a7f5c427d30c9b6a31bae18d9bd9
5
5
  SHA512:
6
- metadata.gz: 113de685c58e2350fbf8cd1eaa00c46393fa20d33f681ddbfb0540a568ffe564911bf59fc0b05d909c3c6c9ebc3019a10e2de4c5f2c117b5a5ead116c058c211
7
- data.tar.gz: 419d71e6f5c7549d8740a39601d03577b5cdc14173474ecc231d9e861b435a088f93ba9f9ad6f5964b331e1af9d95f3e67c0faee72195959cd9391cf76cc86f3
6
+ metadata.gz: 95b20ad5885ee1790e052587cdd77e2f2acf45d42f7c14236ce1ed8928177718f589ae683989df07891a350e265b2ed51e02e5b6129beac244ba0d88ba64c60d
7
+ data.tar.gz: 2b4927fdb72f53db78b638973a7f93a56d8f16ad6e50891c66c9fd79cdc33e43dabab5b48371768abdadec26ce52af448d4e772ebd8a72ae13b04b554e7fdb10
@@ -15,7 +15,7 @@ module Stretcher
15
15
  body = generic_opts
16
16
  end
17
17
 
18
- response = request(:get, "_search", query_opts) do |req|
18
+ response = request(:get, "_search", query_opts, nil, {}, :mashify => false) do |req|
19
19
  req.body = body
20
20
  end
21
21
  SearchResults.new(response)
@@ -25,10 +25,10 @@ module Stretcher
25
25
  request(:post, "_refresh")
26
26
  end
27
27
 
28
- def request(method, path=nil, params={}, body=nil, headers={}, &block)
28
+ def request(method, path=nil, params={}, body=nil, headers={}, options={}, &block)
29
29
  prefixed_path = path_uri(path)
30
30
  raise "Cannot issue request, no server specified!" unless @server
31
- @server.request(method, prefixed_path, params, body, headers, &block)
31
+ @server.request(method, prefixed_path, params, body, headers, options, &block)
32
32
  end
33
33
 
34
34
  def do_delete_query(query)
@@ -85,7 +85,7 @@ module Stretcher
85
85
  # See http://www.elasticsearch.org/guide/reference/api/more-like-this/ for more
86
86
  # Takens an options hash as a second argument, for things like fields=
87
87
  def mlt(id, options={})
88
- SearchResults.new(request(:get, "#{id}/_mlt", options))
88
+ SearchResults.new(request(:get, "#{id}/_mlt", options, nil, {}, :mashify => false))
89
89
  end
90
90
 
91
91
  # Retrieve the mapping for this type
@@ -6,7 +6,6 @@ module Stretcher
6
6
  # Returns a properly configured HTTP client when initializing an instance
7
7
  def self.build_client(uri_components, options={})
8
8
  http = Faraday.new(:url => uri_components) do |builder|
9
- builder.response :mashify
10
9
  builder.response :multi_json, :content_type => /\bjson$/
11
10
 
12
11
  builder.request :multi_json
@@ -139,9 +138,9 @@ module Stretcher
139
138
  raise ArgumentError, "msearch takes an array!" unless body.is_a?(Array)
140
139
  fmt_body = body.map {|l| MultiJson.dump(l) }.join("\n") << "\n"
141
140
 
142
- res = request(:get, path_uri("/_msearch"), {}, fmt_body)
141
+ res = request(:get, path_uri("/_msearch"), {}, fmt_body, {}, :mashify => false)
143
142
 
144
- errors = res.responses.map(&:error).compact
143
+ errors = res['responses'].map { |response| response['error'] }.compact
145
144
  if !errors.empty?
146
145
  raise RequestError.new(res), "Could not msearch #{errors.inspect}"
147
146
  end
@@ -213,7 +212,8 @@ module Stretcher
213
212
 
214
213
  # Handy way to query the server, returning *only* the body
215
214
  # Will raise an exception when the status is not in the 2xx range
216
- def request(method, path, params={}, body=nil, headers={}, &block)
215
+ def request(method, path, params={}, body=nil, headers={}, options={}, &block)
216
+ options = { :mashify => true }.merge(options)
217
217
  req = http.build_request(method)
218
218
  req.path = path
219
219
  req.params.update(Util.clean_params(params)) if params
@@ -224,7 +224,7 @@ module Stretcher
224
224
 
225
225
  @request_mtx.synchronize {
226
226
  env = req.to_env(http)
227
- check_response(http.app.call(env))
227
+ check_response(http.app.call(env), options)
228
228
  }
229
229
  end
230
230
 
@@ -233,9 +233,13 @@ module Stretcher
233
233
 
234
234
  # Internal use only
235
235
  # Check response codes from request
236
- def check_response(res)
236
+ def check_response(res, options)
237
237
  if res.status >= 200 && res.status <= 299
238
- res.body
238
+ if(options[:mashify] && res.body.instance_of?(Hash))
239
+ Hashie::Mash.new(res.body)
240
+ else
241
+ res.body
242
+ end
239
243
  elsif [404, 410].include? res.status
240
244
  err_str = "Error processing request: (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}"
241
245
  err_str << "\n Resp Body: #{res.body}"
@@ -1,3 +1,3 @@
1
1
  module Stretcher
2
- VERSION = "1.21.0"
2
+ VERSION = "1.21.1"
3
3
  end
@@ -235,7 +235,7 @@ describe Stretcher::Index do
235
235
 
236
236
  context "with no options" do
237
237
  it "calls request for the correct endpoint with empty options" do
238
- expect(index.server).to receive(:request).with(:post, request_url, nil, nil, {})
238
+ expect(index.server).to receive(:request).with(:post, request_url, nil, nil, {}, {})
239
239
  index.optimize
240
240
  end
241
241
 
@@ -246,7 +246,7 @@ describe Stretcher::Index do
246
246
 
247
247
  context "with options" do
248
248
  it "calls request for the correct endpoint with options passed" do
249
- expect(index.server).to receive(:request).with(:post, request_url, {"max_num_segments" => 1}, nil, {})
249
+ expect(index.server).to receive(:request).with(:post, request_url, {"max_num_segments" => 1}, nil, {}, {})
250
250
  index.optimize("max_num_segments" => 1)
251
251
  end
252
252
 
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stretcher::SearchResults do
4
+ let(:server) {
5
+ Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER)
6
+ }
7
+ let(:index) { ensure_test_index(server, :foo) }
8
+
4
9
  let(:result) do
5
10
  Hashie::Mash.new({
6
11
  'facets' => [],
@@ -53,4 +58,18 @@ describe Stretcher::SearchResults do
53
58
  its(:_id) { should == 2 }
54
59
  its(:_highlight) { should == {'message.*' => ["meeting at <hit>protonet</hit>!"]} }
55
60
  end
61
+
62
+ context 'result object types' do
63
+ let(:search_result) {
64
+ index.search(:query => {:match_all => {}})
65
+ }
66
+
67
+ it 'returns a plain hash for raw_plain' do
68
+ search_result.raw_plain.should be_instance_of(::Hash)
69
+ end
70
+
71
+ it 'returns a hashie mash for raw' do
72
+ search_result.raw.should be_instance_of(Hashie::Mash)
73
+ end
74
+ end
56
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stretcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.0
4
+ version: 1.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Cholakian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday