chewy 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +35 -29
- data/Appraisals +37 -0
- data/CHANGELOG.md +115 -4
- data/Gemfile +2 -3
- data/README.md +135 -40
- data/chewy.gemspec +4 -3
- data/gemfiles/rails.3.2.activerecord.gemfile +13 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +14 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.0.activerecord.gemfile +13 -0
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.0.mongoid.gemfile +13 -0
- data/gemfiles/rails.4.0.mongoid.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.0.mongoid.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.1.mongoid.gemfile +13 -0
- data/gemfiles/rails.4.1.mongoid.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.1.mongoid.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +13 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +14 -0
- data/gemfiles/rails.4.2.mongoid.gemfile +13 -0
- data/gemfiles/rails.4.2.mongoid.kaminari.gemfile +14 -0
- data/gemfiles/rails.4.2.mongoid.will_paginate.gemfile +14 -0
- data/lib/chewy.rb +65 -0
- data/lib/chewy/config.rb +44 -93
- data/lib/chewy/errors.rb +14 -5
- data/lib/chewy/fields/base.rb +8 -7
- data/lib/chewy/fields/root.rb +2 -2
- data/lib/chewy/index.rb +7 -9
- data/lib/chewy/log_subscriber.rb +34 -0
- data/lib/chewy/query.rb +41 -27
- data/lib/chewy/query/criteria.rb +28 -23
- data/lib/chewy/query/scoping.rb +20 -0
- data/lib/chewy/railtie.rb +51 -13
- data/lib/chewy/repository.rb +61 -0
- data/lib/chewy/rspec/update_index.rb +3 -6
- data/lib/chewy/search.rb +28 -7
- data/lib/chewy/strategy.rb +60 -0
- data/lib/chewy/strategy/atomic.rb +31 -0
- data/lib/chewy/strategy/base.rb +27 -0
- data/lib/chewy/strategy/bypass.rb +15 -0
- data/lib/chewy/strategy/urgent.rb +17 -0
- data/lib/chewy/type.rb +19 -5
- data/lib/chewy/type/adapter/active_record.rb +28 -117
- data/lib/chewy/type/adapter/base.rb +35 -0
- data/lib/chewy/type/adapter/mongoid.rb +23 -123
- data/lib/chewy/type/adapter/object.rb +41 -19
- data/lib/chewy/type/adapter/orm.rb +142 -0
- data/lib/chewy/type/import.rb +43 -16
- data/lib/chewy/type/observe.rb +8 -21
- data/lib/chewy/version.rb +1 -1
- data/lib/tasks/chewy.rake +8 -4
- data/spec/chewy/config_spec.rb +20 -97
- data/spec/chewy/fields/base_spec.rb +24 -11
- data/spec/chewy/fields/time_fields_spec.rb +27 -0
- data/spec/chewy/index/settings_spec.rb +2 -1
- data/spec/chewy/index_spec.rb +98 -79
- data/spec/chewy/query/criteria_spec.rb +14 -0
- data/spec/chewy/query_spec.rb +1 -1
- data/spec/chewy/repository_spec.rb +50 -0
- data/spec/chewy/search_spec.rb +100 -0
- data/spec/chewy/strategy_spec.rb +109 -0
- data/spec/chewy/type/adapter/active_record_spec.rb +110 -46
- data/spec/chewy/type/adapter/mongoid_spec.rb +123 -74
- data/spec/chewy/type/adapter/object_spec.rb +51 -34
- data/spec/chewy/type/import_spec.rb +21 -21
- data/spec/chewy/type/observe_spec.rb +26 -29
- data/spec/chewy/type_spec.rb +19 -0
- data/spec/chewy_spec.rb +19 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +2 -1
- data/spec/support/mongoid.rb +29 -38
- metadata +85 -55
- data/gemfiles/Gemfile.rails-3.2.active_record +0 -6
- data/gemfiles/Gemfile.rails-3.2.active_record.kaminari +0 -7
- data/gemfiles/Gemfile.rails-3.2.active_record.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.0.active_record +0 -6
- data/gemfiles/Gemfile.rails-4.0.active_record.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.0.active_record.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.0.mongoid +0 -6
- data/gemfiles/Gemfile.rails-4.0.mongoid.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.0.mongoid.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.1.active_record +0 -6
- data/gemfiles/Gemfile.rails-4.1.active_record.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.1.active_record.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.1.mongoid +0 -6
- data/gemfiles/Gemfile.rails-4.1.mongoid.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.1.mongoid.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.2.active_record +0 -6
- data/gemfiles/Gemfile.rails-4.2.active_record.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.2.active_record.will_paginate +0 -7
- data/gemfiles/Gemfile.rails-4.2.mongoid +0 -6
- data/gemfiles/Gemfile.rails-4.2.mongoid.kaminari +0 -7
- data/gemfiles/Gemfile.rails-4.2.mongoid.will_paginate +0 -7
- data/spec/chewy/index/search_spec.rb +0 -46
data/chewy.gemspec
CHANGED
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_development_dependency 'rake'
|
22
|
-
spec.add_development_dependency '
|
23
|
-
spec.add_development_dependency 'rspec
|
22
|
+
spec.add_development_dependency 'appraisal'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rspec-its'
|
24
25
|
spec.add_development_dependency 'rspec-collection_matchers'
|
25
26
|
spec.add_development_dependency 'sqlite3'
|
26
|
-
spec.add_development_dependency 'database_cleaner'
|
27
|
+
spec.add_development_dependency 'database_cleaner', '~> 1.3.0'
|
27
28
|
spec.add_development_dependency 'elasticsearch-extensions'
|
28
29
|
spec.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx'
|
29
30
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 3.2.0"
|
6
|
+
gem "activesupport", "~> 3.2.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 3.2.0"
|
6
|
+
gem "activesupport", "~> 3.2.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.0.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.0.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.0.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.0.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.1.0"
|
6
|
+
gem "activesupport", "~> 4.1.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.1.0"
|
6
|
+
gem "activesupport", "~> 4.1.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.1.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.1.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.2.0"
|
6
|
+
gem "activesupport", "~> 4.2.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activerecord", "~> 4.2.0"
|
6
|
+
gem "activesupport", "~> 4.2.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.2.0"
|
7
|
+
gem "kaminari", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "mongoid", "~> 4.0.0"
|
6
|
+
gem "activesupport", "~> 4.2.0"
|
7
|
+
gem "will_paginate", :require => false
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "guard"
|
11
|
+
gem "guard-rspec"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
data/lib/chewy.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/log_subscriber'
|
2
3
|
require 'active_support/deprecation'
|
3
4
|
require 'active_support/core_ext'
|
4
5
|
require 'active_support/concern'
|
@@ -12,7 +13,10 @@ require 'elasticsearch'
|
|
12
13
|
require 'chewy/version'
|
13
14
|
require 'chewy/errors'
|
14
15
|
require 'chewy/config'
|
16
|
+
require 'chewy/repository'
|
15
17
|
require 'chewy/runtime'
|
18
|
+
require 'chewy/log_subscriber'
|
19
|
+
require 'chewy/strategy'
|
16
20
|
require 'chewy/index'
|
17
21
|
require 'chewy/type'
|
18
22
|
require 'chewy/fields/base'
|
@@ -103,6 +107,12 @@ module Chewy
|
|
103
107
|
type
|
104
108
|
end
|
105
109
|
|
110
|
+
# Main elasticsearch-ruby client instance
|
111
|
+
#
|
112
|
+
def client
|
113
|
+
Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new configuration
|
114
|
+
end
|
115
|
+
|
106
116
|
# Sends wait_for_status request to ElasticSearch with status
|
107
117
|
# defined in configuration.
|
108
118
|
#
|
@@ -121,9 +131,64 @@ module Chewy
|
|
121
131
|
end
|
122
132
|
alias_method :delete_all, :massacre
|
123
133
|
|
134
|
+
# Strategies are designed to allow nesting, so it is possible
|
135
|
+
# to redefine it for nested contexts.
|
136
|
+
#
|
137
|
+
# Chewy.strategy(:atomic) do
|
138
|
+
# city1.do_update!
|
139
|
+
# Chewy.strategy(:urgent) do
|
140
|
+
# city2.do_update!
|
141
|
+
# city3.do_update!
|
142
|
+
# # there will be 2 update index requests for city2 and city3
|
143
|
+
# end
|
144
|
+
# city4..do_update!
|
145
|
+
# # city1 and city4 will be grouped in one index update request
|
146
|
+
# end
|
147
|
+
#
|
148
|
+
# It is possible to nest strategies without blocks:
|
149
|
+
#
|
150
|
+
# Chewy.strategy(:urgent)
|
151
|
+
# city1.do_update! # index updated
|
152
|
+
# Chewy.strategy(:bypass)
|
153
|
+
# city2.do_update! # update bypassed
|
154
|
+
# Chewy.strategy.pop
|
155
|
+
# city3.do_update! # index updated again
|
156
|
+
#
|
157
|
+
def strategy name = nil, &block
|
158
|
+
Thread.current[:chewy_strategy] ||= Chewy::Strategy.new
|
159
|
+
if name
|
160
|
+
if block
|
161
|
+
Thread.current[:chewy_strategy].wrap name, &block
|
162
|
+
else
|
163
|
+
Thread.current[:chewy_strategy].push name
|
164
|
+
end
|
165
|
+
else
|
166
|
+
Thread.current[:chewy_strategy]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def urgent_update= value
|
171
|
+
ActiveSupport::Deprecation.warn('`Chewy.urgent_update = value` is deprecated and will be removed soon, use `Chewy.strategy(:urgent)` block instead')
|
172
|
+
if value
|
173
|
+
strategy(:urgent)
|
174
|
+
else
|
175
|
+
strategy.pop
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def atomic &block
|
180
|
+
ActiveSupport::Deprecation.warn('`Chewy.atomic` block is deprecated and will be removed soon, use `Chewy.strategy(:atomic)` block instead')
|
181
|
+
strategy(:atomic, &block)
|
182
|
+
end
|
183
|
+
|
124
184
|
def config
|
125
185
|
Chewy::Config.instance
|
126
186
|
end
|
127
187
|
delegate *Chewy::Config.delegated, to: :config
|
188
|
+
|
189
|
+
def repository
|
190
|
+
Chewy::Repository.instance
|
191
|
+
end
|
192
|
+
delegate *Chewy::Repository.delegated, to: :repository
|
128
193
|
end
|
129
194
|
end
|
data/lib/chewy/config.rb
CHANGED
@@ -2,20 +2,7 @@ module Chewy
|
|
2
2
|
class Config
|
3
3
|
include Singleton
|
4
4
|
|
5
|
-
|
6
|
-
attr_accessor :configuration,
|
7
|
-
# Just sets up logger to current configuration
|
8
|
-
#
|
9
|
-
# Chewy.logger = Rails.logger
|
10
|
-
#
|
11
|
-
:logger,
|
12
|
-
|
13
|
-
# Urgent update default value. False by default. Urgent
|
14
|
-
# updates are useful for testing, so don't use it in the
|
15
|
-
# application code. Prefer `Chewy.atomic` block for cumulative
|
16
|
-
# index updates.
|
17
|
-
#
|
18
|
-
:urgent_update,
|
5
|
+
attr_accessor :settings, :transport_logger, :transport_tracer, :logger,
|
19
6
|
|
20
7
|
# Default query compilation mode. `:must` by default.
|
21
8
|
# See Chewy::Query#query_mode for details
|
@@ -30,68 +17,52 @@ module Chewy
|
|
30
17
|
# Default post_filters compilation mode. `nil` by default.
|
31
18
|
# See Chewy::Query#post_filter_mode for details
|
32
19
|
#
|
33
|
-
:post_filter_mode
|
20
|
+
:post_filter_mode,
|
34
21
|
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
# The first trategy in stack. `:base` by default.
|
23
|
+
# If you neet to return to the previous chewy behavior -
|
24
|
+
# just set it to `:bypass`
|
25
|
+
#
|
26
|
+
:root_strategy,
|
38
27
|
|
39
|
-
|
40
|
-
|
28
|
+
# The first trategy in stack. `:base` by default.
|
29
|
+
# If you neet to return to the previous chewy behavior -
|
30
|
+
# just set it to `:bypass`
|
31
|
+
#
|
32
|
+
:request_strategy,
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
# Use after_commit callbacks for RDBMS instead of
|
35
|
+
# after_save and after_destroy. True by default. Useful
|
36
|
+
# in tests with transactional fixtures or transactional
|
37
|
+
# DatabaseCleaner strategy.
|
38
|
+
#
|
39
|
+
:use_after_commit_callbacks
|
40
|
+
|
41
|
+
def self.delegated
|
42
|
+
public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
|
47
43
|
end
|
48
44
|
|
49
45
|
def initialize
|
50
|
-
@
|
51
|
-
@urgent_update = false
|
46
|
+
@settings = {}
|
52
47
|
@query_mode = :must
|
53
48
|
@filter_mode = :and
|
54
|
-
@
|
55
|
-
@
|
56
|
-
@
|
57
|
-
@char_filters = {}
|
49
|
+
@root_strategy = :base
|
50
|
+
@request_strategy = :atomic
|
51
|
+
@use_after_commit_callbacks = true
|
58
52
|
end
|
59
53
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# tokenizer: 'my_tokenizer1',
|
65
|
-
# filter : ['my_token_filter1', 'my_token_filter2']
|
66
|
-
# char_filter : ['my_html']
|
67
|
-
# }
|
68
|
-
# Chewy.analyzer(:my_analyzer2) # => {type: 'custom', tokenizer: ...}
|
69
|
-
#
|
70
|
-
repository :analyzer
|
71
|
-
|
72
|
-
# Tokenizers repository:
|
73
|
-
#
|
74
|
-
# Chewy.tokenizer :my_tokenizer1, {type: standard, max_token_length: 900}
|
75
|
-
# Chewy.tokenizer(:my_tokenizer1) # => {type: standard, max_token_length: 900}
|
76
|
-
#
|
77
|
-
repository :tokenizer
|
78
|
-
|
79
|
-
# Token filters repository:
|
80
|
-
#
|
81
|
-
# Chewy.filter :my_token_filter1, {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
|
82
|
-
# Chewy.filter(:my_token_filter1) # => {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
|
83
|
-
#
|
84
|
-
repository :filter
|
54
|
+
def transport_logger= logger
|
55
|
+
Chewy.client.transport.logger = logger
|
56
|
+
@transport_logger = logger
|
57
|
+
end
|
85
58
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
repository :char_filter
|
59
|
+
def transport_tracer= tracer
|
60
|
+
Chewy.client.transport.tracer = tracer
|
61
|
+
@transport_tracer = tracer
|
62
|
+
end
|
92
63
|
|
93
64
|
# Chewy core configurations. There is two ways to set it up:
|
94
|
-
# use `Chewy.
|
65
|
+
# use `Chewy.settings=` method or, for Rails application,
|
95
66
|
# create `config/chewy.yml` file. Btw, `config/chewy.yml` supports
|
96
67
|
# ERB the same way as ActiveRecord's config.
|
97
68
|
#
|
@@ -134,45 +105,25 @@ module Chewy
|
|
134
105
|
# number_of_replicas: 0
|
135
106
|
#
|
136
107
|
def configuration
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
def client
|
143
|
-
Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new configuration
|
144
|
-
end
|
145
|
-
|
146
|
-
def atomic?
|
147
|
-
stash.any?
|
148
|
-
end
|
149
|
-
|
150
|
-
def atomic
|
151
|
-
stash.push({})
|
152
|
-
yield
|
153
|
-
ensure
|
154
|
-
stash.pop.each { |type, ids| type.import(ids) }
|
108
|
+
yaml_settings.merge(settings.deep_symbolize_keys).tap do |configuration|
|
109
|
+
configuration.merge(logger: transport_logger) if transport_logger
|
110
|
+
configuration.merge(tracer: transport_tracer) if transport_tracer
|
111
|
+
end
|
155
112
|
end
|
156
113
|
|
157
|
-
def
|
158
|
-
|
159
|
-
|
160
|
-
raise ArgumentError.new('Only Chewy::Type accepted as the first argument') unless type < Chewy::Type
|
161
|
-
stash.last[type] ||= []
|
162
|
-
stash.last[type] |= ids
|
163
|
-
else
|
164
|
-
Thread.current[:chewy_cache] ||= []
|
165
|
-
end
|
114
|
+
def configuration= options
|
115
|
+
ActiveSupport::Deprecation.warn("`Chewy.configuration = {foo: 'bar'}` method is deprecated and will be removed soon, use `Chewy.settings = {foo: 'bar'}` method instead")
|
116
|
+
self.settings = options
|
166
117
|
end
|
167
118
|
|
168
119
|
private
|
169
120
|
|
170
|
-
def
|
171
|
-
@
|
121
|
+
def yaml_settings
|
122
|
+
@yaml_settings ||= begin
|
172
123
|
if defined?(Rails)
|
173
124
|
file = Rails.root.join(*%w(config chewy.yml))
|
174
125
|
|
175
|
-
if File.
|
126
|
+
if File.exist?(file)
|
176
127
|
yaml = ERB.new(File.read(file)).result
|
177
128
|
hash = YAML.load(yaml)
|
178
129
|
hash[Rails.env].try(:deep_symbolize_keys) if hash
|