elastify 0.2.4 → 0.2.5

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: fa548bd07b0b3431f9fe21c4e1bec9dbfd0105ca
4
- data.tar.gz: 8480f5cd58f69422dae23ca1255b143743c36d4a
3
+ metadata.gz: 6574255a477a79f3ea8d236bf7a10cb8bd5702f9
4
+ data.tar.gz: 9410d4edb7474edd368775c908224f455dfcd4c7
5
5
  SHA512:
6
- metadata.gz: 63a937116d4d8109b629638f82e76ea1e1bf560f120f83124b1023d433dc1fd9ceee98c57f2eeb6e5cb556c58e710856bab31a0c106a2cff2d827e8068f9eeee
7
- data.tar.gz: f7cee3663f6c6e7652e2a17b9e453b697d67e0d223d622d187019c1e36a14dbc743871cac7a07131fdfbeb79c1fe211b437630327e20d8eafd96f4f23cca09e5
6
+ metadata.gz: f64b09a28b1d6dc0fa54ca92a5c58adfc5b30a57f6dd79d170934772e2cd36c601dc116922664ee6be0125db58972aa18677311a2ac999de089ebb40045b0b12
7
+ data.tar.gz: 58425beb87625933539354588cb8b771ad2b24a93f78d0e18e26fc6763a025c08eb5e2569ec1abad38477e31059c27c935e1bce4dbdf8c011f926b0eeb6b269b
data/.gitignore CHANGED
File without changes
data/CODE_OF_CONDUCT.md CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
data/elastify.gemspec CHANGED
@@ -31,10 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_runtime_dependency "activerecord", ">= 3.0.5"
34
- spec.add_runtime_dependency "httparty", ">= 0.6.0"
35
34
  spec.add_runtime_dependency "backgrounded", ">= 2.0.0"
36
35
  spec.add_runtime_dependency "multi_json", ">= 1.0.0"
37
- spec.add_runtime_dependency "rest-client", ["~> 2.0", ">= 2.0.1"]
36
+ spec.add_runtime_dependency "elasticsearch", ["~> 5.0", ">= 5.0.5"]
38
37
 
39
38
  spec.add_development_dependency "bundler", "~> 1.13"
40
39
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/elastify.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -37,24 +37,20 @@ module Elastify
37
37
  end
38
38
 
39
39
  def self.search(options, dsl, scroll_timeout)
40
- if dsl.blank?
41
- raise :elastify__search__required_dsl
42
- end
43
- url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/_search"
40
+ raise :elastify__search__required_dsl unless dsl.present?
44
41
  scroll_timeout ||= options[:scroll_timeout]
45
- url += "?scroll=#{scroll_timeout}" if scroll_timeout.present?
46
- Elastify::Helpers::ElasticSearch::SearchResultCollection.new(RestClient.post(url, dsl.to_json, {}), options)
42
+ client = elasticsearch_client options
43
+ response = client.search body: dsl, index: options[:index], type: options[:type], scroll: scroll_timeout
44
+ Elastify::Helpers::ElasticSearch::SearchResultCollection.new(response, options)
47
45
  end
48
46
 
49
47
  def self.scroll(options, scroll_id, scroll_timeout)
50
- if scroll_id.blank?
51
- raise :elastify__search__required_scroll_id
52
- end
53
- url = "#{options[:base_url]}/_search/scroll"
54
- dsl = { scroll_id: scroll_id }
48
+ raise :elastify__search__required_scroll_id unless scroll_id.present?
55
49
  scroll_timeout ||= options[:scroll_timeout]
56
- dsl[:scroll] = scroll_timeout if scroll_timeout.present?
57
- Elastify::Helpers::ElasticSearch::SearchResultCollection.new(RestClient.post(url, dsl.to_json, {}), options)
50
+ dsl = { scroll_id: scroll_id, scroll: scroll_timeout }
51
+ client = elasticsearch_client options
52
+ response = client.scroll body: dsl
53
+ Elastify::Helpers::ElasticSearch::SearchResultCollection.new(response, options)
58
54
  end
59
55
 
60
56
  def self.create_index(options)
@@ -71,6 +67,11 @@ module Elastify
71
67
  url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}"
72
68
  JSON.parse(RestClient.put(url, options[:map].squish, {})).to_hash
73
69
  end
70
+
71
+ private
72
+ def self.elasticsearch_client options
73
+ Elasticsearch::Client.new host: options[:base_url]
74
+ end
74
75
  end
75
76
  end
76
77
  end
File without changes
File without changes
@@ -6,17 +6,22 @@ module Elastify
6
6
  :elastify_options
7
7
 
8
8
  def initialize(elasticsearch_search_result, elastify_options)
9
- esr = JSON.parse(elasticsearch_search_result)
10
- @scroll_id = esr["_scroll_id"]
11
- @took = esr["took"]
12
- @timed_out = esr["timed_out"]
13
- @shards_total = esr["_shards"]["total"]
14
- @shards_successful = esr["_shards"]["successful"]
15
- @shards_failed = esr["_shards"]["failed"]
16
- @hits_total = esr["hits"]["total"]
17
- @hits_maxscore = esr["hits"]["maxscore"]
18
- @hits = esr["hits"]["hits"].map{ |hit| Elastify::Helpers::ElasticSearch::SearchResult.new(hit, elastify_options) }
19
9
  @elastify_options = elastify_options
10
+ @scroll_id = elasticsearch_search_result["_scroll_id"]
11
+ @took = elasticsearch_search_result["took"]
12
+ @timed_out = elasticsearch_search_result["timed_out"]
13
+ @shards_total = elasticsearch_search_result["_shards"]["total"]
14
+ @shards_successful = elasticsearch_search_result["_shards"]["successful"]
15
+ @shards_failed = elasticsearch_search_result["_shards"]["failed"]
16
+ @hits_total = elasticsearch_search_result["hits"]["total"]
17
+ @hits_maxscore = elasticsearch_search_result["hits"]["maxscore"]
18
+ @hits = map_hits(elasticsearch_search_result["hits"]["hits"])
19
+ end
20
+
21
+ def map_hits(hits)
22
+ hits.map do |hit|
23
+ Elastify::Helpers::ElasticSearch::SearchResult.new(hit, @elastify_options)
24
+ end
20
25
  end
21
26
  end
22
27
  end
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module Elastify
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Bortolotti Ribeiro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2019-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.5
27
- - !ruby/object:Gem::Dependency
28
- name: httparty
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 0.6.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 0.6.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: backgrounded
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,25 +53,25 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: 1.0.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: rest-client
56
+ name: elasticsearch
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '2.0'
61
+ version: '5.0'
76
62
  - - ">="
77
63
  - !ruby/object:Gem::Version
78
- version: 2.0.1
64
+ version: 5.0.5
79
65
  type: :runtime
80
66
  prerelease: false
81
67
  version_requirements: !ruby/object:Gem::Requirement
82
68
  requirements:
83
69
  - - "~>"
84
70
  - !ruby/object:Gem::Version
85
- version: '2.0'
71
+ version: '5.0'
86
72
  - - ">="
87
73
  - !ruby/object:Gem::Version
88
- version: 2.0.1
74
+ version: 5.0.5
89
75
  - !ruby/object:Gem::Dependency
90
76
  name: bundler
91
77
  requirement: !ruby/object:Gem::Requirement
@@ -208,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
194
  version: '0'
209
195
  requirements: []
210
196
  rubyforge_project:
211
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.5.2.3
212
198
  signing_key:
213
199
  specification_version: 4
214
200
  summary: A gem to help with ActiveRecord-ElasticSeach integration