search_flip 3.4.0 → 3.5.0
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/CHANGELOG.md +5 -0
- data/README.md +8 -0
- data/lib/search_flip.rb +8 -3
- data/lib/search_flip/criteria.rb +28 -7
- data/lib/search_flip/http_client.rb +4 -0
- data/lib/search_flip/index.rb +1 -1
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/criteria_spec.rb +29 -6
- data/spec/search_flip/index_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b534f2309a3433637b7e8c661d098bcbb04aa6c047655ad3c4ab944cbb860bf7
|
|
4
|
+
data.tar.gz: ec32a8f3ef761bb9d1f4dd99e1e31448b5eceb88a40643c63cada7bc4bedeaa7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad28e9a932ad4a572bb401593e1d0c9551d2aeb7e128ffad6d1c237f8e78f7a5385a2e94e4a113ae47bcc4576c07bfc74ab24bcbc2d65e8e7f2751951b5d09da
|
|
7
|
+
data.tar.gz: 73c88dc39c4709dc716f3a45428771c08ce83ec51b278bcbd1285663e5cdafc2c66181b61ad78ee741feb2963bde607916ddaab8ffe8ec35124e695d37f287b7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -698,6 +698,14 @@ Specify a timeout to limit query processing time:
|
|
|
698
698
|
CommentIndex.timeout("3s").execute
|
|
699
699
|
```
|
|
700
700
|
|
|
701
|
+
* `http_timeout`
|
|
702
|
+
|
|
703
|
+
Specify a http timeout for the request which will be send to Elasticsearch:
|
|
704
|
+
|
|
705
|
+
```ruby
|
|
706
|
+
CommentIndex.http_timeout(3).execute
|
|
707
|
+
```
|
|
708
|
+
|
|
701
709
|
* `terminate_after`
|
|
702
710
|
|
|
703
711
|
Activate early query termination to stop query processing after the specified
|
data/lib/search_flip.rb
CHANGED
|
@@ -33,10 +33,15 @@ require "search_flip/index"
|
|
|
33
33
|
require "search_flip/model"
|
|
34
34
|
|
|
35
35
|
module SearchFlip
|
|
36
|
-
class
|
|
37
|
-
class ConnectionError < StandardError; end
|
|
36
|
+
class Error < StandardError; end
|
|
38
37
|
|
|
39
|
-
class
|
|
38
|
+
class NotSupportedError < Error; end
|
|
39
|
+
|
|
40
|
+
class HttpError < Error; end
|
|
41
|
+
class ConnectionError < HttpError; end
|
|
42
|
+
class TimeoutError < HttpError; end
|
|
43
|
+
|
|
44
|
+
class ResponseError < Error
|
|
40
45
|
attr_reader :code, :body
|
|
41
46
|
|
|
42
47
|
def initialize(code:, body:)
|
data/lib/search_flip/criteria.rb
CHANGED
|
@@ -26,7 +26,8 @@ module SearchFlip
|
|
|
26
26
|
|
|
27
27
|
attr_accessor :target, :profile_value, :source_value, :suggest_values, :includes_values,
|
|
28
28
|
:eager_load_values, :preload_values, :failsafe_value, :scroll_args, :terminate_after_value,
|
|
29
|
-
:timeout_value, :preference_value, :search_type_value, :routing_value, :track_total_hits_value
|
|
29
|
+
:timeout_value, :preference_value, :search_type_value, :routing_value, :track_total_hits_value,
|
|
30
|
+
:http_timeout_value
|
|
30
31
|
|
|
31
32
|
# Creates a new criteria while merging the attributes (constraints,
|
|
32
33
|
# settings, etc) of the current criteria with the attributes of another one
|
|
@@ -47,7 +48,7 @@ module SearchFlip
|
|
|
47
48
|
[
|
|
48
49
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value,
|
|
49
50
|
:limit_value, :scroll_args, :source_value, :preference_value, :search_type_value,
|
|
50
|
-
:routing_value, :track_total_hits_value, :explain_value
|
|
51
|
+
:routing_value, :track_total_hits_value, :explain_value, :http_timeout_value
|
|
51
52
|
].each do |name|
|
|
52
53
|
criteria.send(:"#{name}=", other.send(name)) unless other.send(name).nil?
|
|
53
54
|
end
|
|
@@ -148,6 +149,22 @@ module SearchFlip
|
|
|
148
149
|
end
|
|
149
150
|
end
|
|
150
151
|
|
|
152
|
+
# Specifies a http timeout, such that a SearchFlip::TimeoutError will be
|
|
153
|
+
# thrown when the request times out.
|
|
154
|
+
#
|
|
155
|
+
# @example
|
|
156
|
+
# ProductIndex.http_timeout(3).search("hello world")
|
|
157
|
+
#
|
|
158
|
+
# @param value [Fixnum] The timeout value
|
|
159
|
+
#
|
|
160
|
+
# @return [SearchFlip::Criteria] A newly created extended criteria
|
|
161
|
+
|
|
162
|
+
def http_timeout(value)
|
|
163
|
+
fresh.tap do |criteria|
|
|
164
|
+
criteria.http_timeout_value = value
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
151
168
|
# Specifies early query termination, such that the processing will be
|
|
152
169
|
# stopped after the specified number of results has been accumulated.
|
|
153
170
|
#
|
|
@@ -330,10 +347,13 @@ module SearchFlip
|
|
|
330
347
|
dupped_request.delete(:from)
|
|
331
348
|
dupped_request.delete(:size)
|
|
332
349
|
|
|
350
|
+
http_request = connection.http_client
|
|
351
|
+
http_request = http_request.timeout(http_timeout_value) if http_timeout_value
|
|
352
|
+
|
|
333
353
|
if connection.version.to_i >= 5
|
|
334
|
-
|
|
354
|
+
http_request.post("#{target.type_url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
|
|
335
355
|
else
|
|
336
|
-
|
|
356
|
+
http_request.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request)
|
|
337
357
|
end
|
|
338
358
|
|
|
339
359
|
target.refresh if SearchFlip::Config[:auto_refresh]
|
|
@@ -501,8 +521,8 @@ module SearchFlip
|
|
|
501
521
|
end
|
|
502
522
|
|
|
503
523
|
# Executes the search request for the current criteria, ie sends the
|
|
504
|
-
# request to Elasticsearch and returns the response. Connection
|
|
505
|
-
# response errors will be rescued if you specify the criteria to be
|
|
524
|
+
# request to Elasticsearch and returns the response. Connection, timeout
|
|
525
|
+
# and response errors will be rescued if you specify the criteria to be
|
|
506
526
|
# #failsafe, such that an empty response is returned instead.
|
|
507
527
|
#
|
|
508
528
|
# @example
|
|
@@ -590,6 +610,7 @@ module SearchFlip
|
|
|
590
610
|
|
|
591
611
|
def execute!
|
|
592
612
|
http_request = connection.http_client.headers(accept: "application/json")
|
|
613
|
+
http_request = http_request.timeout(http_timeout_value) if http_timeout_value
|
|
593
614
|
|
|
594
615
|
http_response =
|
|
595
616
|
if scroll_args && scroll_args[:id]
|
|
@@ -609,7 +630,7 @@ module SearchFlip
|
|
|
609
630
|
end
|
|
610
631
|
|
|
611
632
|
SearchFlip::Response.new(self, SearchFlip::JSON.parse(http_response.to_s))
|
|
612
|
-
rescue SearchFlip::ConnectionError, SearchFlip::ResponseError => e
|
|
633
|
+
rescue SearchFlip::ConnectionError, SearchFlip::TimeoutError, SearchFlip::ResponseError => e
|
|
613
634
|
raise e unless failsafe_value
|
|
614
635
|
|
|
615
636
|
SearchFlip::Response.new(self, "took" => 0, "hits" => { "total" => 0, "hits" => [] })
|
|
@@ -66,6 +66,10 @@ module SearchFlip
|
|
|
66
66
|
response
|
|
67
67
|
rescue HTTP::ConnectionError => e
|
|
68
68
|
raise SearchFlip::ConnectionError, e.message
|
|
69
|
+
rescue HTTP::TimeoutError => e
|
|
70
|
+
raise SearchFlip::TimeoutError, e.message
|
|
71
|
+
rescue HTTP::Error => e
|
|
72
|
+
raise SearchFlip::HttpError, e.message
|
|
69
73
|
end
|
|
70
74
|
end
|
|
71
75
|
end
|
data/lib/search_flip/index.rb
CHANGED
|
@@ -254,7 +254,7 @@ module SearchFlip
|
|
|
254
254
|
:page, :per, :search, :highlight, :suggest, :custom, :find_in_batches, :find_results_in_batches,
|
|
255
255
|
:find_each, :find_each_result, :failsafe, :total_entries, :total_count, :timeout, :terminate_after,
|
|
256
256
|
:records, :results, :must, :must_not, :should, :preference, :search_type, :routing,
|
|
257
|
-
:track_total_hits, :explain
|
|
257
|
+
:track_total_hits, :explain, :http_timeout
|
|
258
258
|
|
|
259
259
|
# Override to specify the type name used within Elasticsearch. Recap,
|
|
260
260
|
# this gem uses an individual index for each index class, because
|
data/lib/search_flip/version.rb
CHANGED
|
@@ -97,7 +97,8 @@ RSpec.describe SearchFlip::Criteria do
|
|
|
97
97
|
methods = [
|
|
98
98
|
:profile_value, :failsafe_value, :terminate_after_value, :timeout_value,
|
|
99
99
|
:offset_value, :limit_value, :scroll_args, :source_value, :preference_value,
|
|
100
|
-
:search_type_value, :routing_value, :track_total_hits_value, :explain_value
|
|
100
|
+
:search_type_value, :routing_value, :track_total_hits_value, :explain_value,
|
|
101
|
+
:http_timeout_value
|
|
101
102
|
]
|
|
102
103
|
|
|
103
104
|
methods.each do |method|
|
|
@@ -191,6 +192,22 @@ RSpec.describe SearchFlip::Criteria do
|
|
|
191
192
|
end
|
|
192
193
|
end
|
|
193
194
|
|
|
195
|
+
describe "#http_timeout" do
|
|
196
|
+
it "sets the query timeout" do
|
|
197
|
+
http_client = double("client").as_null_object
|
|
198
|
+
allow(http_client).to receive(:timeout).and_return(http_client)
|
|
199
|
+
allow(http_client).to receive(:post).and_raise(SearchFlip::TimeoutError)
|
|
200
|
+
allow(ProductIndex.connection).to receive(:http_client).and_return(http_client)
|
|
201
|
+
|
|
202
|
+
expect { ProductIndex.http_timeout(1).execute }.to raise_error(SearchFlip::TimeoutError)
|
|
203
|
+
expect(http_client).to have_received(:timeout).with(1)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "executes without errors" do
|
|
207
|
+
expect { ProductIndex.http_timeout(1).execute }.not_to raise_error
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
194
211
|
describe "#terminate_after" do
|
|
195
212
|
it "sets the terminate after value" do
|
|
196
213
|
query = ProductIndex.terminate_after(1)
|
|
@@ -1204,13 +1221,19 @@ RSpec.describe SearchFlip::Criteria do
|
|
|
1204
1221
|
end
|
|
1205
1222
|
|
|
1206
1223
|
describe "#failsafe" do
|
|
1207
|
-
|
|
1208
|
-
|
|
1224
|
+
[SearchFlip::ConnectionError, SearchFlip::TimeoutError, SearchFlip::ResponseError.new(code: "code", body: "body")].each do |error|
|
|
1225
|
+
it "prevents #{error}" do
|
|
1226
|
+
http_client = double("client").as_null_object
|
|
1227
|
+
allow(http_client).to receive(:post).and_raise(error)
|
|
1228
|
+
allow(ProductIndex.connection).to receive(:http_client).and_return(http_client)
|
|
1229
|
+
|
|
1230
|
+
expect { ProductIndex.all.execute }.to raise_error(error)
|
|
1209
1231
|
|
|
1210
|
-
|
|
1232
|
+
query = ProductIndex.failsafe(true)
|
|
1211
1233
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1234
|
+
expect(query.records).to eq([])
|
|
1235
|
+
expect(query.total_entries).to eq(0)
|
|
1236
|
+
end
|
|
1214
1237
|
end
|
|
1215
1238
|
end
|
|
1216
1239
|
|
|
@@ -14,7 +14,7 @@ RSpec.describe SearchFlip::Index do
|
|
|
14
14
|
:total_entries, :total_count, :terminate_after, :timeout, :records, :results,
|
|
15
15
|
:must, :must_not, :should, :find_each_result,
|
|
16
16
|
:find_results_in_batches, :preference, :search_type, :routing,
|
|
17
|
-
:track_total_hits, :explain
|
|
17
|
+
:track_total_hits, :explain, :http_timeout
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
methods.each do |method|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: search_flip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Vetter
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|