elastify 0.1.0 → 0.1.3

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: a3d823100945b0cb9a6129108a9505b2679e634c
4
- data.tar.gz: 80b3798a246a0262592c94c47983a7cf26ddb949
3
+ metadata.gz: 52f92afd2a45df622a50571ed9a39d5ec3cb8518
4
+ data.tar.gz: 467a2373ede71ebadf822f31e7452e19ef4c7f71
5
5
  SHA512:
6
- metadata.gz: 6b2d472e359aa8db1176980b981305cbc63c0b4789024f68836394b1b5b868b4535635fc17e8947f37ccf0d42a535b04ac366fd6b8548b3f8fb16b9f9879740d
7
- data.tar.gz: d6878c1a436b7fdc189a0240964f7aab64b133235e6187305c1c766e4e0053e1124e2b32c1b01be15e23b19a1541f5bf07688f1778c99649acfb97041d388cc1
6
+ metadata.gz: 6c86d092e4fbbde756540849a5227398c735aa0c81757d2d177b0b4900838533a7e12bed990e836af6fcd64154002838315712a37dced0475441542ca5d0d240
7
+ data.tar.gz: 46a90cfc07fb96296b46a572a328799c2098a94f26e0b91689dce6b450677469bd99276781ecb6ac0af67b533462ad88e0815ca79a7bcb794406bd24e280e150
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/elastify.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
21
  else
22
22
  raise "RubyGems 2.0 or newer is required to protect against " \
23
23
  "public gem pushes."
@@ -7,18 +7,19 @@ module Elastify
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  module ClassMethods
10
- def elastify options = {}, &block
10
+ def elastify elastify_options = {}, &block
11
11
  include Elastify::ActiveRecordExtensions::LocalMethods
12
- cattr_accessor :options, :elastify_model_block
12
+ cattr_accessor :elastify_options, :elastify_model_block
13
13
  attr_accessor :elastify_serialized_document
14
14
 
15
- self.options = {
15
+ self.elastify_options = {
16
16
  base_url: Elastify.defaults[:base_url],
17
- index: options[:index] || Elastify.defaults[:default_index],
18
- type: options[:type] || Elastify.defaults[:default_type]
17
+ index: elastify_options[:index] || Elastify.defaults[:default_index],
18
+ type: elastify_options[:type] || Elastify.defaults[:default_type],
19
+ map: elastify_options[:map] || Elastify.defaults[:default_map]
19
20
  }
20
21
 
21
- self.options.each do |key, value|
22
+ self.elastify_options.each do |key, value|
22
23
  if value.blank?
23
24
  raise ElastifyError, "You must specify the #{key} value"
24
25
  end
@@ -32,12 +33,40 @@ module Elastify
32
33
  }
33
34
  end
34
35
  end
35
-
36
-
37
36
  end
38
37
 
39
38
  module LocalMethods
40
39
  extend ActiveSupport::Concern
40
+
41
+ def elastify_create
42
+ run_callbacks(:elastify_sync) do
43
+ if not self.elastify_serialized_document.blank?
44
+ run_callbacks(:elastify_create) do
45
+ ElasticSearchHelper::Document.new(self.elastify_options).create(self.elastify_serialized_document)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def elastify_update
52
+ run_callbacks(:elastify_sync) do
53
+ if not self.elastify_serialized_document.blank?
54
+ run_callbacks(:elastify_update) do
55
+ ElasticSearchHelper::Document.new(self.elastify_options).update(self.elastify_serialized_document)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def elastify_destroy
62
+ run_callbacks(:elastify_sync) do
63
+ if not self.elastify_serialized_document.blank?
64
+ run_callbacks(:elastify_destroy) do
65
+ ElasticSearchHelper::Document.new(self.elastify_options).destroy(self.elastify_serialized_document)
66
+ end
67
+ end
68
+ end
69
+ end
41
70
 
42
71
  included do
43
72
  define_model_callbacks :elastify_create
@@ -47,33 +76,15 @@ module Elastify
47
76
  # define_model_callbacks :elastify_serialize
48
77
 
49
78
  after_create { |item|
50
- run_callbacks(:elastify_sync) do
51
- if not item.elastify_serialized_document.blank?
52
- run_callbacks(:elastify_create) do
53
- ElasticSearchHelper::Document.new(self.options).create(item.elastify_serialized_document)
54
- end
55
- end
56
- end
79
+ item.elastify_create
57
80
  }
58
81
 
59
82
  after_update { |item|
60
- run_callbacks(:elastify_sync) do
61
- if not item.elastify_serialized_document.blank?
62
- run_callbacks(:elastify_update) do
63
- ElasticSearchHelper::Document.new(self.options).update(item.elastify_serialized_document)
64
- end
65
- end
66
- end
83
+ item.elastify_update
67
84
  }
68
85
 
69
86
  after_destroy { |item|
70
- run_callbacks(:elastify_sync) do
71
- if not item.elastify_serialized_document.blank?
72
- run_callbacks(:elastify_destroy) do
73
- ElasticSearchHelper::Document.new(self.options).destroy(item.elastify_serialized_document)
74
- end
75
- end
76
- end
87
+ item.elastify_destroy
77
88
  }
78
89
 
79
90
  before_elastify_sync { |item|
@@ -82,8 +93,12 @@ module Elastify
82
93
  end
83
94
 
84
95
  module ClassMethods
85
- def elastifind dsl
86
- return ElasticSearchHelper::Document.new(self.options).search(dsl)
96
+ def elastify_search(dsl: nil, scroll_timer: "1m")
97
+ return ElasticSearchHelper::Document.new(self.elastify_options).search(dsl, scroll_timer)
98
+ end
99
+
100
+ def elastify_scroll(scroll_id: nil, scroll_timer: "1m")
101
+ return ElasticSearchHelper::Document.new(self.elastify_options).scroll(scroll_id, scroll_timer)
87
102
  end
88
103
  end
89
104
  end
@@ -6,20 +6,23 @@ module Elastify
6
6
  self.options = options
7
7
  end
8
8
  def create model
9
- Connector.create self.options, model
9
+ Connector.create(self.options, model)
10
10
  end
11
11
  def update model
12
- Connector.update self.options, model
12
+ Connector.update(self.options, model)
13
13
  end
14
14
  def destroy model
15
- Connector.destroy self.options, model
15
+ Connector.destroy(self.options, model)
16
16
  end
17
- def search dsl
18
- Connector.search self.options, dsl
17
+ def search dsl, scroll_timer = nil
18
+ Connector.search(self.options, dsl, scroll_timer)
19
+ end
20
+ def scroll scroll_id, scroll_timer = nil
21
+ Connector.scroll(self.options, scroll_id, scroll_timer)
19
22
  end
20
23
  end
21
24
  class Connector
22
- def self.create options, data
25
+ def self.create(options, data)
23
26
  if data.blank?
24
27
  raise :elastify__create__required_data
25
28
  end
@@ -49,22 +52,42 @@ module Elastify
49
52
  url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/#{data[:id]}"
50
53
  response = JSON.parse(RestClient.delete(url)).to_hash
51
54
  end
52
- def self.search options, dsl
55
+ def self.search options, dsl, scroll_timer
53
56
  if dsl.blank?
54
57
  raise :elastify__search__required_dsl
55
58
  end
56
59
  url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}/_search"
60
+ url += "?scroll=#{scroll_timer}" if scroll_timer.present?
61
+ puts url
62
+ response = SearchResultSet.new(RestClient.post(url, dsl.to_json, {}))
63
+ end
64
+ def self.scroll options, scroll_id, scroll_timer
65
+ if scroll_id.blank?
66
+ raise :elastify__search__required_scroll_id
67
+ end
68
+ url = "#{options[:base_url]}/_search/scroll"
69
+ dsl = { scroll: scroll_timer, scroll_id: scroll_id }
70
+ puts dsl.to_json
57
71
  response = SearchResultSet.new(RestClient.post(url, dsl.to_json, {}))
58
72
  end
59
- def self.destroy_type options
60
- url = "#{options[:base_url]}/#{options[:index]}/#{options[:type]}"
73
+ def self.create_index options
74
+ url = "#{options[:base_url]}/#{options[:index]}"
75
+ response = JSON.parse(RestClient.put(url, {}.to_json, {})).to_hash
76
+ end
77
+ def self.destroy_index options
78
+ url = "#{options[:base_url]}/#{options[:index]}"
61
79
  response = JSON.parse(RestClient.delete(url)).to_hash
62
80
  end
81
+ def self.create_mapping options
82
+ url = "#{options[:base_url]}/#{options[:index]}/_mappings/#{options[:type]}"
83
+ response = JSON.parse(RestClient.put(url, options[:map].to_json, {})).to_hash
84
+ end
63
85
  end
64
86
  class SearchResultSet
65
- attr_accessor :took, :timed_out, :shards_total, :shards_successful, :shards_failed, :hits_total, :hits_maxscore, :hits
87
+ attr_accessor :scroll_id, :took, :timed_out, :shards_total, :shards_successful, :shards_failed, :hits_total, :hits_maxscore, :hits
66
88
  def initialize elasticsearch_search_result
67
89
  esr = JSON.parse(elasticsearch_search_result)
90
+ self.scroll_id = esr["_scroll_id"]
68
91
  self.took = esr["took"]
69
92
  self.timed_out = esr["timed_out"]
70
93
  self.shards_total = esr["_shards"]["total"]
@@ -78,11 +101,10 @@ module Elastify
78
101
  class SearchResult
79
102
  attr_accessor :index, :type, :id, :score, :source
80
103
  def initialize elasticsearch_search_result_hit
81
- esrh = elasticsearch_search_result_hit
82
- self.index = esrh["_index"]
83
- self.type = esrh["_type"]
84
- self.id = esrh["_id"]
85
- self.source = OpenStruct.new(esrh["_source"])
104
+ self.index = elasticsearch_search_result_hit["_index"]
105
+ self.type = elasticsearch_search_result_hit["_type"]
106
+ self.id = elasticsearch_search_result_hit["_id"]
107
+ self.source = elasticsearch_search_result_hit["_source"]
86
108
  end
87
109
  end
88
110
  end
@@ -1,3 +1,3 @@
1
1
  module Elastify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/elastify.rb CHANGED
File without changes
metadata CHANGED
@@ -1,117 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
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: 2017-05-20 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: backgrounded
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: multi_json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.0'
76
- - - ">="
76
+ - - '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: 2.0.1
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - "~>"
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
85
  version: '2.0'
86
- - - ">="
86
+ - - '>='
87
87
  - !ruby/object:Gem::Version
88
88
  version: 2.0.1
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: bundler
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ~>
94
94
  - !ruby/object:Gem::Version
95
95
  version: '1.13'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ~>
101
101
  - !ruby/object:Gem::Version
102
102
  version: '1.13'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: '10.0'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ~>
115
115
  - !ruby/object:Gem::Version
116
116
  version: '10.0'
117
117
  - !ruby/object:Gem::Dependency
@@ -163,7 +163,7 @@ executables: []
163
163
  extensions: []
164
164
  extra_rdoc_files: []
165
165
  files:
166
- - ".gitignore"
166
+ - .gitignore
167
167
  - CODE_OF_CONDUCT.md
168
168
  - Gemfile
169
169
  - LICENSE.txt
@@ -180,24 +180,24 @@ homepage: https://github.com/brunobortolotti/elastify.git
180
180
  licenses:
181
181
  - MIT
182
182
  metadata:
183
- allowed_push_host: https://rubygems.org
183
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
184
184
  post_install_message:
185
185
  rdoc_options: []
186
186
  require_paths:
187
187
  - lib
188
188
  required_ruby_version: !ruby/object:Gem::Requirement
189
189
  requirements:
190
- - - ">="
190
+ - - '>='
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - ">="
195
+ - - '>='
196
196
  - !ruby/object:Gem::Version
197
197
  version: '0'
198
198
  requirements: []
199
199
  rubyforge_project:
200
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.0.14.1
201
201
  signing_key:
202
202
  specification_version: 4
203
203
  summary: A gem to help with ActiveRecord-ElasticSeach integration