stretcher 1.21.0 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/stretcher/es_component.rb +3 -3
- data/lib/stretcher/index_type.rb +1 -1
- data/lib/stretcher/server.rb +11 -7
- data/lib/stretcher/version.rb +1 -1
- data/spec/lib/stretcher_index_spec.rb +2 -2
- data/spec/lib/stretcher_search_results_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68796baf58beb2f78fd3383919e0cd94d824aff8
|
4
|
+
data.tar.gz: 2d3bdb627625a7f5c427d30c9b6a31bae18d9bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/stretcher/index_type.rb
CHANGED
@@ -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
|
data/lib/stretcher/server.rb
CHANGED
@@ -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
|
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}"
|
data/lib/stretcher/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|