chewy 0.10.1 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +240 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/.rubocop.yml +25 -25
  7. data/Appraisals +12 -10
  8. data/CHANGELOG.md +312 -331
  9. data/CODE_OF_CONDUCT.md +14 -0
  10. data/CONTRIBUTING.md +63 -0
  11. data/Gemfile +5 -1
  12. data/LICENSE.txt +1 -1
  13. data/README.md +143 -77
  14. data/chewy.gemspec +10 -12
  15. data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.5.2.activerecord.gemfile} +6 -4
  16. data/gemfiles/{rails.4.2.activerecord.gemfile → rails.5.2.mongoid.6.4.gemfile} +6 -4
  17. data/gemfiles/{rails.4.0.activerecord.gemfile → rails.6.0.activerecord.gemfile} +6 -3
  18. data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
  19. data/gemfiles/sequel.4.45.gemfile +2 -2
  20. data/lib/chewy.rb +2 -1
  21. data/lib/chewy/backports/duplicable.rb +1 -1
  22. data/lib/chewy/config.rb +10 -39
  23. data/lib/chewy/fields/base.rb +9 -3
  24. data/lib/chewy/fields/root.rb +13 -9
  25. data/lib/chewy/index.rb +3 -1
  26. data/lib/chewy/index/actions.rb +28 -16
  27. data/lib/chewy/index/aliases.rb +16 -5
  28. data/lib/chewy/index/settings.rb +2 -0
  29. data/lib/chewy/index/specification.rb +12 -10
  30. data/lib/chewy/minitest/helpers.rb +6 -6
  31. data/lib/chewy/minitest/search_index_receiver.rb +17 -17
  32. data/lib/chewy/multi_search.rb +62 -0
  33. data/lib/chewy/railtie.rb +3 -5
  34. data/lib/chewy/rake_helper.rb +5 -5
  35. data/lib/chewy/rspec/update_index.rb +3 -5
  36. data/lib/chewy/search.rb +4 -11
  37. data/lib/chewy/search/loader.rb +1 -1
  38. data/lib/chewy/search/pagination/will_paginate.rb +1 -1
  39. data/lib/chewy/search/parameters.rb +24 -6
  40. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  41. data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
  42. data/lib/chewy/search/parameters/indices.rb +123 -0
  43. data/lib/chewy/search/parameters/none.rb +1 -3
  44. data/lib/chewy/search/request.rb +101 -74
  45. data/lib/chewy/search/scrolling.rb +7 -6
  46. data/lib/chewy/stash.rb +31 -22
  47. data/lib/chewy/strategy/active_job.rb +1 -1
  48. data/lib/chewy/strategy/atomic.rb +1 -1
  49. data/lib/chewy/strategy/sidekiq.rb +1 -1
  50. data/lib/chewy/type.rb +5 -2
  51. data/lib/chewy/type/adapter/active_record.rb +1 -1
  52. data/lib/chewy/type/adapter/base.rb +9 -9
  53. data/lib/chewy/type/adapter/mongoid.rb +2 -4
  54. data/lib/chewy/type/adapter/orm.rb +7 -4
  55. data/lib/chewy/type/adapter/sequel.rb +5 -7
  56. data/lib/chewy/type/crutch.rb +1 -1
  57. data/lib/chewy/type/import.rb +16 -5
  58. data/lib/chewy/type/import/bulk_builder.rb +1 -1
  59. data/lib/chewy/type/import/bulk_request.rb +4 -2
  60. data/lib/chewy/type/import/journal_builder.rb +3 -3
  61. data/lib/chewy/type/import/routine.rb +3 -3
  62. data/lib/chewy/type/mapping.rb +42 -36
  63. data/lib/chewy/type/observe.rb +16 -12
  64. data/lib/chewy/type/syncer.rb +6 -7
  65. data/lib/chewy/type/witchcraft.rb +5 -3
  66. data/lib/chewy/type/wrapper.rb +14 -4
  67. data/lib/chewy/version.rb +1 -1
  68. data/lib/sequel/plugins/chewy_observe.rb +4 -19
  69. data/migration_guide.md +34 -0
  70. data/spec/chewy/config_spec.rb +16 -21
  71. data/spec/chewy/fields/base_spec.rb +68 -70
  72. data/spec/chewy/fields/root_spec.rb +13 -13
  73. data/spec/chewy/index/actions_spec.rb +157 -38
  74. data/spec/chewy/index/aliases_spec.rb +3 -3
  75. data/spec/chewy/index/specification_spec.rb +25 -16
  76. data/spec/chewy/index_spec.rb +75 -45
  77. data/spec/chewy/journal_spec.rb +33 -29
  78. data/spec/chewy/minitest/search_index_receiver_spec.rb +11 -9
  79. data/spec/chewy/multi_search_spec.rb +85 -0
  80. data/spec/chewy/rake_helper_spec.rb +123 -95
  81. data/spec/chewy/rspec/update_index_spec.rb +47 -46
  82. data/spec/chewy/runtime_spec.rb +2 -2
  83. data/spec/chewy/search/parameters/indices_spec.rb +190 -0
  84. data/spec/chewy/search/parameters/none_spec.rb +1 -1
  85. data/spec/chewy/search/parameters_spec.rb +21 -4
  86. data/spec/chewy/search/request_spec.rb +103 -70
  87. data/spec/chewy/search/response_spec.rb +27 -17
  88. data/spec/chewy/search/scrolling_spec.rb +27 -17
  89. data/spec/chewy/search_spec.rb +49 -35
  90. data/spec/chewy/stash_spec.rb +15 -13
  91. data/spec/chewy/strategy/active_job_spec.rb +15 -2
  92. data/spec/chewy/strategy/shoryuken_spec.rb +8 -2
  93. data/spec/chewy/strategy/sidekiq_spec.rb +6 -2
  94. data/spec/chewy/type/adapter/active_record_spec.rb +16 -4
  95. data/spec/chewy/type/import/bulk_builder_spec.rb +9 -94
  96. data/spec/chewy/type/import/journal_builder_spec.rb +17 -15
  97. data/spec/chewy/type/import_spec.rb +15 -0
  98. data/spec/chewy/type/mapping_spec.rb +51 -18
  99. data/spec/chewy/type/observe_spec.rb +4 -4
  100. data/spec/chewy/type/witchcraft_spec.rb +15 -0
  101. data/spec/chewy/type/wrapper_spec.rb +3 -1
  102. data/spec/chewy_spec.rb +0 -7
  103. data/spec/spec_helper.rb +5 -1
  104. data/spec/support/active_record.rb +21 -0
  105. metadata +51 -116
  106. data/.travis.yml +0 -53
  107. data/LEGACY_DSL.md +0 -497
  108. data/gemfiles/rails.4.1.activerecord.gemfile +0 -14
  109. data/gemfiles/rails.5.0.activerecord.gemfile +0 -15
  110. data/gemfiles/rails.5.0.mongoid.6.0.gemfile +0 -15
  111. data/gemfiles/rails.5.1.activerecord.gemfile +0 -15
  112. data/gemfiles/rails.5.1.mongoid.6.1.gemfile +0 -15
  113. data/lib/chewy/query.rb +0 -1098
  114. data/lib/chewy/query/compose.rb +0 -68
  115. data/lib/chewy/query/criteria.rb +0 -191
  116. data/lib/chewy/query/filters.rb +0 -227
  117. data/lib/chewy/query/loading.rb +0 -111
  118. data/lib/chewy/query/nodes/and.rb +0 -25
  119. data/lib/chewy/query/nodes/base.rb +0 -17
  120. data/lib/chewy/query/nodes/bool.rb +0 -34
  121. data/lib/chewy/query/nodes/equal.rb +0 -34
  122. data/lib/chewy/query/nodes/exists.rb +0 -20
  123. data/lib/chewy/query/nodes/expr.rb +0 -28
  124. data/lib/chewy/query/nodes/field.rb +0 -110
  125. data/lib/chewy/query/nodes/has_child.rb +0 -15
  126. data/lib/chewy/query/nodes/has_parent.rb +0 -15
  127. data/lib/chewy/query/nodes/has_relation.rb +0 -59
  128. data/lib/chewy/query/nodes/match_all.rb +0 -11
  129. data/lib/chewy/query/nodes/missing.rb +0 -20
  130. data/lib/chewy/query/nodes/not.rb +0 -25
  131. data/lib/chewy/query/nodes/or.rb +0 -25
  132. data/lib/chewy/query/nodes/prefix.rb +0 -19
  133. data/lib/chewy/query/nodes/query.rb +0 -20
  134. data/lib/chewy/query/nodes/range.rb +0 -63
  135. data/lib/chewy/query/nodes/raw.rb +0 -15
  136. data/lib/chewy/query/nodes/regexp.rb +0 -35
  137. data/lib/chewy/query/nodes/script.rb +0 -20
  138. data/lib/chewy/query/pagination.rb +0 -25
  139. data/spec/chewy/query/criteria_spec.rb +0 -700
  140. data/spec/chewy/query/filters_spec.rb +0 -201
  141. data/spec/chewy/query/loading_spec.rb +0 -124
  142. data/spec/chewy/query/nodes/and_spec.rb +0 -12
  143. data/spec/chewy/query/nodes/bool_spec.rb +0 -14
  144. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  145. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  146. data/spec/chewy/query/nodes/has_child_spec.rb +0 -59
  147. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -59
  148. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  149. data/spec/chewy/query/nodes/missing_spec.rb +0 -16
  150. data/spec/chewy/query/nodes/not_spec.rb +0 -13
  151. data/spec/chewy/query/nodes/or_spec.rb +0 -12
  152. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  153. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  154. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  155. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  156. data/spec/chewy/query/nodes/regexp_spec.rb +0 -43
  157. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  158. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -5
  159. data/spec/chewy/query/pagination/will_paginate_spec.rb +0 -5
  160. data/spec/chewy/query/pagination_spec.rb +0 -39
  161. data/spec/chewy/query_spec.rb +0 -636
  162. data/spec/chewy/search/parameters/indices_boost_spec.rb +0 -83
@@ -13,7 +13,7 @@ module Chewy
13
13
  # * performs the bulk request;
14
14
  # * composes new leftovers bulk for the next iteration basing on the response errors if `update_failover` is true;
15
15
  # * appends the rest of unfixable errors to the instance level errors array.
16
- # 4. Perform the request for the last leftovers bulk if present using {#process_leftovers}.
16
+ # 4. Perform the request for the last leftovers bulk if present using {#extract_leftovers}.
17
17
  # 3. Return the result errors array.
18
18
  #
19
19
  # At the moment, it tries to restore only from the partial document update errors in cases
@@ -64,9 +64,9 @@ module Chewy
64
64
  # Creates the journal index and the type corresponding index if necessary.
65
65
  # @return [Object] whatever
66
66
  def create_indexes!
67
- Chewy::Stash.create if @options[:journal]
67
+ Chewy::Stash::Journal.create if @options[:journal]
68
68
  return if Chewy.configuration[:skip_index_creation_on_import]
69
- @type.index.create!(@bulk_options.slice(:suffix)) unless @type.index.exists?
69
+ @type.index.create!(**@bulk_options.slice(:suffix)) unless @type.index.exists?
70
70
  end
71
71
 
72
72
  # The main process method. Converts passed objects to thr bulk request body,
@@ -17,10 +17,11 @@ module Chewy
17
17
  # definition. Use it only if you need to pass options for root
18
18
  # object mapping, such as `date_detection` or `dynamic_date_formats`
19
19
  #
20
+ # @example
20
21
  # class UsersIndex < Chewy::Index
21
22
  # define_type User do
22
23
  # # root object defined implicitly and optionless for current type
23
- # field :full_name, type: 'string'
24
+ # field :full_name, type: 'keyword'
24
25
  # end
25
26
  # end
26
27
  #
@@ -28,32 +29,37 @@ module Chewy
28
29
  # define_type Car do
29
30
  # # explicit root definition with additional options
30
31
  # root dynamic_date_formats: ['yyyy-MM-dd'] do
31
- # field :model_name, type: 'string'
32
+ # field :model_name, type: 'keyword'
32
33
  # end
33
34
  # end
34
35
  # end
35
36
  #
36
- def root(options = {}, &block)
37
- raise 'Root is already defined' if root_object
38
- build_root(options, &block)
37
+ def root(**options)
38
+ self.root_object ||= Chewy::Fields::Root.new(type_name, **Chewy.default_root_options.merge(options))
39
+ root_object.update_options!(**options)
40
+ yield if block_given?
41
+ root_object
39
42
  end
40
43
 
41
44
  # Defines mapping field for current type
42
45
  #
46
+ # @example
43
47
  # class UsersIndex < Chewy::Index
44
48
  # define_type User do
45
49
  # # passing all the options to field definition:
46
- # field :full_name, type: 'string', analyzer: 'special'
50
+ # field :full_name, analyzer: 'special'
47
51
  # end
48
52
  # end
49
53
  #
50
54
  # The `type` is optional and defaults to `string` if not defined:
51
55
  #
56
+ # @example
52
57
  # field :full_name
53
58
  #
54
59
  # Also, multiple fields might be defined with one call and
55
60
  # with the same options:
56
61
  #
62
+ # @example
57
63
  # field :first_name, :last_name, analyzer: 'special'
58
64
  #
59
65
  # The only special option in the field definition
@@ -61,31 +67,35 @@ module Chewy
61
67
  # method will be called for the indexed object. Also
62
68
  # `:value` might be a proc or indexed object method name:
63
69
  #
70
+ # @example
64
71
  # class User < ActiveRecord::Base
65
72
  # def user_full_name
66
73
  # [first_name, last_name].join(' ')
67
74
  # end
68
75
  # end
69
76
  #
70
- # field :full_name, type: 'string', value: :user_full_name
77
+ # field :full_name, type: 'keyword', value: :user_full_name
71
78
  #
72
79
  # The proc evaluates inside the indexed object context if
73
80
  # its arity is 0 and in present contexts if there is an argument:
74
81
  #
75
- # field :full_name, type: 'string', value: -> { [first_name, last_name].join(' ') }
82
+ # @example
83
+ # field :full_name, type: 'keyword', value: -> { [first_name, last_name].join(' ') }
76
84
  #
77
85
  # separator = ' '
78
- # field :full_name, type: 'string', value: ->(user) { [user.first_name, user.last_name].join(separator) }
86
+ # field :full_name, type: 'keyword', value: ->(user) { [user.first_name, user.last_name].join(separator) }
79
87
  #
80
88
  # If array was returned as value - it will be put in index as well.
81
89
  #
82
- # field :tags, type: 'string', value: -> { tags.map(&:name) }
90
+ # @example
91
+ # field :tags, type: 'keyword', value: -> { tags.map(&:name) }
83
92
  #
84
93
  # Fields supports nesting in case of `object` field type. If
85
94
  # `user.quiz` will return an array of objects, then result index content
86
95
  # will be an array of hashes, if `user.quiz` is not a collection association
87
96
  # then just values hash will be put in the index.
88
97
  #
98
+ # @example
89
99
  # field :quiz do
90
100
  # field :question, :answer
91
101
  # field :score, type: 'integer'
@@ -93,6 +103,7 @@ module Chewy
93
103
  #
94
104
  # Nested fields are composed from nested objects:
95
105
  #
106
+ # @example
96
107
  # field :name, value: -> { name_translations } do
97
108
  # field :ru, value: ->(name) { name['ru'] }
98
109
  # field :en, value: ->(name) { name['en'] }
@@ -101,32 +112,31 @@ module Chewy
101
112
  # Of course it is possible to define object fields contents dynamically
102
113
  # but make sure evaluation proc returns hash:
103
114
  #
115
+ # @example
104
116
  # field :name, type: 'object', value: -> { name_translations }
105
117
  #
106
118
  # The special case is multi_field. If type options and block are
107
119
  # both present field is treated as a multi-field. In that case field
108
120
  # composition changes satisfy elasticsearch rules:
109
121
  #
110
- # field :full_name, type: 'string', analyzer: 'name', value: ->{ full_name.try(:strip) } do
122
+ # @example
123
+ # field :full_name, type: 'text', analyzer: 'name', value: ->{ full_name.try(:strip) } do
111
124
  # field :sorted, analyzer: 'sorted'
112
125
  # end
113
126
  #
114
- def field(*args, &block)
115
- options = args.extract_options!
116
- build_root
117
-
127
+ def field(*args, **options, &block)
118
128
  if args.size > 1
119
- args.map { |name| field(name, options) }
129
+ args.map { |name| field(name, **options) }
120
130
  else
121
- expand_nested(Chewy::Fields::Base.new(args.first, options), &block)
131
+ expand_nested(Chewy::Fields::Base.new(args.first, **options), &block)
122
132
  end
123
133
  end
124
134
 
125
135
  # Defines an aggregation that can be bound to a query or filter
126
136
  #
127
- # Suppose that a user has posts and each post has ratings
128
- # avg_post_rating is the mean of all ratings
129
- #
137
+ # @example
138
+ # # Suppose that a user has posts and each post has ratings
139
+ # # avg_post_rating is the mean of all ratings
130
140
  # class UsersIndex < Chewy::Index
131
141
  # define_type User do
132
142
  # field :posts do
@@ -139,72 +149,68 @@ module Chewy
139
149
  # end
140
150
  # end
141
151
  def agg(name, &block)
142
- build_root
143
152
  self._agg_defs = _agg_defs.merge(name => block)
144
153
  end
145
154
  alias_method :aggregation, :agg
146
155
 
147
156
  # Defines dynamic template in mapping root objects
148
157
  #
158
+ # @example
149
159
  # class CarsIndex < Chewy::Index
150
160
  # define_type Car do
151
- # template 'model.*', type: 'string', analyzer: 'special'
161
+ # template 'model.*', type: 'text', analyzer: 'special'
152
162
  # field 'model', type: 'object' # here we can put { de: 'Der Mercedes', en: 'Mercedes' }
153
163
  # # and template will be applyed to this field
154
164
  # end
155
165
  # end
156
166
  #
157
167
  # Name for each template is generated with the following
158
- # rule: "template_#{dynamic_templates.size + 1}".
168
+ # rule: `template_#!{dynamic_templates.size + 1}`.
159
169
  #
170
+ # @example Templates
160
171
  # template 'tit*', mapping_hash
161
172
  # template 'title.*', mapping_hash # dot in template causes "path_match" using
162
173
  # template /tit.+/, mapping_hash # using "match_pattern": "regexp"
163
174
  # template /title\..+/, mapping_hash # "\." - escaped dot causes "path_match" using
164
- # template /tit.+/, 'string', mapping_hash # "match_mapping_type" as the optionsl second argument
175
+ # template /tit.+/, type: 'text', mapping_hash # "match_mapping_type" as the optionsl second argument
165
176
  # template template42: {match: 'hello*', mapping: {type: 'object'}} # or even pass a template as is
166
177
  #
167
178
  def template(*args)
168
- build_root.dynamic_template(*args)
179
+ root.dynamic_template(*args)
169
180
  end
170
181
  alias_method :dynamic_template, :template
171
182
 
172
183
  # Returns compiled mappings hash for current type
173
184
  #
174
185
  def mappings_hash
175
- root_object ? root_object.mappings_hash : {}
186
+ root.mappings_hash[type_name.to_sym].present? ? root.mappings_hash : {}
176
187
  end
177
188
 
178
189
  # Check whether the type has outdated_sync_field defined with a simple value.
179
190
  #
180
191
  # @return [true, false]
181
192
  def supports_outdated_sync?
182
- updated_at_field = root_object.child_hash[outdated_sync_field] if root_object && outdated_sync_field
193
+ updated_at_field = root.child_hash[outdated_sync_field] if outdated_sync_field
183
194
  !!updated_at_field && updated_at_field.value.nil?
184
195
  end
185
196
 
186
197
  private
187
198
 
188
- def expand_nested(field, &block)
199
+ def expand_nested(field)
200
+ @_current_field ||= root
201
+
189
202
  if @_current_field
190
203
  field.parent = @_current_field
191
204
  @_current_field.children.push(field)
192
205
  end
193
206
 
194
- return unless block
207
+ return unless block_given?
195
208
 
196
209
  previous_field = @_current_field
197
210
  @_current_field = field
198
211
  yield
199
212
  @_current_field = previous_field
200
213
  end
201
-
202
- def build_root(options = {}, &block)
203
- return root_object if root_object
204
- self.root_object = Chewy::Fields::Root.new(type_name, Chewy.default_root_options.merge(options))
205
- expand_nested(root_object, &block)
206
- @_current_field = root_object
207
- end
208
214
  end
209
215
  end
210
216
  end
@@ -9,14 +9,6 @@ module Chewy
9
9
  method = args.first
10
10
 
11
11
  proc do
12
- backreference = if method && method.to_s == 'self'
13
- self
14
- elsif method
15
- send(method)
16
- else
17
- instance_eval(&block)
18
- end
19
-
20
12
  reference = if type_name.is_a?(Proc)
21
13
  if type_name.arity.zero?
22
14
  instance_exec(&type_name)
@@ -27,7 +19,19 @@ module Chewy
27
19
  type_name
28
20
  end
29
21
 
30
- Chewy.derive_type(reference).update_index(backreference, options)
22
+ type = Chewy.derive_type(reference)
23
+
24
+ next if Chewy.strategy.current.name == :bypass
25
+
26
+ backreference = if method && method.to_s == 'self'
27
+ self
28
+ elsif method
29
+ send(method)
30
+ else
31
+ instance_eval(&block)
32
+ end
33
+
34
+ type.update_index(backreference, options)
31
35
  end
32
36
  end
33
37
 
@@ -59,10 +63,10 @@ module Chewy
59
63
  update_proc = Observe.update_proc(type_name, *args, &block)
60
64
 
61
65
  if Chewy.use_after_commit_callbacks
62
- after_commit(callback_options, &update_proc)
66
+ after_commit(**callback_options, &update_proc)
63
67
  else
64
- after_save(callback_options, &update_proc)
65
- after_destroy(callback_options, &update_proc)
68
+ after_save(**callback_options, &update_proc)
69
+ after_destroy(**callback_options, &update_proc)
66
70
  end
67
71
  end
68
72
  end
@@ -2,7 +2,7 @@ module Chewy
2
2
  class Type
3
3
  # This class is able to find missing and outdated documents in the ES
4
4
  # comparing ids from the data source and the ES index. Also, if `outdated_sync_field`
5
- # existss in the index definition, it performs comparison of this field
5
+ # exists in the index definition, it performs comparison of this field
6
6
  # values for each source object and corresponding ES document. Usually,
7
7
  # this field is `updated_at` and if its value in the source is not equal
8
8
  # to the value in the index - this means that this document outdated and
@@ -34,7 +34,7 @@ module Chewy
34
34
  next unless source_data_hash[id]
35
35
 
36
36
  outdated = if outdated_sync_field_type == 'date'
37
- !Chewy::Type::Syncer.dates_equal(typecast_date(source_data_hash[id]), DateTime.iso8601(index_sync_value))
37
+ !Chewy::Type::Syncer.dates_equal(typecast_date(source_data_hash[id]), Time.iso8601(index_sync_value))
38
38
  else
39
39
  source_data_hash[id] != index_sync_value
40
40
  end
@@ -57,7 +57,7 @@ module Chewy
57
57
  if string.is_a?(String) && (match = ISO_DATETIME.match(string))
58
58
  microsec = (match[7].to_r * 1_000_000).to_i
59
59
  date = "#{match[1]}-#{match[2]}-#{match[3]}T#{match[4]}:#{match[5]}:#{match[6]}.#{format('%06d', microsec)}+00:00"
60
- DateTime.iso8601(date)
60
+ Time.iso8601(date)
61
61
  else
62
62
  string
63
63
  end
@@ -205,10 +205,9 @@ module Chewy
205
205
  return @outdated_sync_field_type if instance_variable_defined?(:@outdated_sync_field_type)
206
206
  return unless @type.outdated_sync_field
207
207
 
208
- mappings = @type.client.indices.get_mapping(
209
- index: @type.index_name,
210
- type: @type.type_name
211
- ).values.first.fetch('mappings', {})
208
+ args = {index: @type.index_name, type: @type.type_name}
209
+ args[:include_type_name] = true if Runtime.version >= '6.7.0'
210
+ mappings = @type.client.indices.get_mapping(**args).values.first.fetch('mappings', {})
212
211
 
213
212
  @outdated_sync_field_type = mappings
214
213
  .fetch(@type.type_name, {})
@@ -58,9 +58,9 @@ module Chewy
58
58
  private
59
59
 
60
60
  def alicorn
61
- @alicorn ||= class_eval <<-RUBY
61
+ @alicorn ||= singleton_class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
62
62
  -> (locals, object0, crutches) do
63
- #{composed_values(@type.root_object, 0)}
63
+ #{composed_values(@type.root, 0)}
64
64
  end
65
65
  RUBY
66
66
  end
@@ -79,7 +79,9 @@ module Chewy
79
79
  if field.children.present? && !field.multi_field?
80
80
  <<-RUBY
81
81
  (result#{nesting} = #{fetcher}
82
- if result#{nesting}.respond_to?(:to_ary)
82
+ if result#{nesting}.nil?
83
+ nil
84
+ elsif result#{nesting}.respond_to?(:to_ary)
83
85
  result#{nesting}.map do |object#{nesting}|
84
86
  #{composed_values(field, nesting)}
85
87
  end
@@ -41,7 +41,7 @@ module Chewy
41
41
 
42
42
  %w[_id _type _index].each do |name|
43
43
  define_method name do
44
- data[name]
44
+ _data[name]
45
45
  end
46
46
  end
47
47
 
@@ -49,6 +49,8 @@ module Chewy
49
49
  m = method.to_s
50
50
  if (name = highlight_name(m))
51
51
  highlight(name)
52
+ elsif (name = highlight_names(m))
53
+ highlights(name)
52
54
  elsif @attributes.key?(m)
53
55
  @attributes[m]
54
56
  elsif attribute_defined?(m)
@@ -60,7 +62,7 @@ module Chewy
60
62
 
61
63
  def respond_to_missing?(method, include_private = false)
62
64
  m = method.to_s
63
- highlight_name(m) || @attributes.key?(m) || attribute_defined?(m) || super
65
+ highlight_name(m) || highlight_names(m) || @attributes.key?(m) || attribute_defined?(m) || super
64
66
  end
65
67
 
66
68
  private
@@ -69,12 +71,20 @@ module Chewy
69
71
  method.sub(/_highlight\z/, '') if method.end_with?('_highlight')
70
72
  end
71
73
 
74
+ def highlight_names(method)
75
+ method.sub(/_highlights\z/, '') if method.end_with?('_highlights')
76
+ end
77
+
72
78
  def attribute_defined?(attribute)
73
- self.class.root_object && self.class.root_object.children.find { |a| a.name.to_s == attribute }.present?
79
+ self.class.root && self.class.root.children.find { |a| a.name.to_s == attribute }.present?
74
80
  end
75
81
 
76
82
  def highlight(attribute)
77
- _data['highlight'][attribute].first
83
+ _data['highlight'][attribute].first if highlight?(attribute)
84
+ end
85
+
86
+ def highlights(attribute)
87
+ _data['highlight'][attribute] if highlight?(attribute)
78
88
  end
79
89
 
80
90
  def highlight?(attribute)
data/lib/chewy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chewy
2
- VERSION = '0.10.1'.freeze
2
+ VERSION = '7.0.0'.freeze
3
3
  end
@@ -36,40 +36,25 @@ module Sequel
36
36
  callback_options = ChewyObserve.extract_callback_options!(args)
37
37
  update_proc = ChewyObserve.update_proc(type_name, *args, &block)
38
38
 
39
- if Chewy.use_after_commit_callbacks
40
- set_callback(:commit, callback_options, &update_proc)
41
- set_callback(:destroy_commit, callback_options, &update_proc)
42
- else
43
- set_callback(:save, callback_options, &update_proc)
44
- set_callback(:destroy, callback_options, &update_proc)
45
- end
39
+ set_callback(:save, callback_options, &update_proc)
40
+ set_callback(:destroy, callback_options, &update_proc)
46
41
  end
47
42
  end
48
43
 
49
44
  # Instance level methods for Sequel::Model
50
45
  #
51
46
  module InstanceMethods
52
- def after_commit
53
- run_callbacks(:commit) do
54
- super
55
- end
56
- end
57
-
58
- def after_destroy_commit
59
- run_callbacks(:destroy_commit) do
60
- super
61
- end
62
- end
63
-
64
47
  def after_save
65
48
  run_callbacks(:save) do
66
49
  super
50
+ db.after_commit {} if Chewy.use_after_commit_callbacks
67
51
  end
68
52
  end
69
53
 
70
54
  def after_destroy
71
55
  run_callbacks(:destroy) do
72
56
  super
57
+ db.after_commit {} if Chewy.use_after_commit_callbacks
73
58
  end
74
59
  end
75
60
  end