chewy 0.10.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +25 -25
- data/.travis.yml +21 -29
- data/Appraisals +27 -9
- data/CHANGELOG.md +36 -0
- data/Gemfile +3 -1
- data/README.md +73 -23
- data/chewy.gemspec +6 -8
- data/gemfiles/rails.4.0.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.1.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.4.2.mongoid.5.2.gemfile} +2 -1
- data/gemfiles/rails.5.0.activerecord.gemfile +2 -1
- data/gemfiles/{rails.5.0.mongoid.6.0.gemfile → rails.5.0.mongoid.6.1.gemfile} +3 -2
- data/gemfiles/rails.5.1.activerecord.gemfile +2 -1
- data/gemfiles/{rails.5.1.mongoid.6.1.gemfile → rails.5.1.mongoid.6.3.gemfile} +3 -2
- data/gemfiles/rails.5.2.activerecord.gemfile +16 -0
- data/gemfiles/sequel.4.45.gemfile +2 -2
- data/lib/chewy.rb +1 -0
- data/lib/chewy/config.rb +8 -19
- data/lib/chewy/fields/base.rb +15 -3
- data/lib/chewy/fields/root.rb +13 -9
- data/lib/chewy/index.rb +1 -1
- data/lib/chewy/index/actions.rb +14 -12
- data/lib/chewy/index/settings.rb +2 -0
- data/lib/chewy/index/specification.rb +12 -10
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/query.rb +135 -96
- data/lib/chewy/query/filters.rb +20 -3
- data/lib/chewy/query/loading.rb +0 -1
- data/lib/chewy/railtie.rb +2 -4
- data/lib/chewy/rake_helper.rb +5 -5
- data/lib/chewy/rspec/update_index.rb +3 -5
- data/lib/chewy/search.rb +2 -2
- data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
- data/lib/chewy/stash.rb +30 -21
- data/lib/chewy/strategy/atomic.rb +1 -1
- data/lib/chewy/type.rb +2 -2
- data/lib/chewy/type/adapter/base.rb +9 -9
- data/lib/chewy/type/adapter/mongoid.rb +1 -3
- data/lib/chewy/type/adapter/sequel.rb +4 -6
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +3 -2
- data/lib/chewy/type/import/bulk_builder.rb +1 -1
- data/lib/chewy/type/import/journal_builder.rb +3 -3
- data/lib/chewy/type/import/routine.rb +2 -2
- data/lib/chewy/type/mapping.rb +40 -34
- data/lib/chewy/type/observe.rb +13 -9
- data/lib/chewy/type/syncer.rb +2 -2
- data/lib/chewy/type/witchcraft.rb +2 -2
- data/lib/chewy/type/wrapper.rb +2 -2
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/spec/chewy/config_spec.rb +16 -0
- data/spec/chewy/fields/base_spec.rb +61 -65
- data/spec/chewy/fields/root_spec.rb +13 -13
- data/spec/chewy/index/actions_spec.rb +37 -5
- data/spec/chewy/index/specification_spec.rb +25 -16
- data/spec/chewy/index_spec.rb +61 -8
- data/spec/chewy/journal_spec.rb +11 -11
- data/spec/chewy/query/filters_spec.rb +1 -1
- data/spec/chewy/query/nodes/not_spec.rb +1 -0
- data/spec/chewy/query_spec.rb +3 -2
- data/spec/chewy/rake_helper_spec.rb +46 -33
- data/spec/chewy/search_spec.rb +20 -10
- data/spec/chewy/stash_spec.rb +1 -1
- data/spec/chewy/strategy/shoryuken_spec.rb +2 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +8 -8
- data/spec/chewy/type/import_spec.rb +6 -0
- data/spec/chewy/type/mapping_spec.rb +48 -17
- data/spec/spec_helper.rb +8 -0
- metadata +26 -25
data/lib/chewy/query/filters.rb
CHANGED
@@ -24,18 +24,20 @@ module Chewy
|
|
24
24
|
# You can use logic operations <tt>&</tt> and <tt>|</tt> to concat
|
25
25
|
# expressions.
|
26
26
|
#
|
27
|
+
# @example
|
27
28
|
# UsersIndex.filter{ (article.title =~ /Honey/) & (age < 42) & !rate }
|
28
29
|
#
|
29
30
|
#
|
30
31
|
class Filters
|
31
32
|
def initialize(outer = nil, &block)
|
32
33
|
@block = block
|
33
|
-
@outer = outer || eval('self', block.binding)
|
34
|
+
@outer = outer || eval('self', block.binding, __FILE__, __LINE__)
|
34
35
|
end
|
35
36
|
|
36
37
|
# Outer scope call
|
37
38
|
# Block evaluates in the external context
|
38
39
|
#
|
40
|
+
# @example
|
39
41
|
# def name
|
40
42
|
# 'Friend'
|
41
43
|
# end
|
@@ -50,12 +52,14 @@ module Chewy
|
|
50
52
|
# Used if method_missing is not working by some reason.
|
51
53
|
# Additional expression options might be passed as second argument hash.
|
52
54
|
#
|
55
|
+
# @example
|
53
56
|
# UsersIndex.filter{ f(:name) == 'Name' } == UsersIndex.filter{ name == 'Name' } # => true
|
54
57
|
# UsersIndex.filter{ f(:name, execution: :bool) == ['Name1', 'Name2'] } ==
|
55
58
|
# UsersIndex.filter{ name(execution: :bool) == ['Name1', 'Name2'] } # => true
|
56
59
|
#
|
57
60
|
# Supports block for getting field name from the outer scope
|
58
61
|
#
|
62
|
+
# @example
|
59
63
|
# def field
|
60
64
|
# :name
|
61
65
|
# end
|
@@ -70,11 +74,13 @@ module Chewy
|
|
70
74
|
# Returns script filter
|
71
75
|
# Just script filter. Supports additional params.
|
72
76
|
#
|
77
|
+
# @example
|
73
78
|
# UsersIndex.filter{ s('doc["num1"].value > 1') }
|
74
79
|
# UsersIndex.filter{ s('doc["num1"].value > param1', param1: 42) }
|
75
80
|
#
|
76
81
|
# Supports block for getting script from the outer scope
|
77
82
|
#
|
83
|
+
# @example
|
78
84
|
# def script
|
79
85
|
# 'doc["num1"].value > param1 || 1'
|
80
86
|
# end
|
@@ -90,10 +96,12 @@ module Chewy
|
|
90
96
|
|
91
97
|
# Returns query filter
|
92
98
|
#
|
99
|
+
# @example
|
93
100
|
# UsersIndex.filter{ q(query_string: {query: 'name: hello'}) }
|
94
101
|
#
|
95
102
|
# Supports block for getting query from the outer scope
|
96
103
|
#
|
104
|
+
# @example
|
97
105
|
# def query
|
98
106
|
# {query_string: {query: 'name: hello'}}
|
99
107
|
# end
|
@@ -107,11 +115,13 @@ module Chewy
|
|
107
115
|
# Returns raw expression
|
108
116
|
# Same as filter with arguments instead of block, but can participate in expressions
|
109
117
|
#
|
118
|
+
# @example
|
110
119
|
# UsersIndex.filter{ r(term: {name: 'Name'}) }
|
111
120
|
# UsersIndex.filter{ r(term: {name: 'Name'}) & (age < 42) }
|
112
121
|
#
|
113
122
|
# Supports block for getting raw filter from the outer scope
|
114
123
|
#
|
124
|
+
# @example
|
115
125
|
# def filter
|
116
126
|
# {term: {name: 'Name'}}
|
117
127
|
# end
|
@@ -126,6 +136,7 @@ module Chewy
|
|
126
136
|
# Bool filter chainable methods
|
127
137
|
# Used to create bool query. Nodes are passed as arguments.
|
128
138
|
#
|
139
|
+
# @example
|
129
140
|
# UsersIndex.filter{ must(age < 42, name == 'Name') }
|
130
141
|
# UsersIndex.filter{ should(age < 42, name == 'Name') }
|
131
142
|
# UsersIndex.filter{ must(age < 42).should(name == 'Name1', name == 'Name2') }
|
@@ -141,12 +152,14 @@ module Chewy
|
|
141
152
|
# Chainable interface acts the same as main query interface. You can pass plain
|
142
153
|
# filters or plain queries or filter with DSL block.
|
143
154
|
#
|
155
|
+
# @example
|
144
156
|
# UsersIndex.filter{ has_child('user').filter(term: {role: 'Admin'}) }
|
145
157
|
# UsersIndex.filter{ has_child('user').filter{ role == 'Admin' } }
|
146
158
|
# UsersIndex.filter{ has_child('user').query(match: {name: 'borogoves'}) }
|
147
159
|
#
|
148
160
|
# Filters and queries might be combined and filter_mode and query_mode are configurable:
|
149
161
|
#
|
162
|
+
# @example
|
150
163
|
# UsersIndex.filter do
|
151
164
|
# has_child('user')
|
152
165
|
# .filter{ name: 'Peter' }
|
@@ -155,7 +168,7 @@ module Chewy
|
|
155
168
|
# .filter_mode(:or)
|
156
169
|
# end
|
157
170
|
#
|
158
|
-
def has_child(type) # rubocop:disable
|
171
|
+
def has_child(type) # rubocop:disable Naming/PredicateName
|
159
172
|
Nodes::HasChild.new(type, @outer)
|
160
173
|
end
|
161
174
|
|
@@ -163,12 +176,14 @@ module Chewy
|
|
163
176
|
# Chainable interface acts the same as main query interface. You can pass plain
|
164
177
|
# filters or plain queries or filter with DSL block.
|
165
178
|
#
|
179
|
+
# @example
|
166
180
|
# UsersIndex.filter{ has_parent('user').filter(term: {role: 'Admin'}) }
|
167
181
|
# UsersIndex.filter{ has_parent('user').filter{ role == 'Admin' } }
|
168
182
|
# UsersIndex.filter{ has_parent('user').query(match: {name: 'borogoves'}) }
|
169
183
|
#
|
170
184
|
# Filters and queries might be combined and filter_mode and query_mode are configurable:
|
171
185
|
#
|
186
|
+
# @example
|
172
187
|
# UsersIndex.filter do
|
173
188
|
# has_parent('user')
|
174
189
|
# .filter{ name: 'Peter' }
|
@@ -177,7 +192,7 @@ module Chewy
|
|
177
192
|
# .filter_mode(:or)
|
178
193
|
# end
|
179
194
|
#
|
180
|
-
def has_parent(type) # rubocop:disable
|
195
|
+
def has_parent(type) # rubocop:disable Naming/PredicateName
|
181
196
|
Nodes::HasParent.new(type, @outer)
|
182
197
|
end
|
183
198
|
|
@@ -190,6 +205,7 @@ module Chewy
|
|
190
205
|
# Creates field or exists node
|
191
206
|
# Additional options for further expression might be passed as hash
|
192
207
|
#
|
208
|
+
# @example
|
193
209
|
# UsersIndex.filter{ name == 'Name' } == UsersIndex.filter(term: {name: 'Name'}) # => true
|
194
210
|
# UsersIndex.filter{ name? } == UsersIndex.filter(exists: {term: 'name'}) # => true
|
195
211
|
# UsersIndex.filter{ name(execution: :bool) == ['Name1', 'Name2'] } ==
|
@@ -197,6 +213,7 @@ module Chewy
|
|
197
213
|
#
|
198
214
|
# Also field names might be chained to use dot-notation for ES field names
|
199
215
|
#
|
216
|
+
# @example
|
200
217
|
# UsersIndex.filter{ article.title =~ 'Hello' }
|
201
218
|
# UsersIndex.filter{ article.tags? }
|
202
219
|
#
|
data/lib/chewy/query/loading.rb
CHANGED
@@ -94,7 +94,6 @@ module Chewy
|
|
94
94
|
loaded_objects = Hash[_results.group_by(&:class).map do |type, objects|
|
95
95
|
next if except.include?(type.type_name)
|
96
96
|
next if only.present? && !only.include?(type.type_name)
|
97
|
-
|
98
97
|
loaded = type.adapter.load(objects.map(&:id), options.merge(_type: type)) || objects
|
99
98
|
[type, loaded.index_by.with_index do |loaded_object, i|
|
100
99
|
objects[i]._object = loaded_object
|
data/lib/chewy/railtie.rb
CHANGED
@@ -14,7 +14,7 @@ module Chewy
|
|
14
14
|
if Rails.application.config.respond_to?(:assets) && env['PATH_INFO'].start_with?(Rails.application.config.assets.prefix)
|
15
15
|
@app.call(env)
|
16
16
|
else
|
17
|
-
Chewy.logger.info("Chewy request strategy is `#{Chewy.request_strategy}`") if @request_strategy != Chewy.request_strategy
|
17
|
+
Chewy.logger.info("Chewy request strategy is `#{Chewy.request_strategy}`") if Chewy.logger && @request_strategy != Chewy.request_strategy
|
18
18
|
@request_strategy = Chewy.request_strategy
|
19
19
|
Chewy.strategy(Chewy.request_strategy) { @app.call(env) }
|
20
20
|
end
|
@@ -43,14 +43,12 @@ module Chewy
|
|
43
43
|
end
|
44
44
|
|
45
45
|
console do |app|
|
46
|
-
Chewy.logger = ActiveRecord::Base.logger if defined?(ActiveRecord)
|
47
|
-
|
48
46
|
if app.sandbox?
|
49
47
|
Chewy.strategy(:bypass)
|
50
48
|
else
|
51
49
|
Chewy.strategy(:urgent)
|
52
50
|
end
|
53
|
-
|
51
|
+
puts "Chewy console strategy is `#{Chewy.strategy.current.name}`"
|
54
52
|
end
|
55
53
|
|
56
54
|
initializer 'chewy.logger', after: 'active_record.logger' do
|
data/lib/chewy/rake_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Chewy
|
2
2
|
module RakeHelper
|
3
|
-
IMPORT_CALLBACK = lambda do |output, _name, start, finish, _id, payload|
|
3
|
+
IMPORT_CALLBACK = lambda do |output, _name, start, finish, _id, payload|
|
4
4
|
duration = (finish - start).ceil
|
5
5
|
stats = payload.fetch(:import, {}).map { |key, count| "#{key} #{count}" }.join(', ')
|
6
|
-
output.puts " Imported #{payload[:type]}
|
6
|
+
output.puts " Imported #{payload[:type]} in #{human_duration(duration)}, stats: #{stats}"
|
7
7
|
if payload[:errors]
|
8
8
|
payload[:errors].each do |action, errors|
|
9
9
|
output.puts " #{action.to_s.humanize} errors:"
|
@@ -15,7 +15,7 @@ module Chewy
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
JOURNAL_CALLBACK = lambda do |output, _, _, _, _, payload|
|
18
|
+
JOURNAL_CALLBACK = lambda do |output, _, _, _, _, payload|
|
19
19
|
count = payload[:groups].values.map(&:size).sum
|
20
20
|
targets = payload[:groups].keys.sort_by(&:derivable_name)
|
21
21
|
output.puts " Applying journal to #{targets}, #{count} entries, stage #{payload[:stage]}"
|
@@ -196,12 +196,12 @@ module Chewy
|
|
196
196
|
end
|
197
197
|
|
198
198
|
# Eager loads and returns all the indexes defined in the application
|
199
|
-
# except
|
199
|
+
# except Chewy::Stash::Specification and Chewy::Stash::Journal.
|
200
200
|
#
|
201
201
|
# @return [Array<Chewy::Index>] indexes found
|
202
202
|
def all_indexes
|
203
203
|
Chewy.eager_load!
|
204
|
-
Chewy::Index.descendants - [Chewy::Stash]
|
204
|
+
Chewy::Index.descendants - [Chewy::Stash::Journal, Chewy::Stash::Specification]
|
205
205
|
end
|
206
206
|
|
207
207
|
def normalize_indexes(*identifiers)
|
@@ -83,9 +83,7 @@ RSpec::Matchers.define :update_index do |type_name, options = {}| # rubocop:disa
|
|
83
83
|
# .to update_index(UsersIndex.user).and_reindex(user1).only }
|
84
84
|
#
|
85
85
|
chain(:only) do |*_args|
|
86
|
-
if @reindex.blank? && @delete.blank?
|
87
|
-
raise 'Use `only` in conjunction with `and_reindex` or `and_delete`'
|
88
|
-
end
|
86
|
+
raise 'Use `only` in conjunction with `and_reindex` or `and_delete`' if @reindex.blank? && @delete.blank?
|
89
87
|
|
90
88
|
@only = true
|
91
89
|
end
|
@@ -128,13 +126,13 @@ RSpec::Matchers.define :update_index do |type_name, options = {}| # rubocop:disa
|
|
128
126
|
end
|
129
127
|
end
|
130
128
|
|
131
|
-
@reindex.
|
129
|
+
@reindex.each_value do |document|
|
132
130
|
document[:match_count] = (!document[:expected_count] && document[:real_count] > 0) ||
|
133
131
|
(document[:expected_count] && document[:expected_count] == document[:real_count])
|
134
132
|
document[:match_attributes] = document[:expected_attributes].blank? ||
|
135
133
|
compare_attributes(document[:expected_attributes], document[:real_attributes])
|
136
134
|
end
|
137
|
-
@delete.
|
135
|
+
@delete.each_value do |document|
|
138
136
|
document[:match_count] = (!document[:expected_count] && document[:real_count] > 0) ||
|
139
137
|
(document[:expected_count] && document[:expected_count] == document[:real_count])
|
140
138
|
end
|
data/lib/chewy/search.rb
CHANGED
@@ -91,12 +91,12 @@ module Chewy
|
|
91
91
|
|
92
92
|
def build_search_class(base)
|
93
93
|
search_class = Class.new(base)
|
94
|
+
|
94
95
|
if self < Chewy::Type
|
95
96
|
index_scopes = index.scopes - scopes
|
96
|
-
|
97
97
|
delegate_scoped index, search_class, index_scopes
|
98
|
-
delegate_scoped index, self, index_scopes
|
99
98
|
end
|
99
|
+
|
100
100
|
delegate_scoped self, search_class, scopes
|
101
101
|
const_set('Query', search_class)
|
102
102
|
end
|
@@ -20,16 +20,17 @@ module Chewy
|
|
20
20
|
# rendering logic.
|
21
21
|
#
|
22
22
|
# @!attribute must
|
23
|
-
# @return [Array<Hash
|
23
|
+
# @return [Array<Hash>, Hash, nil]
|
24
24
|
# @!attribute should
|
25
|
-
# @return [Array<Hash
|
25
|
+
# @return [Array<Hash>, Hash, nil]
|
26
26
|
# @!attribute must_not
|
27
|
-
# @return [Array<Hash
|
27
|
+
# @return [[Array<Hash>, Hash, nil]
|
28
28
|
# @!attribute minimum_should_match
|
29
29
|
# @return [String, Integer, nil]
|
30
30
|
class Bool
|
31
31
|
# Acceptable bool query keys
|
32
32
|
KEYS = %i[must should must_not minimum_should_match].freeze
|
33
|
+
# @!ignorewarning
|
33
34
|
attr_reader(*KEYS)
|
34
35
|
|
35
36
|
# @param must [Array<Hash>, Hash, nil]
|
data/lib/chewy/stash.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
1
1
|
module Chewy
|
2
2
|
# This class is the main storage for Chewy service data,
|
3
|
-
# Now index raw specifications are stored in the `
|
4
|
-
# index.
|
3
|
+
# Now index raw specifications are stored in the `chewy_specifications`
|
4
|
+
# index.
|
5
|
+
# Journal entries are stored in `chewy_journal`
|
5
6
|
#
|
6
7
|
# @see Chewy::Index::Specification
|
7
|
-
|
8
|
-
|
8
|
+
module Stash
|
9
|
+
class Specification < Chewy::Index
|
10
|
+
index_name 'chewy_specifications'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
define_type :specification do
|
13
|
+
default_import_options journal: false
|
12
14
|
|
13
|
-
|
15
|
+
field :specification, type: 'binary'
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
field :index_name, type: 'string', index: 'not_analyzed'
|
20
|
-
field :type_name, type: 'string', index: 'not_analyzed'
|
21
|
-
field :action, type: 'string', index: 'not_analyzed'
|
22
|
-
field :references, type: 'string', index: 'no'
|
23
|
-
field :created_at, type: 'date'
|
19
|
+
class Journal < Chewy::Index
|
20
|
+
index_name 'chewy_journal'
|
24
21
|
|
25
22
|
# Loads all entries since the specified time.
|
26
23
|
#
|
@@ -52,18 +49,30 @@ module Chewy
|
|
52
49
|
types.group_by(&:index).each do |index, index_types|
|
53
50
|
scope = scope.or(
|
54
51
|
filter(term: {index_name: index.derivable_name})
|
55
|
-
|
52
|
+
.filter(terms: {type_name: index_types.map(&:type_name)})
|
56
53
|
)
|
57
54
|
end
|
58
55
|
scope
|
59
56
|
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
define_type :journal do
|
59
|
+
default_import_options journal: false
|
60
|
+
|
61
|
+
field :index_name, type: 'keyword'
|
62
|
+
field :type_name, type: 'keyword'
|
63
|
+
field :action, type: 'keyword'
|
64
|
+
field :references, type: 'binary'
|
65
|
+
field :created_at, type: 'date'
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
+
def type
|
68
|
+
@type ||= Chewy.derive_type("#{index_name}##{type_name}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def references
|
72
|
+
@references ||= Array.wrap(@attributes['references']).map do |item|
|
73
|
+
JSON.load(Base64.decode64(item)) # rubocop:disable Security/JSONLoad
|
74
|
+
end
|
75
|
+
end
|
67
76
|
end
|
68
77
|
end
|
69
78
|
end
|
@@ -18,7 +18,7 @@ module Chewy
|
|
18
18
|
|
19
19
|
def update(type, objects, _options = {})
|
20
20
|
@stash[type] ||= []
|
21
|
-
@stash[type] |= type.
|
21
|
+
@stash[type] |= type.root.id ? Array.wrap(objects) : type.adapter.identify(objects)
|
22
22
|
end
|
23
23
|
|
24
24
|
def leave
|
data/lib/chewy/type.rb
CHANGED
@@ -14,7 +14,7 @@ require 'chewy/type/witchcraft'
|
|
14
14
|
|
15
15
|
module Chewy
|
16
16
|
class Type
|
17
|
-
IMPORT_OPTIONS_KEYS = %i[batch_size bulk_size refresh consistency replication raw_import journal].freeze
|
17
|
+
IMPORT_OPTIONS_KEYS = %i[batch_size bulk_size refresh consistency replication raw_import journal pipeline].freeze
|
18
18
|
|
19
19
|
include Search
|
20
20
|
include Mapping
|
@@ -34,7 +34,7 @@ module Chewy
|
|
34
34
|
# Chewy index current type belongs to. Defined inside `Chewy.create_type`
|
35
35
|
#
|
36
36
|
def index
|
37
|
-
raise NotImplementedError, 'Looks like this type
|
37
|
+
raise NotImplementedError, 'Looks like this type was defined outside the index scope and `.index` method is undefined for it'
|
38
38
|
end
|
39
39
|
|
40
40
|
# Current type adapter. Defined inside `Chewy.create_type`, derived from
|
@@ -41,19 +41,19 @@ module Chewy
|
|
41
41
|
#
|
42
42
|
# { delete: [object_or_id1, object_or_id2], index: [object3, object4, object5] }
|
43
43
|
#
|
44
|
-
# @
|
44
|
+
# @yieldparam _batch [Array<Object>] each batch of objects
|
45
45
|
# @return [true, false] returns true if all the block call returns true and false otherwise
|
46
|
-
def import(
|
46
|
+
def import(_batch, &_block)
|
47
47
|
raise NotImplementedError
|
48
48
|
end
|
49
49
|
|
50
50
|
# Unlike {#import} fetches only ids (references) to the imported objects,
|
51
51
|
# using the same procedures as {#import}.
|
52
52
|
#
|
53
|
-
# @param
|
54
|
-
# @param
|
55
|
-
# @
|
56
|
-
def import_fields(
|
53
|
+
# @param _fields [Array<Symbol>] additional fields to fetch
|
54
|
+
# @param _batch_size [Integer] batch size, defaults to 1000
|
55
|
+
# @yieldparam batch [Array<Object>] each batch of objects
|
56
|
+
def import_fields(_fields, _batch_size, &_block)
|
57
57
|
raise NotImplementedError
|
58
58
|
end
|
59
59
|
|
@@ -61,9 +61,9 @@ module Chewy
|
|
61
61
|
# an array of references to the passed objects. Returns ids if possible.
|
62
62
|
# Otherwise - and array of objects themselves.
|
63
63
|
#
|
64
|
-
# @param
|
65
|
-
# @
|
66
|
-
def import_references(
|
64
|
+
# @param _batch_size [Integer] batch size, defaults to 1000
|
65
|
+
# @yieldparam batch [Array<Object>] each batch of objects
|
66
|
+
def import_references(_batch_size, &_block)
|
67
67
|
raise NotImplementedError
|
68
68
|
end
|
69
69
|
|
@@ -17,9 +17,7 @@ module Chewy
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def cleanup_default_scope!
|
20
|
-
if Chewy.logger && @default_scope.options.values_at(:sort, :limit, :skip).compact.present?
|
21
|
-
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified')
|
22
|
-
end
|
20
|
+
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified') if Chewy.logger && @default_scope.options.values_at(:sort, :limit, :skip).compact.present?
|
23
21
|
|
24
22
|
@default_scope.options.delete(:limit)
|
25
23
|
@default_scope.options.delete(:skip)
|
@@ -16,9 +16,7 @@ module Chewy
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def cleanup_default_scope!
|
19
|
-
if Chewy.logger && @default_scope != @default_scope.unordered.unlimited
|
20
|
-
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified')
|
21
|
-
end
|
19
|
+
Chewy.logger.warn('Default type scope order, limit and offset are ignored and will be nullified') if Chewy.logger && @default_scope != @default_scope.unordered.unlimited
|
22
20
|
|
23
21
|
@default_scope = @default_scope.unordered.unlimited
|
24
22
|
end
|
@@ -34,7 +32,7 @@ module Chewy
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def full_column_name(column)
|
37
|
-
|
35
|
+
::Sequel.qualify(target.table_name, column)
|
38
36
|
end
|
39
37
|
|
40
38
|
def all_scope
|
@@ -55,7 +53,7 @@ module Chewy
|
|
55
53
|
def pluck_in_batches(scope, fields: [], batch_size: nil, **options)
|
56
54
|
return enum_for(:pluck_in_batches, scope, fields: fields, batch_size: batch_size, **options) unless block_given?
|
57
55
|
|
58
|
-
scope = scope.unordered.order(
|
56
|
+
scope = scope.unordered.order(full_column_name(primary_key).asc).limit(batch_size)
|
59
57
|
|
60
58
|
ids = pluck(scope, fields: fields)
|
61
59
|
count = 0
|
@@ -64,7 +62,7 @@ module Chewy
|
|
64
62
|
yield ids
|
65
63
|
break if ids.size < batch_size
|
66
64
|
last_id = ids.last.is_a?(Array) ? ids.last.first : ids.last
|
67
|
-
ids = pluck(scope.where { |
|
65
|
+
ids = pluck(scope.where { |_o| full_column_name(primary_key) > last_id }, fields: fields)
|
68
66
|
end
|
69
67
|
|
70
68
|
count
|