search_flip 3.5.0 → 4.0.0.beta

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
  SHA256:
3
- metadata.gz: b534f2309a3433637b7e8c661d098bcbb04aa6c047655ad3c4ab944cbb860bf7
4
- data.tar.gz: ec32a8f3ef761bb9d1f4dd99e1e31448b5eceb88a40643c63cada7bc4bedeaa7
3
+ metadata.gz: b023bc6411647eaecfcb8f5b0fe535379974a0824d49699dd74ef867a67c69eb
4
+ data.tar.gz: 5dc4a0439f9442811f3966e86b0c6b09d09c54450a04234c3738ae0ab7935900
5
5
  SHA512:
6
- metadata.gz: ad28e9a932ad4a572bb401593e1d0c9551d2aeb7e128ffad6d1c237f8e78f7a5385a2e94e4a113ae47bcc4576c07bfc74ab24bcbc2d65e8e7f2751951b5d09da
7
- data.tar.gz: 73c88dc39c4709dc716f3a45428771c08ce83ec51b278bcbd1285663e5cdafc2c66181b61ad78ee741feb2963bde607916ddaab8ffe8ec35124e695d37f287b7
6
+ metadata.gz: a5fc637e8c016531df22af678adcae60a4f4169e5f1d2215d52be0a0dff1111b849cb4d79ca36d6cbf315c8516bc51d543852ab5026339d59cb1f5d08ba356f7
7
+ data.tar.gz: 7cf9d55a9aca5d6d63401750d40bc656fcc345101d8ce92a300c24649e38810d399d43ff225611bbdd91a257d6cb15eee26a6c811974b987e92e72e67eded704
@@ -11,11 +11,11 @@ jobs:
11
11
  - elasticsearch:5.4
12
12
  - docker.elastic.co/elasticsearch/elasticsearch:6.7.0
13
13
  - docker.elastic.co/elasticsearch/elasticsearch:7.0.0
14
- - docker.elastic.co/elasticsearch/elasticsearch:7.11.2
14
+ - docker.elastic.co/elasticsearch/elasticsearch:7.9.0
15
15
  ruby:
16
+ - 2.5
16
17
  - 2.6
17
18
  - 2.7
18
- - 3.0
19
19
  services:
20
20
  elasticsearch:
21
21
  image: ${{ matrix.elasticsearch }}
@@ -28,7 +28,6 @@ jobs:
28
28
  - uses: actions/setup-ruby@v1
29
29
  with:
30
30
  ruby-version: ${{ matrix.ruby }}
31
- - run: gem install bundler
32
31
  - run: bundle
33
32
  - run: sleep 10
34
33
  - run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -1,14 +1,13 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 2.5
4
- SuggestExtensions: false
5
-
6
- Layout/EmptyLineBetweenDefs:
7
- EmptyLineBetweenClassDefs: false
3
+ TargetRubyVersion: 2.4
8
4
 
9
5
  Gemspec/RequiredRubyVersion:
10
6
  Enabled: false
11
7
 
8
+ Style/CaseLikeIf:
9
+ Enabled: false
10
+
12
11
  Style/ExplicitBlockArgument:
13
12
  Enabled: false
14
13
 
data/CHANGELOG.md CHANGED
@@ -1,29 +1,13 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
- ## v3.5.0
4
+ ## v4.0.0
5
5
 
6
- * Add `SearchFlip::Criteria#http_timeout` to allow specifying timeouts on
7
- a query level
8
-
9
- ## v3.4.0
10
-
11
- * Expose `Http#timeout` via `SearchFlip::HTTPClient`
12
-
13
- ## v3.3.0
14
-
15
- * Update httprb
16
- * Changed oj default options
17
- * Allow to set oj json options
18
-
19
- ## v3.2.1
20
-
21
- * Fix `refresh` having a empty body breaking in elasticsearch 7.11
22
-
23
- ## v3.2.0
24
-
25
- * Fix `index_scope` not being passed in `each_record` without block
26
- * Added `SearchFlip::Criteria#match_none`
6
+ * [BREAKING] For performance reasons, `SearchFlip::Result` now no longer
7
+ inherits `Hashie::Mash`
8
+ * It no longer supports symbol based access like `result[:id]`
9
+ * It no longer supports question mark methods like `result.title?`
10
+ * It no longer supports method based assignment like `result.some_key = "value"`
27
11
 
28
12
  ## v3.1.2
29
13
 
data/README.md CHANGED
@@ -51,7 +51,7 @@ CommentIndex.search("hello world").where(available: true).sort(id: "desc").aggre
51
51
 
52
52
  ```
53
53
 
54
- Finally, SearchFlip comes with a minimal set of dependencies.
54
+ Finally, SearchFlip comes with a minimal set of dependencies (http-rb and oj only).
55
55
 
56
56
  ## Reference Docs
57
57
 
@@ -418,14 +418,6 @@ Simply matches all documents:
418
418
  CommentIndex.match_all
419
419
  ```
420
420
 
421
- * `match_none`
422
-
423
- Simply matches none documents at all:
424
-
425
- ```ruby
426
- CommentIndex.match_none
427
- ```
428
-
429
421
  * `all`
430
422
 
431
423
  Simply returns the criteria as is or an empty criteria when called on the index
@@ -482,8 +474,8 @@ end
482
474
  ```
483
475
 
484
476
  Generally, aggregation results returned by Elasticsearch are returned as a
485
- `SearchFlip::Result`, which basically is a `Hashie::Mash`, such that you can
486
- access them via:
477
+ `SearchFlip::Result`, which basically is a Hash with method-like access, such
478
+ that you can access them via:
487
479
 
488
480
  ```ruby
489
481
  query.aggregations(:username)["mrkamel"].revenue.value
@@ -698,14 +690,6 @@ Specify a timeout to limit query processing time:
698
690
  CommentIndex.timeout("3s").execute
699
691
  ```
700
692
 
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
-
709
693
  * `terminate_after`
710
694
 
711
695
  Activate early query termination to stop query processing after the specified
@@ -764,7 +748,7 @@ end
764
748
  This allows to use different clusters per index e.g. when migrating indices to
765
749
  new versions of Elasticsearch.
766
750
 
767
- You can specify basic auth, additional headers, request timeouts, etc via:
751
+ You can specify basic auth, additional headers, etc via:
768
752
 
769
753
  ```ruby
770
754
  http_client = SearchFlip::HTTPClient.new
@@ -781,9 +765,6 @@ http_client = http_client.via("proxy.host", 8080)
781
765
  # Custom headers
782
766
  http_client = http_client.headers(key: "value")
783
767
 
784
- # Timeouts
785
- http_client = http_client.timeout(20)
786
-
787
768
  SearchFlip::Connection.new(base_url: "...", http_client: http_client)
788
769
  ```
789
770
 
@@ -893,52 +874,57 @@ Thus, if your ORM supports `.find_each`, `#id` and `#where` you are already
893
874
  good to go. Otherwise, simply add your custom implementation of those methods
894
875
  that work with whatever ORM you use.
895
876
 
896
- ## JSON
877
+ ## Date and Timestamps in JSON
897
878
 
898
- SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
899
- JSON. More concretely, SearchFlip is using:
879
+ Elasticsearch requires dates and timestamps to have one of the formats listed
880
+ here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time).
881
+
882
+ However, `JSON.generate` in ruby by default outputs something like:
900
883
 
901
884
  ```ruby
902
- Oj.dump({ key: "value" }, mode: :custom, use_to_json: true, time_format: :xmlschema, bigdecimal_as_decimal: false)
885
+ JSON.generate(time: Time.now.utc)
886
+ # => "{\"time\":\"2018-02-22 18:19:33 UTC\"}"
903
887
  ```
904
888
 
905
- The `use_to_json` option is used for maximum compatibility, most importantly
906
- when using rails `ActiveSupport::TimeWithZone` timestamps, which `oj` can not
907
- serialize natively. However, `use_to_json` adds performance overhead. You can
908
- change the json options via:
889
+ This format is not compatible with Elasticsearch by default. If you're on
890
+ Rails, ActiveSupport adds its own `#to_json` methods to `Time`, `Date`, etc.
891
+ However, ActiveSupport checks whether they are used in combination with
892
+ `JSON.generate` or not and adapt:
909
893
 
910
894
  ```ruby
911
- SearchFlip::Config[:json_options] = {
912
- mode: :custom,
913
- use_to_json: false,
914
- time_format: :xmlschema,
915
- bigdecimal_as_decimal: false
916
- }
895
+ Time.now.utc.to_json
896
+ => "\"2018-02-22T18:18:22.088Z\""
897
+
898
+ JSON.generate(time: Time.now.utc)
899
+ => "{\"time\":\"2018-02-22 18:18:59 UTC\"}"
917
900
  ```
918
901
 
919
- However, you then have to convert timestamps manually for indexation via e.g.:
902
+ SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
903
+ JSON. More concretely, SearchFlip is using:
920
904
 
921
905
  ```ruby
922
- class MyIndex
923
- # ...
906
+ Oj.dump({ key: "value" }, mode: :custom, use_to_json: true)
907
+ ```
924
908
 
925
- def self.serialize(model)
926
- {
927
- # ...
909
+ This mitigates the issues if you're on Rails:
928
910
 
929
- created_at: model.created_at.to_time
930
- }
931
- end
932
- end
911
+ ```ruby
912
+ Oj.dump(Time.now, mode: :custom, use_to_json: true)
913
+ # => "\"2018-02-22T18:21:21.064Z\""
933
914
  ```
934
915
 
935
- Please check out the oj docs for more details.
916
+ However, if you're not on Rails, you need to add `#to_json` methods to `Time`,
917
+ `Date` and `DateTime` to get proper serialization. You can either add them on
918
+ your own, via other libraries or by simply using:
919
+
920
+ ```ruby
921
+ require "search_flip/to_json"
922
+ ```
936
923
 
937
924
  ## Feature Support
938
925
 
939
926
  * for Elasticsearch 2.x, the delete-by-query plugin is required to delete
940
927
  records via queries
941
- * `#match_none` is only available with Elasticsearch >= 5
942
928
  * `#track_total_hits` is only available with Elasticsearch >= 7
943
929
 
944
930
  ## Keeping your Models and Indices in Sync
data/UPDATING.md CHANGED
@@ -1,6 +1,46 @@
1
1
 
2
2
  # Updating from previous SearchFlip versions
3
3
 
4
+ ## Update 3.x to 4.x
5
+
6
+ **[BREAKING]** For performance reasons, `SearchFlip::Result` no longer
7
+ inherits `Hashie::Mash`
8
+
9
+ * It no longer supports symbol based access like `result[:id]`
10
+
11
+ 2.x:
12
+
13
+ ```ruby
14
+ CommentIndex.match_all.results.first[:id]
15
+ CommentIndex.aggregate(:tags).aggregations(:tags).values.first[:doc_count]
16
+ ```
17
+
18
+ 3.x
19
+
20
+ ```ruby
21
+ CommentIndex.match_all.results.first["id"] # or .id
22
+ CommentIndex.aggregate(:tags).aggregations(:tags).values.first["doc_count"] # or .doc_count
23
+ ```
24
+
25
+ * It no longer supports question mark methods like `result.title?`
26
+
27
+ 2.x:
28
+
29
+ ```ruby
30
+ CommentIndex.match_all.results.first.is_published?
31
+ ```
32
+
33
+ 3.x
34
+
35
+ ```ruby
36
+ CommentIndex.match_all.results.first.is_published == true
37
+ ```
38
+
39
+ * It no longer supports method based assignment like `result.some_key = "value"`.
40
+
41
+ However, this should not have any practical implications, as changing the
42
+ results is not considered to be a common use case.
43
+
4
44
  ## Update 2.x to 3.x
5
45
 
6
46
  * **[BREAKING]** No longer pass multiple arguments to `#must`, `#must_not`,
@@ -143,7 +143,7 @@ module SearchFlip
143
143
 
144
144
  return if options[:raise] == false
145
145
 
146
- parsed_response = SearchFlip::JSON.parse(response.to_s)
146
+ parsed_response = response.parse
147
147
 
148
148
  return unless parsed_response["errors"]
149
149
 
@@ -5,12 +5,6 @@ module SearchFlip
5
5
  bulk_limit: 1_000,
6
6
  bulk_max_mb: 100,
7
7
  auto_refresh: false,
8
- instrumenter: NullInstrumenter.new,
9
- json_options: {
10
- mode: :custom,
11
- use_to_json: true,
12
- time_format: :xmlschema,
13
- bigdecimal_as_decimal: false
14
- }
8
+ instrumenter: NullInstrumenter.new
15
9
  }
16
10
  end
@@ -28,11 +28,7 @@ module SearchFlip
28
28
 
29
29
  def version
30
30
  @version_mutex.synchronize do
31
- @version ||= begin
32
- response = http_client.headers(accept: "application/json").get("#{base_url}/")
33
-
34
- SearchFlip::JSON.parse(response.to_s)["version"]["number"]
35
- end
31
+ @version ||= http_client.headers(accept: "application/json").get("#{base_url}/").parse["version"]["number"]
36
32
  end
37
33
  end
38
34
 
@@ -44,9 +40,7 @@ module SearchFlip
44
40
  # @return [Hash] The raw response
45
41
 
46
42
  def cluster_health
47
- response = http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health")
48
-
49
- SearchFlip::JSON.parse(response.to_s)
43
+ http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health").parse
50
44
  end
51
45
 
52
46
  # Uses the Elasticsearch Multi Search API to execute multiple search requests
@@ -96,11 +90,10 @@ module SearchFlip
96
90
  # @return [Hash] The raw response
97
91
 
98
92
  def update_aliases(payload)
99
- response = http_client
93
+ http_client
100
94
  .headers(accept: "application/json", content_type: "application/json")
101
95
  .post("#{base_url}/_aliases", body: SearchFlip::JSON.generate(payload))
102
-
103
- SearchFlip::JSON.parse(response.to_s)
96
+ .parse
104
97
  end
105
98
 
106
99
  # Sends an analyze request to Elasticsearch. Raises
@@ -112,11 +105,10 @@ module SearchFlip
112
105
  # @return [Hash] The raw response
113
106
 
114
107
  def analyze(request, params = {})
115
- response = http_client
108
+ http_client
116
109
  .headers(accept: "application/json")
117
110
  .post("#{base_url}/_analyze", json: request, params: params)
118
-
119
- SearchFlip::JSON.parse(response.to_s)
111
+ .parse
120
112
  end
121
113
 
122
114
  # Fetches information about the specified index aliases. Raises
@@ -132,11 +124,10 @@ module SearchFlip
132
124
  # @return [Hash] The raw response
133
125
 
134
126
  def get_aliases(index_name: "*", alias_name: "*")
135
- response = http_client
127
+ http_client
136
128
  .headers(accept: "application/json", content_type: "application/json")
137
129
  .get("#{base_url}/#{index_name}/_alias/#{alias_name}")
138
-
139
- SearchFlip::JSON.parse(response.to_s)
130
+ .parse
140
131
  end
141
132
 
142
133
  # Returns whether or not the associated Elasticsearch alias already
@@ -168,11 +159,10 @@ module SearchFlip
168
159
  # @return [Array] The raw response
169
160
 
170
161
  def get_indices(name = "*", params: {})
171
- response = http_client
162
+ http_client
172
163
  .headers(accept: "application/json", content_type: "application/json")
173
164
  .get("#{base_url}/_cat/indices/#{name}", params: params)
174
-
175
- SearchFlip::JSON.parse(response.to_s)
165
+ .parse
176
166
  end
177
167
 
178
168
  alias_method :cat_indices, :get_indices
@@ -269,11 +259,10 @@ module SearchFlip
269
259
  # @return [Hash] The index settings
270
260
 
271
261
  def get_index_settings(index_name)
272
- response = http_client
262
+ http_client
273
263
  .headers(accept: "application/json")
274
264
  .get("#{index_url(index_name)}/_settings")
275
-
276
- SearchFlip::JSON.parse(response.to_s)
265
+ .parse
277
266
  end
278
267
 
279
268
  # Sends a refresh request to Elasticsearch. Raises
@@ -283,7 +272,7 @@ module SearchFlip
283
272
  # @return [Boolean] Returns true or raises SearchFlip::ResponseError
284
273
 
285
274
  def refresh(index_names = nil)
286
- http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh")
275
+ http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh", json: {})
287
276
 
288
277
  true
289
278
  end
@@ -321,9 +310,7 @@ module SearchFlip
321
310
  url = type_name ? type_url(index_name, type_name) : index_url(index_name)
322
311
  params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
323
312
 
324
- response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
325
-
326
- SearchFlip::JSON.parse(response.to_s)
313
+ http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params).parse
327
314
  end
328
315
 
329
316
  # Deletes the specified index from Elasticsearch. Raises
@@ -26,8 +26,7 @@ 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,
30
- :http_timeout_value
29
+ :timeout_value, :preference_value, :search_type_value, :routing_value, :track_total_hits_value
31
30
 
32
31
  # Creates a new criteria while merging the attributes (constraints,
33
32
  # settings, etc) of the current criteria with the attributes of another one
@@ -48,7 +47,7 @@ module SearchFlip
48
47
  [
49
48
  :profile_value, :failsafe_value, :terminate_after_value, :timeout_value, :offset_value,
50
49
  :limit_value, :scroll_args, :source_value, :preference_value, :search_type_value,
51
- :routing_value, :track_total_hits_value, :explain_value, :http_timeout_value
50
+ :routing_value, :track_total_hits_value, :explain_value
52
51
  ].each do |name|
53
52
  criteria.send(:"#{name}=", other.send(name)) unless other.send(name).nil?
54
53
  end
@@ -149,22 +148,6 @@ module SearchFlip
149
148
  end
150
149
  end
151
150
 
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
-
168
151
  # Specifies early query termination, such that the processing will be
169
152
  # stopped after the specified number of results has been accumulated.
170
153
  #
@@ -347,13 +330,10 @@ module SearchFlip
347
330
  dupped_request.delete(:from)
348
331
  dupped_request.delete(:size)
349
332
 
350
- http_request = connection.http_client
351
- http_request = http_request.timeout(http_timeout_value) if http_timeout_value
352
-
353
333
  if connection.version.to_i >= 5
354
- http_request.post("#{target.type_url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
334
+ connection.http_client.post("#{target.type_url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
355
335
  else
356
- http_request.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request)
336
+ connection.http_client.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request)
357
337
  end
358
338
 
359
339
  target.refresh if SearchFlip::Config[:auto_refresh]
@@ -521,8 +501,8 @@ module SearchFlip
521
501
  end
522
502
 
523
503
  # Executes the search request for the current criteria, ie sends the
524
- # request to Elasticsearch and returns the response. Connection, timeout
525
- # and response errors will be rescued if you specify the criteria to be
504
+ # request to Elasticsearch and returns the response. Connection and
505
+ # response errors will be rescued if you specify the criteria to be
526
506
  # #failsafe, such that an empty response is returned instead.
527
507
  #
528
508
  # @example
@@ -610,7 +590,6 @@ module SearchFlip
610
590
 
611
591
  def execute!
612
592
  http_request = connection.http_client.headers(accept: "application/json")
613
- http_request = http_request.timeout(http_timeout_value) if http_timeout_value
614
593
 
615
594
  http_response =
616
595
  if scroll_args && scroll_args[:id]
@@ -630,7 +609,7 @@ module SearchFlip
630
609
  end
631
610
 
632
611
  SearchFlip::Response.new(self, SearchFlip::JSON.parse(http_response.to_s))
633
- rescue SearchFlip::ConnectionError, SearchFlip::TimeoutError, SearchFlip::ResponseError => e
612
+ rescue SearchFlip::ConnectionError, SearchFlip::ResponseError => e
634
613
  raise e unless failsafe_value
635
614
 
636
615
  SearchFlip::Response.new(self, "took" => 0, "hits" => { "total" => 0, "hits" => [] })
@@ -235,22 +235,6 @@ module SearchFlip
235
235
  filter(match_all: options)
236
236
  end
237
237
 
238
- # Adds a match none filter to the criteria, which simply matches none
239
- # documents at all. Check out the Elasticsearch docs for further details.
240
- #
241
- # @example Basic usage
242
- # CommentIndex.match_none
243
- #
244
- # @example Filter chaining
245
- # query = CommentIndex.search("...")
246
- # query = query.match_none unless current_user.admin?
247
- #
248
- # @return [SearchFlip::Criteria] A newly created extended criteria
249
-
250
- def match_none
251
- filter(match_none: {})
252
- end
253
-
254
238
  # Adds an exists filter to the criteria, which selects all documents for
255
239
  # which the specified field has a non-null value.
256
240
  #
@@ -1,28 +1,7 @@
1
1
  module SearchFlip
2
- # The SearchFlip::HTTPClient class wraps the http gem and responsible for the
3
- # http request/response handling, ie communicating with Elasticsearch. You
4
- # only need to use it directly if you need authentication to communicate with
5
- # Elasticsearch or if you want to set some custom http settings.
6
- #
7
- # @example
8
- # http_client = SearchFlip::HTTPClient.new
9
- #
10
- # # Basic Auth
11
- # http_client = http_client.basic_auth(user: "username", pass: "password")
12
- #
13
- # # Raw Auth Header
14
- # http_client = http_client.auth("Bearer VGhlIEhUVFAgR2VtLCBST0NLUw")
15
- #
16
- # # Proxy Settings
17
- # http_client = http_client.via("proxy.host", 8080)
18
- #
19
- # # Custom headers
20
- # http_client = http_client.headers(key: "value")
21
- #
22
- # # Timeouts
23
- # http_client = http_client.timeout(20)
24
- #
25
- # SearchFlip::Connection.new(base_url: "...", http_client: http_client)
2
+ # The SearchFlip::HTTPClient class wraps the http gem, is for internal use
3
+ # and responsible for the http request/response handling, ie communicating
4
+ # with Elasticsearch.
26
5
 
27
6
  class HTTPClient
28
7
  attr_accessor :request, :plugins
@@ -35,11 +14,11 @@ module SearchFlip
35
14
  class << self
36
15
  extend Forwardable
37
16
 
38
- def_delegators :new, :headers, :via, :basic_auth, :auth, :timeout
17
+ def_delegators :new, :headers, :via, :basic_auth, :auth
39
18
  def_delegators :new, :get, :post, :put, :delete, :head
40
19
  end
41
20
 
42
- [:headers, :via, :basic_auth, :auth, :timeout].each do |method|
21
+ [:headers, :via, :basic_auth, :auth].each do |method|
43
22
  define_method method do |*args|
44
23
  dup.tap do |client|
45
24
  client.request = request.send(method, *args)
@@ -66,10 +45,6 @@ module SearchFlip
66
45
  response
67
46
  rescue HTTP::ConnectionError => e
68
47
  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
73
48
  end
74
49
  end
75
50
  end
@@ -153,7 +153,7 @@ module SearchFlip
153
153
  # scope to be applied to the scope
154
154
 
155
155
  def each_record(scope, index_scope: false)
156
- return enum_for(:each_record, scope, index_scope: index_scope) unless block_given?
156
+ return enum_for(:each_record, scope) unless block_given?
157
157
 
158
158
  if scope.respond_to?(:find_each)
159
159
  (index_scope ? self.index_scope(scope) : scope).find_each do |record|
@@ -247,14 +247,14 @@ module SearchFlip
247
247
  SearchFlip::Criteria.new(target: self)
248
248
  end
249
249
 
250
- def_delegators :criteria, :all, :profile, :where, :where_not, :filter, :range, :match_all, :match_none,
251
- :exists, :exists_not, :post_where, :post_where_not, :post_range, :post_exists, :post_exists_not,
250
+ def_delegators :criteria, :all, :profile, :where, :where_not, :filter, :range, :match_all, :exists,
251
+ :exists_not, :post_where, :post_where_not, :post_range, :post_exists, :post_exists_not,
252
252
  :post_filter, :post_must, :post_must_not, :post_should, :aggregate, :scroll, :source,
253
253
  :includes, :eager_load, :preload, :sort, :resort, :order, :reorder, :offset, :limit, :paginate,
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, :http_timeout
257
+ :track_total_hits, :explain
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
@@ -487,9 +487,7 @@ module SearchFlip
487
487
  # @return [Hash] The raw response
488
488
 
489
489
  def analyze(request, params = {})
490
- response = connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params)
491
-
492
- SearchFlip::JSON.parse(response.to_s)
490
+ connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params).parse
493
491
  end
494
492
 
495
493
  # Sends a index refresh request to Elasticsearch. Raises
@@ -1,11 +1,11 @@
1
1
  module SearchFlip
2
2
  class JSON
3
3
  def self.generate(obj)
4
- Oj.dump(obj, SearchFlip::Config[:json_options])
4
+ Oj.dump(obj, mode: :custom, use_to_json: true)
5
5
  end
6
6
 
7
- def self.parse(json)
8
- ::JSON.parse(json)
7
+ def self.parse(str)
8
+ Oj.load(str)
9
9
  end
10
10
  end
11
11
  end