chewy 0.10.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +25 -25
  3. data/.travis.yml +21 -29
  4. data/Appraisals +27 -9
  5. data/CHANGELOG.md +36 -0
  6. data/Gemfile +3 -1
  7. data/README.md +73 -23
  8. data/chewy.gemspec +6 -8
  9. data/gemfiles/rails.4.0.activerecord.gemfile +1 -0
  10. data/gemfiles/rails.4.1.activerecord.gemfile +1 -0
  11. data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
  12. data/gemfiles/{rails.4.2.mongoid.5.1.gemfile → rails.4.2.mongoid.5.2.gemfile} +2 -1
  13. data/gemfiles/rails.5.0.activerecord.gemfile +2 -1
  14. data/gemfiles/{rails.5.0.mongoid.6.0.gemfile → rails.5.0.mongoid.6.1.gemfile} +3 -2
  15. data/gemfiles/rails.5.1.activerecord.gemfile +2 -1
  16. data/gemfiles/{rails.5.1.mongoid.6.1.gemfile → rails.5.1.mongoid.6.3.gemfile} +3 -2
  17. data/gemfiles/rails.5.2.activerecord.gemfile +16 -0
  18. data/gemfiles/sequel.4.45.gemfile +2 -2
  19. data/lib/chewy.rb +1 -0
  20. data/lib/chewy/config.rb +8 -19
  21. data/lib/chewy/fields/base.rb +15 -3
  22. data/lib/chewy/fields/root.rb +13 -9
  23. data/lib/chewy/index.rb +1 -1
  24. data/lib/chewy/index/actions.rb +14 -12
  25. data/lib/chewy/index/settings.rb +2 -0
  26. data/lib/chewy/index/specification.rb +12 -10
  27. data/lib/chewy/minitest/helpers.rb +6 -6
  28. data/lib/chewy/minitest/search_index_receiver.rb +17 -17
  29. data/lib/chewy/query.rb +135 -96
  30. data/lib/chewy/query/filters.rb +20 -3
  31. data/lib/chewy/query/loading.rb +0 -1
  32. data/lib/chewy/railtie.rb +2 -4
  33. data/lib/chewy/rake_helper.rb +5 -5
  34. data/lib/chewy/rspec/update_index.rb +3 -5
  35. data/lib/chewy/search.rb +2 -2
  36. data/lib/chewy/search/parameters/concerns/query_storage.rb +4 -3
  37. data/lib/chewy/stash.rb +30 -21
  38. data/lib/chewy/strategy/atomic.rb +1 -1
  39. data/lib/chewy/type.rb +2 -2
  40. data/lib/chewy/type/adapter/base.rb +9 -9
  41. data/lib/chewy/type/adapter/mongoid.rb +1 -3
  42. data/lib/chewy/type/adapter/sequel.rb +4 -6
  43. data/lib/chewy/type/crutch.rb +1 -1
  44. data/lib/chewy/type/import.rb +3 -2
  45. data/lib/chewy/type/import/bulk_builder.rb +1 -1
  46. data/lib/chewy/type/import/journal_builder.rb +3 -3
  47. data/lib/chewy/type/import/routine.rb +2 -2
  48. data/lib/chewy/type/mapping.rb +40 -34
  49. data/lib/chewy/type/observe.rb +13 -9
  50. data/lib/chewy/type/syncer.rb +2 -2
  51. data/lib/chewy/type/witchcraft.rb +2 -2
  52. data/lib/chewy/type/wrapper.rb +2 -2
  53. data/lib/chewy/version.rb +1 -1
  54. data/lib/sequel/plugins/chewy_observe.rb +4 -19
  55. data/spec/chewy/config_spec.rb +16 -0
  56. data/spec/chewy/fields/base_spec.rb +61 -65
  57. data/spec/chewy/fields/root_spec.rb +13 -13
  58. data/spec/chewy/index/actions_spec.rb +37 -5
  59. data/spec/chewy/index/specification_spec.rb +25 -16
  60. data/spec/chewy/index_spec.rb +61 -8
  61. data/spec/chewy/journal_spec.rb +11 -11
  62. data/spec/chewy/query/filters_spec.rb +1 -1
  63. data/spec/chewy/query/nodes/not_spec.rb +1 -0
  64. data/spec/chewy/query_spec.rb +3 -2
  65. data/spec/chewy/rake_helper_spec.rb +46 -33
  66. data/spec/chewy/search_spec.rb +20 -10
  67. data/spec/chewy/stash_spec.rb +1 -1
  68. data/spec/chewy/strategy/shoryuken_spec.rb +2 -0
  69. data/spec/chewy/type/import/journal_builder_spec.rb +8 -8
  70. data/spec/chewy/type/import_spec.rb +6 -0
  71. data/spec/chewy/type/mapping_spec.rb +48 -17
  72. data/spec/spec_helper.rb +8 -0
  73. metadata +26 -25
@@ -6,14 +6,14 @@ module Chewy
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  # Assert that an index *changes* during a block.
9
- # @param (Chewy::Type) index the index / type to watch, eg EntitiesIndex::Entity.
10
- # @param (Symbol) strategy the Chewy strategy to use around the block. See Chewy docs.
11
- # @param (boolean) assert the index changes
12
- # @param (boolean) bypass_actual_index
9
+ # @param index [Chewy::Type] the index / type to watch, eg EntitiesIndex::Entity.
10
+ # @param strategy [Symbol] the Chewy strategy to use around the block. See Chewy docs.
11
+ # @param bypass_actual_index [true, false]
13
12
  # True to preempt the http call to Elastic, false otherwise.
14
13
  # Should be set to true unless actually testing search functionality.
15
14
  #
16
- # @return (SearchIndexReceiver) for optional further assertions on the nature of the index changes.
15
+ # @return [SearchIndexReceiver] for optional further assertions on the nature of the index changes.
16
+ #
17
17
  def assert_indexes(index, strategy: :atomic, bypass_actual_index: true)
18
18
  type = Chewy.derive_type index
19
19
  receiver = SearchIndexReceiver.new
@@ -43,7 +43,7 @@ module Chewy
43
43
 
44
44
  # Run indexing for the database changes during the block provided.
45
45
  # By default, indexing is run at the end of the block.
46
- # @param (Symbol) strategy the Chewy index update strategy see Chewy docs.
46
+ # @param strategy [Symbol] the Chewy index update strategy see Chewy docs.
47
47
  def run_indexing(strategy: :atomic)
48
48
  Chewy.strategy strategy do
49
49
  yield
@@ -1,17 +1,17 @@
1
1
  # Test helper class to provide minitest hooks for Chewy::Index testing.
2
2
  #
3
3
  # @note Intended to be used in conjunction with a test helper which mocks over the #bulk
4
- # method on a Chewy::Type class. (See SearchTestHelper)
4
+ # method on a {Chewy::Type} class. (See SearchTestHelper)
5
5
  #
6
- # The class will capture the data from the *param on the Chewy::Type#bulk method and
6
+ # The class will capture the data from the *param on the Chewy::Type.bulk method and
7
7
  # aggregate the data for test analysis.
8
8
  class SearchIndexReceiver
9
9
  def initialize
10
10
  @mutations = {}
11
11
  end
12
12
 
13
- # @param bulk_params the bulk_params that should be sent to the Chewy::Type#bulk method.
14
- # @param (Chewy::Type) type the Index::Type executing this query.
13
+ # @param bulk_params [Hash] the bulk_params that should be sent to the Chewy::Type.bulk method.
14
+ # @param type [Chewy::Type] the type executing this query.
15
15
  def catch(bulk_params, type)
16
16
  Array.wrap(bulk_params).map { |y| y[:body] }.flatten.each do |update|
17
17
  if update[:delete]
@@ -22,8 +22,8 @@ class SearchIndexReceiver
22
22
  end
23
23
  end
24
24
 
25
- # @param index return only index requests to the specified Chewy::Type index.
26
- # @return the index changes captured by the mock.
25
+ # @param index [Chewy::Index] return only index requests to the specified {Chewy::Type} index.
26
+ # @return [Hash] the index changes captured by the mock.
27
27
  def indexes_for(index = nil)
28
28
  if index
29
29
  mutation_for(index).indexes
@@ -35,8 +35,8 @@ class SearchIndexReceiver
35
35
  end
36
36
  alias_method :indexes, :indexes_for
37
37
 
38
- # @param index return only delete requests to the specified Chewy::Type index.
39
- # @return the index deletes captured by the mock.
38
+ # @param index [Chewy::Index] return only delete requests to the specified {Chewy::Type} index.
39
+ # @return [Hash] the index deletes captured by the mock.
40
40
  def deletes_for(index = nil)
41
41
  if index
42
42
  mutation_for(index).deletes
@@ -49,22 +49,22 @@ class SearchIndexReceiver
49
49
  alias_method :deletes, :deletes_for
50
50
 
51
51
  # Check to see if a given object has been indexed.
52
- # @param (#id) obj the object to look for.
53
- # @param Chewy::Type what type the object should be indexed as.
54
- # @return bool if the object was indexed.
52
+ # @param obj [#id] obj the object to look for.
53
+ # @param type [Chewy::Type] what type the object should be indexed as.
54
+ # @return [true, false] if the object was indexed.
55
55
  def indexed?(obj, type)
56
56
  indexes_for(type).map { |i| i[:_id] }.include? obj.id
57
57
  end
58
58
 
59
59
  # Check to see if a given object has been deleted.
60
- # @param (#id) obj the object to look for.
61
- # @param Chewy::Type what type the object should have been deleted from.
62
- # @return bool if the object was deleted.
60
+ # @param obj [#id] obj the object to look for.
61
+ # @param type [Chewy::Type] what type the object should have been deleted from.
62
+ # @return [true, false] if the object was deleted.
63
63
  def deleted?(obj, type)
64
64
  deletes_for(type).include? obj.id
65
65
  end
66
66
 
67
- # @return a list of Chewy::Type indexes changed.
67
+ # @return [Array<Chewy::Type>] a list of types indexes changed.
68
68
  def updated_indexes
69
69
  @mutations.keys
70
70
  end
@@ -72,8 +72,8 @@ class SearchIndexReceiver
72
72
  private
73
73
 
74
74
  # Get the mutation object for a given type.
75
- # @param (Chewy::Type) type the index type to fetch.
76
- # @return (#indexes, #deletes) an object with a list of indexes and a list of deletes.
75
+ # @param type [Chewy::Type] the index type to fetch.
76
+ # @return [#indexes, #deletes] an object with a list of indexes and a list of deletes.
77
77
  def mutation_for(type)
78
78
  @mutations[type] ||= OpenStruct.new(indexes: [], deletes: [])
79
79
  end
@@ -8,6 +8,7 @@ module Chewy
8
8
  # chainable DSL. Queries are lazy evaluated and might be merged.
9
9
  # The same DSL is used for whole index or individual types query build.
10
10
  #
11
+ # @example
11
12
  # UsersIndex.filter{ age < 42 }.query(text: {name: 'Alex'}).limit(20)
12
13
  # UsersIndex::User.filter{ age < 42 }.query(text: {name: 'Alex'}).limit(20)
13
14
  #
@@ -43,6 +44,7 @@ module Chewy
43
44
  # If other is collection - search request is executed and
44
45
  # result is used for comparation
45
46
  #
47
+ # @example
46
48
  # UsersIndex.filter(term: {name: 'Johny'}) == UsersIndex.filter(term: {name: 'Johny'}) # => true
47
49
  # UsersIndex.filter(term: {name: 'Johny'}) == UsersIndex.filter(term: {name: 'Johny'}).to_a # => true
48
50
  # UsersIndex.filter(term: {name: 'Johny'}) == UsersIndex.filter(term: {name: 'Winnie'}) # => false
@@ -51,23 +53,27 @@ module Chewy
51
53
  super || other.is_a?(self.class) ? other.criteria == criteria : other == to_a
52
54
  end
53
55
 
54
- # Adds <tt>explain</tt> parameter to search request.
56
+ # Adds `explain` parameter to search request.
55
57
  #
58
+ # @example
56
59
  # UsersIndex.filter(term: {name: 'Johny'}).explain
57
60
  # UsersIndex.filter(term: {name: 'Johny'}).explain(true)
58
61
  # UsersIndex.filter(term: {name: 'Johny'}).explain(false)
59
62
  #
60
63
  # Calling explain without any arguments sets explanation flag to true.
61
- # With <tt>explain: true</tt>, every result object has <tt>_explanation</tt>
64
+ # With `explain: true`, every result object has `_explanation`
62
65
  # method
63
66
  #
67
+ # @example
64
68
  # UsersIndex::User.filter(term: {name: 'Johny'}).explain.first._explanation # => {...}
65
69
  #
66
70
  def explain(value = nil)
67
71
  chain { criteria.update_request_options explain: (value.nil? ? true : value) }
68
72
  end
69
73
 
70
- # Adds <tt>script_fields</tt> parameter to search request.
74
+ # Adds `script_fields` parameter to search request.
75
+ #
76
+ # @example
71
77
  # UsersIndex.script_fields(
72
78
  # distance: {
73
79
  # params: {
@@ -85,31 +91,28 @@ module Chewy
85
91
  # Not used if only one filter for search is specified.
86
92
  # Possible values:
87
93
  #
88
- # * <tt>:must</tt>
89
- # Default value. Query compiles into a bool <tt>must</tt> query.
90
- #
91
- # Ex:
94
+ # * `:must`
95
+ # Default value. Query compiles into a bool `must` query.
92
96
  #
97
+ # @example
93
98
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}})
94
99
  # # => {body: {
95
100
  # query: {bool: {must: [{text: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}}
96
101
  # }}
97
102
  #
98
- # * <tt>:should</tt>
99
- # Query compiles into a bool <tt>should</tt> query.
100
- #
101
- # Ex:
103
+ # * `:should`
104
+ # Query compiles into a bool `should` query.
102
105
  #
106
+ # @example
103
107
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}}).query_mode(:should)
104
108
  # # => {body: {
105
109
  # query: {bool: {should: [{text: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}}
106
110
  # }}
107
111
  #
108
- # * Any acceptable <tt>minimum_should_match</tt> value (1, '2', '75%')
109
- # Query compiles into a bool <tt>should</tt> query with <tt>minimum_should_match</tt> set.
110
- #
111
- # Ex:
112
+ # * Any acceptable `minimum_should_match` value (1, '2', '75%')
113
+ # Query compiles into a bool `should` query with `minimum_should_match` set.
112
114
  #
115
+ # @example
113
116
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}}).query_mode('50%')
114
117
  # # => {body: {
115
118
  # query: {bool: {
@@ -118,21 +121,19 @@ module Chewy
118
121
  # }}
119
122
  # }}
120
123
  #
121
- # * <tt>:dis_max</tt>
122
- # Query compiles into a <tt>dis_max</tt> query.
123
- #
124
- # Ex:
124
+ # * `:dis_max`
125
+ # Query compiles into a `dis_max` query.
125
126
  #
127
+ # @example
126
128
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}}).query_mode(:dis_max)
127
129
  # # => {body: {
128
130
  # query: {dis_max: {queries: [{text: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}}
129
131
  # }}
130
132
  #
131
133
  # * Any Float value (0.0, 0.7, 1.0)
132
- # Query compiles into a <tt>dis_max</tt> query with <tt>tie_breaker</tt> option set.
133
- #
134
- # Ex:
134
+ # Query compiles into a `dis_max` query with `tie_breaker` option set.
135
135
  #
136
+ # @example
136
137
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}}).query_mode(0.7)
137
138
  # # => {body: {
138
139
  # query: {dis_max: {
@@ -141,9 +142,10 @@ module Chewy
141
142
  # }}
142
143
  # }}
143
144
  #
144
- # Default value for <tt>:query_mode</tt> might be changed
145
- # with <tt>Chewy.query_mode</tt> config option.
145
+ # Default value for `:query_mode` might be changed
146
+ # with `Chewy.query_mode` config option.
146
147
  #
148
+ # @example
147
149
  # Chewy.query_mode = :dis_max
148
150
  # Chewy.query_mode = '50%'
149
151
  #
@@ -155,55 +157,50 @@ module Chewy
155
157
  # Not used if only one filter for search is specified.
156
158
  # Possible values:
157
159
  #
158
- # * <tt>:and</tt>
159
- # Default value. Filter compiles into an <tt>and</tt> filter.
160
- #
161
- # Ex:
160
+ # * `:and`
161
+ # Default value. Filter compiles into an `and` filter.
162
162
  #
163
+ # @example
163
164
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }
164
165
  # # => {body: {query: {filtered: {
165
166
  # query: {...},
166
167
  # filter: {and: [{term: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}
167
168
  # }}}}
168
169
  #
169
- # * <tt>:or</tt>
170
- # Filter compiles into an <tt>or</tt> filter.
171
- #
172
- # Ex:
170
+ # * `:or`
171
+ # Filter compiles into an `or` filter.
173
172
  #
173
+ # @example
174
174
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }.filter_mode(:or)
175
175
  # # => {body: {query: {filtered: {
176
176
  # query: {...},
177
177
  # filter: {or: [{term: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}
178
178
  # }}}}
179
179
  #
180
- # * <tt>:must</tt>
181
- # Filter compiles into a bool <tt>must</tt> filter.
182
- #
183
- # Ex:
180
+ # * `:must`
181
+ # Filter compiles into a bool `must` filter.
184
182
  #
183
+ # @example
185
184
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }.filter_mode(:must)
186
185
  # # => {body: {query: {filtered: {
187
186
  # query: {...},
188
187
  # filter: {bool: {must: [{term: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}}
189
188
  # }}}}
190
189
  #
191
- # * <tt>:should</tt>
192
- # Filter compiles into a bool <tt>should</tt> filter.
193
- #
194
- # Ex:
190
+ # * `:should`
191
+ # Filter compiles into a bool `should` filter.
195
192
  #
193
+ # @example
196
194
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }.filter_mode(:should)
197
195
  # # => {body: {query: {filtered: {
198
196
  # query: {...},
199
197
  # filter: {bool: {should: [{term: {name: 'Johny'}}, {range: {age: {lte: 42}}}]}}
200
198
  # }}}}
201
199
  #
202
- # * Any acceptable <tt>minimum_should_match</tt> value (1, '2', '75%')
203
- # Filter compiles into bool <tt>should</tt> filter with <tt>minimum_should_match</tt> set.
204
- #
205
- # Ex:
200
+ # * Any acceptable `minimum_should_match` value (1, '2', '75%')
201
+ # Filter compiles into bool `should` filter with `minimum_should_match` set.
206
202
  #
203
+ # @example
207
204
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }.filter_mode('50%')
208
205
  # # => {body: {query: {filtered: {
209
206
  # query: {...},
@@ -213,9 +210,10 @@ module Chewy
213
210
  # }}
214
211
  # }}}}
215
212
  #
216
- # Default value for <tt>:filter_mode</tt> might be changed
217
- # with <tt>Chewy.filter_mode</tt> config option.
213
+ # Default value for `:filter_mode` might be changed
214
+ # with `Chewy.filter_mode` config option.
218
215
  #
216
+ # @example
219
217
  # Chewy.filter_mode = :should
220
218
  # Chewy.filter_mode = '50%'
221
219
  #
@@ -227,6 +225,7 @@ module Chewy
227
225
  # Note that it fallbacks by default to `Chewy.filter_mode` if
228
226
  # `Chewy.post_filter_mode` is nil.
229
227
  #
228
+ # @example
230
229
  # UsersIndex.post_filter{ name == 'Johny' }.post_filter{ age <= 42 }.post_filter_mode(:and)
231
230
  # UsersIndex.post_filter{ name == 'Johny' }.post_filter{ age <= 42 }.post_filter_mode(:should)
232
231
  # UsersIndex.post_filter{ name == 'Johny' }.post_filter{ age <= 42 }.post_filter_mode('50%')
@@ -250,6 +249,7 @@ module Chewy
250
249
  # The response to a search request will indicate whether the search timed
251
250
  # out and how many shards responded successfully:
252
251
  #
252
+ # @example
253
253
  # ...
254
254
  # "timed_out": true,
255
255
  # "_shards": {
@@ -267,6 +267,7 @@ module Chewy
267
267
  # responding with an error. The timeout parameter can be used to explicitly
268
268
  # specify how long it waits.
269
269
  #
270
+ # @example
270
271
  # UsersIndex.timeout("5000ms")
271
272
  #
272
273
  # Timeout is not a circuit breaker.
@@ -284,9 +285,10 @@ module Chewy
284
285
  chain { criteria.update_request_options timeout: value }
285
286
  end
286
287
 
287
- # Sets elasticsearch <tt>size</tt> search request param
288
+ # Sets elasticsearch `size` search request param
288
289
  # Default value is set in the elasticsearch and is 10.
289
290
  #
291
+ # @example
290
292
  # UsersIndex.filter{ name == 'Johny' }.limit(100)
291
293
  # # => {body: {
292
294
  # query: {...},
@@ -297,8 +299,9 @@ module Chewy
297
299
  chain { criteria.update_request_options size: block || Integer(value) }
298
300
  end
299
301
 
300
- # Sets elasticsearch <tt>from</tt> search request param
302
+ # Sets elasticsearch `from` search request param
301
303
  #
304
+ # @example
302
305
  # UsersIndex.filter{ name == 'Johny' }.offset(300)
303
306
  # # => {body: {
304
307
  # query: {...},
@@ -311,6 +314,7 @@ module Chewy
311
314
 
312
315
  # Elasticsearch highlight query option support
313
316
  #
317
+ # @example
314
318
  # UsersIndex.query(...).highlight(fields: { ... })
315
319
  #
316
320
  def highlight(value)
@@ -319,6 +323,7 @@ module Chewy
319
323
 
320
324
  # Elasticsearch rescore query option support
321
325
  #
326
+ # @example
322
327
  # UsersIndex.query(...).rescore(query: { ... })
323
328
  #
324
329
  def rescore(value)
@@ -327,7 +332,8 @@ module Chewy
327
332
 
328
333
  # Elasticsearch minscore option support
329
334
  #
330
- # UsersIndex.query(...).min_score(0.5)
335
+ # @example
336
+ # UsersIndex.query(...).min_score(0.5)
331
337
  #
332
338
  def min_score(value)
333
339
  chain { criteria.update_request_options min_score: value }
@@ -335,7 +341,8 @@ module Chewy
335
341
 
336
342
  # Elasticsearch track_scores option support
337
343
  #
338
- # UsersIndex.query(...).track_scores(true)
344
+ # @example
345
+ # UsersIndex.query(...).track_scores(true)
339
346
  #
340
347
  def track_scores(value)
341
348
  chain { criteria.update_request_options track_scores: value }
@@ -345,6 +352,7 @@ module Chewy
345
352
  # All the chained facets a merged and added to the
346
353
  # search request
347
354
  #
355
+ # @example
348
356
  # UsersIndex.facets(tags: {terms: {field: 'tags'}}).facets(ages: {terms: {field: 'age'}})
349
357
  # # => {body: {
350
358
  # query: {...},
@@ -365,8 +373,9 @@ module Chewy
365
373
 
366
374
  # Adds a script function to score the search request. All scores are
367
375
  # added to the search request and combinded according to
368
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
376
+ # `boost_mode` and `score_mode`
369
377
  #
378
+ # @example
370
379
  # UsersIndex.script_score("doc['boost'].value", params: { modifier: 2 })
371
380
  # # => {body:
372
381
  # query: {
@@ -387,11 +396,12 @@ module Chewy
387
396
 
388
397
  # Adds a boost factor to the search request. All scores are
389
398
  # added to the search request and combinded according to
390
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
399
+ # `boost_mode` and `score_mode`
391
400
  #
392
401
  # This probably only makes sense if you specify a filter
393
402
  # for the boost factor as well
394
403
  #
404
+ # @example
395
405
  # UsersIndex.boost_factor(23, filter: { term: { foo: :bar} })
396
406
  # # => {body:
397
407
  # query: {
@@ -409,11 +419,12 @@ module Chewy
409
419
 
410
420
  # Add a weight scoring function to the search. All scores are
411
421
  # added to the search request and combinded according to
412
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
422
+ # `boost_mode` and `score_mode`
413
423
  #
414
424
  # This probably only makes sense if you specify a filter
415
425
  # for the weight as well.
416
426
  #
427
+ # @example
417
428
  # UsersIndex.weight(23, filter: { term: { foo: :bar} })
418
429
  # # => {body:
419
430
  # query: {
@@ -431,13 +442,14 @@ module Chewy
431
442
 
432
443
  # Adds a random score to the search request. All scores are
433
444
  # added to the search request and combinded according to
434
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
445
+ # `boost_mode` and `score_mode`
435
446
  #
436
447
  # This probably only makes sense if you specify a filter
437
448
  # for the random score as well.
438
449
  #
439
450
  # If you do not pass in a seed value, Time.now will be used
440
451
  #
452
+ # @example
441
453
  # UsersIndex.random_score(23, filter: { foo: :bar})
442
454
  # # => {body:
443
455
  # query: {
@@ -455,11 +467,12 @@ module Chewy
455
467
 
456
468
  # Add a field value scoring to the search. All scores are
457
469
  # added to the search request and combinded according to
458
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
470
+ # `boost_mode` and `score_mode`
459
471
  #
460
472
  # This function is only available in Elasticsearch 1.2 and
461
473
  # greater
462
474
  #
475
+ # @example
463
476
  # UsersIndex.field_value_factor(
464
477
  # {
465
478
  # field: :boost,
@@ -486,11 +499,12 @@ module Chewy
486
499
 
487
500
  # Add a decay scoring to the search. All scores are
488
501
  # added to the search request and combinded according to
489
- # <tt>boost_mode</tt> and <tt>score_mode</tt>
502
+ # `boost_mode` and `score_mode`
490
503
  #
491
504
  # The parameters have default values, but those may not
492
505
  # be very useful for most applications.
493
506
  #
507
+ # @example
494
508
  # UsersIndex.decay(
495
509
  # :gauss,
496
510
  # :field,
@@ -523,17 +537,19 @@ module Chewy
523
537
  chain { criteria.update_scores scoring }
524
538
  end
525
539
 
526
- # Sets <tt>preference</tt> for request.
527
- # For instance, one can use <tt>preference=_primary</tt> to execute only on the primary shards.
540
+ # Sets `preference` for request.
541
+ # For instance, one can use `preference=_primary` to execute only on the primary shards.
528
542
  #
543
+ # @example
529
544
  # scope = UsersIndex.preference(:_primary)
530
545
  #
531
546
  def preference(value)
532
547
  chain { criteria.update_search_options preference: value }
533
548
  end
534
549
 
535
- # Sets elasticsearch <tt>aggregations</tt> search request param
550
+ # Sets elasticsearch `aggregations` search request param
536
551
  #
552
+ # @example
537
553
  # UsersIndex.filter{ name == 'Johny' }.aggregations(category_id: {terms: {field: 'category_ids'}})
538
554
  # # => {body: {
539
555
  # query: {...},
@@ -592,8 +608,9 @@ module Chewy
592
608
  @_fully_qualified_named_aggs[idx][type][agg_name]
593
609
  end
594
610
 
595
- # Sets elasticsearch <tt>suggest</tt> search request param
611
+ # Sets elasticsearch `suggest` search request param
596
612
  #
613
+ # @example
597
614
  # UsersIndex.suggest(name: {text: 'Joh', term: {field: 'name'}})
598
615
  # # => {body: {
599
616
  # query: {...},
@@ -617,6 +634,7 @@ module Chewy
617
634
  # without touching the elasticsearch server.
618
635
  # All the chained calls of methods don't affect the result
619
636
  #
637
+ # @example
620
638
  # UsersIndex.none.to_a
621
639
  # # => []
622
640
  # UsersIndex.query(text: {name: 'Johny'}).none.to_a
@@ -630,6 +648,7 @@ module Chewy
630
648
 
631
649
  # Setups strategy for top-level filtered query
632
650
  #
651
+ # @example
633
652
  # UsersIndex.filter { name == 'Johny'}.strategy(:leap_frog)
634
653
  # # => {body: {
635
654
  # query: { filtered: {
@@ -645,11 +664,12 @@ module Chewy
645
664
  # Adds one or more query to the search request
646
665
  # Internally queries are stored as an array
647
666
  # While the full query compilation this array compiles
648
- # according to <tt>:query_mode</tt> option value
667
+ # according to `:query_mode` option value
649
668
  #
650
- # By default it joines inside <tt>must</tt> query
651
- # See <tt>#query_mode</tt> chainable method for more info.
669
+ # By default it joines inside `must` query
670
+ # See `#query_mode` chainable method for more info.
652
671
  #
672
+ # @example
653
673
  # UsersIndex.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}})
654
674
  # UsersIndex::User.query(text: {name: 'Johny'}).query(range: {age: {lte: 42}})
655
675
  # # => {body: {
@@ -659,6 +679,7 @@ module Chewy
659
679
  # If only one query was specified, it will become a result
660
680
  # query as is, without joining.
661
681
  #
682
+ # @example
662
683
  # UsersIndex.query(text: {name: 'Johny'})
663
684
  # # => {body: {
664
685
  # query: {text: {name: 'Johny'}}
@@ -671,14 +692,15 @@ module Chewy
671
692
  # Adds one or more filter to the search request
672
693
  # Internally filters are stored as an array
673
694
  # While the full query compilation this array compiles
674
- # according to <tt>:filter_mode</tt> option value
695
+ # according to `:filter_mode` option value
675
696
  #
676
- # By default it joins inside <tt>and</tt> filter
677
- # See <tt>#filter_mode</tt> chainable method for more info.
697
+ # By default it joins inside `and` filter
698
+ # See `#filter_mode` chainable method for more info.
678
699
  #
679
700
  # Also this method supports block DSL.
680
- # See <tt>Chewy::Query::Filters</tt> for more info.
701
+ # See `Chewy::Query::Filters` for more info.
681
702
  #
703
+ # @example
682
704
  # UsersIndex.filter(term: {name: 'Johny'}).filter(range: {age: {lte: 42}})
683
705
  # UsersIndex::User.filter(term: {name: 'Johny'}).filter(range: {age: {lte: 42}})
684
706
  # UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }
@@ -690,6 +712,7 @@ module Chewy
690
712
  # If only one filter was specified, it will become a result
691
713
  # filter as is, without joining.
692
714
  #
715
+ # @example
693
716
  # UsersIndex.filter(term: {name: 'Johny'})
694
717
  # # => {body: {query: {filtered: {
695
718
  # query: {...},
@@ -704,14 +727,15 @@ module Chewy
704
727
  # Adds one or more post_filter to the search request
705
728
  # Internally post_filters are stored as an array
706
729
  # While the full query compilation this array compiles
707
- # according to <tt>:post_filter_mode</tt> option value
730
+ # according to `:post_filter_mode` option value
708
731
  #
709
- # By default it joins inside <tt>and</tt> filter
710
- # See <tt>#post_filter_mode</tt> chainable method for more info.
732
+ # By default it joins inside `and` filter
733
+ # See `#post_filter_mode` chainable method for more info.
711
734
  #
712
735
  # Also this method supports block DSL.
713
- # See <tt>Chewy::Query::Filters</tt> for more info.
736
+ # See `Chewy::Query::Filters` for more info.
714
737
  #
738
+ # @example
715
739
  # UsersIndex.post_filter(term: {name: 'Johny'}).post_filter(range: {age: {lte: 42}})
716
740
  # UsersIndex::User.post_filter(term: {name: 'Johny'}).post_filter(range: {age: {lte: 42}})
717
741
  # UsersIndex.post_filter{ name == 'Johny' }.post_filter{ age <= 42 }
@@ -722,6 +746,7 @@ module Chewy
722
746
  # If only one post_filter was specified, it will become a result
723
747
  # post_filter as is, without joining.
724
748
  #
749
+ # @example
725
750
  # UsersIndex.post_filter(term: {name: 'Johny'})
726
751
  # # => {body: {
727
752
  # post_filter: {term: {name: 'Johny'}}
@@ -736,11 +761,10 @@ module Chewy
736
761
  # Not used if no score functions are specified
737
762
  # Possible values:
738
763
  #
739
- # * <tt>:multiply</tt>
764
+ # * `:multiply`
740
765
  # Default value. Query score and function result are multiplied.
741
766
  #
742
- # Ex:
743
- #
767
+ # @example
744
768
  # UsersIndex.boost_mode('multiply').script_score('doc['boost'].value')
745
769
  # # => {body: {query: function_score: {
746
770
  # query: {...},
@@ -748,23 +772,23 @@ module Chewy
748
772
  # functions: [ ... ]
749
773
  # }}}
750
774
  #
751
- # * <tt>:replace</tt>
775
+ # * `:replace`
752
776
  # Only function result is used, query score is ignored.
753
777
  #
754
- # * <tt>:sum</tt>
778
+ # * `:sum`
755
779
  # Query score and function score are added.
756
780
  #
757
- # * <tt>:avg</tt>
781
+ # * `:avg`
758
782
  # Average of query and function score.
759
783
  #
760
- # * <tt>:max</tt>
784
+ # * `:max`
761
785
  # Max of query and function score.
762
786
  #
763
- # * <tt>:min</tt>
787
+ # * `:min`
764
788
  # Min of query and function score.
765
789
  #
766
- # Default value for <tt>:boost_mode</tt> might be changed
767
- # with <tt>Chewy.score_mode</tt> config option.
790
+ # Default value for `:boost_mode` might be changed
791
+ # with `Chewy.score_mode` config option.
768
792
  def boost_mode(value)
769
793
  chain { criteria.update_options boost_mode: value }
770
794
  end
@@ -773,11 +797,10 @@ module Chewy
773
797
  # Not used if no score functions are specified.
774
798
  # Possible values:
775
799
  #
776
- # * <tt>:multiply</tt>
800
+ # * `:multiply`
777
801
  # Default value. Scores are multiplied.
778
802
  #
779
- # Ex:
780
- #
803
+ # @example
781
804
  # UsersIndex.score_mode('multiply').script_score('doc['boost'].value')
782
805
  # # => {body: {query: function_score: {
783
806
  # query: {...},
@@ -785,24 +808,25 @@ module Chewy
785
808
  # functions: [ ... ]
786
809
  # }}}
787
810
  #
788
- # * <tt>:sum</tt>
811
+ # * `:sum`
789
812
  # Scores are summed.
790
813
  #
791
- # * <tt>:avg</tt>
814
+ # * `:avg`
792
815
  # Scores are averaged.
793
816
  #
794
- # * <tt>:first</tt>
817
+ # * `:first`
795
818
  # The first function that has a matching filter is applied.
796
819
  #
797
- # * <tt>:max</tt>
820
+ # * `:max`
798
821
  # Maximum score is used.
799
822
  #
800
- # * <tt>:min</tt>
823
+ # * `:min`
801
824
  # Minimum score is used
802
825
  #
803
- # Default value for <tt>:score_mode</tt> might be changed
804
- # with <tt>Chewy.score_mode</tt> config option.
826
+ # Default value for `:score_mode` might be changed
827
+ # with `Chewy.score_mode` config option.
805
828
  #
829
+ # @example
806
830
  # Chewy.score_mode = :first
807
831
  #
808
832
  def score_mode(value)
@@ -811,6 +835,7 @@ module Chewy
811
835
 
812
836
  # Sets search request sorting
813
837
  #
838
+ # @example
814
839
  # UsersIndex.order(:first_name, :last_name).order(age: :desc).order(price: {order: :asc, mode: :avg})
815
840
  # # => {body: {
816
841
  # query: {...},
@@ -823,6 +848,7 @@ module Chewy
823
848
 
824
849
  # Cleans up previous search sorting and sets the new one
825
850
  #
851
+ # @example
826
852
  # UsersIndex.order(:first_name, :last_name).order(age: :desc).reorder(price: {order: :asc, mode: :avg})
827
853
  # # => {body: {
828
854
  # query: {...},
@@ -835,6 +861,7 @@ module Chewy
835
861
 
836
862
  # Sets search request field list
837
863
  #
864
+ # @example
838
865
  # UsersIndex.only(:first_name, :last_name).only(:age)
839
866
  # # => {body: {
840
867
  # query: {...},
@@ -847,6 +874,7 @@ module Chewy
847
874
 
848
875
  # Cleans up previous search field list and sets the new one
849
876
  #
877
+ # @example
850
878
  # UsersIndex.only(:first_name, :last_name).only!(:age)
851
879
  # # => {body: {
852
880
  # query: {...},
@@ -858,9 +886,10 @@ module Chewy
858
886
  end
859
887
 
860
888
  # Specify types participating in the search result
861
- # Works via <tt>types</tt> filter. Always merged with another filters
862
- # with the <tt>and</tt> filter.
889
+ # Works via `types` filter. Always merged with another filters
890
+ # with the `and` filter.
863
891
  #
892
+ # @example
864
893
  # UsersIndex.types(:admin, :manager).filters{ name == 'Johny' }.filters{ age <= 42 }
865
894
  # # => {body: {query: {filtered: {
866
895
  # query: {...},
@@ -893,8 +922,9 @@ module Chewy
893
922
  chain { criteria.update_types params }
894
923
  end
895
924
 
896
- # Acts the same way as <tt>types</tt>, but cleans up previously set types
925
+ # Acts the same way as `types`, but cleans up previously set types
897
926
  #
927
+ # @example
898
928
  # UsersIndex.types(:admin).types!(:manager)
899
929
  # # => {body: {query: {filtered: {
900
930
  # query: {...},
@@ -905,9 +935,10 @@ module Chewy
905
935
  chain { criteria.update_types params, purge: true }
906
936
  end
907
937
 
908
- # Sets <tt>search_type</tt> for request.
909
- # For instance, one can use <tt>search_type=count</tt> to fetch only total count of documents or to fetch only aggregations without fetching documents.
938
+ # Sets `search_type` for request.
939
+ # For instance, one can use `search_type=count` to fetch only total count of documents or to fetch only aggregations without fetching documents.
910
940
  #
941
+ # @example
911
942
  # scope = UsersIndex.search_type(:count)
912
943
  # scope.count == 0 # no documents actually fetched
913
944
  # scope.total == 10 # but we know a total count of them
@@ -922,6 +953,7 @@ module Chewy
922
953
  # Merges two queries.
923
954
  # Merges all the values in criteria with the same rules as values added manually.
924
955
  #
956
+ # @example
925
957
  # scope1 = UsersIndex.filter{ name == 'Johny' }
926
958
  # scope2 = UsersIndex.filter{ age <= 42 }
927
959
  # scope3 = UsersIndex.filter{ name == 'Johny' }.filter{ age <= 42 }
@@ -934,6 +966,7 @@ module Chewy
934
966
 
935
967
  # Deletes all documents matching a query.
936
968
  #
969
+ # @example
937
970
  # UsersIndex.delete_all
938
971
  # UsersIndex.filter{ age <= 42 }.delete_all
939
972
  # UsersIndex::User.delete_all
@@ -966,6 +999,7 @@ module Chewy
966
999
 
967
1000
  # Find all documents matching a query.
968
1001
  #
1002
+ # @example
969
1003
  # UsersIndex.find(42)
970
1004
  # UsersIndex.filter{ age <= 42 }.find(42)
971
1005
  # UsersIndex::User.find(42)
@@ -974,6 +1008,7 @@ module Chewy
974
1008
  # In all the previous examples find will return a single object.
975
1009
  # To get a collection - pass an array of ids.
976
1010
  #
1011
+ # @example
977
1012
  # UsersIndex::User.find(42, 7, 3) # array of objects with ids in [42, 7, 3]
978
1013
  # UsersIndex::User.find([8, 13]) # array of objects with ids in [8, 13]
979
1014
  # UsersIndex::User.find([42]) # array of the object with id == 42
@@ -987,6 +1022,7 @@ module Chewy
987
1022
 
988
1023
  # Returns true if there are at least one document that matches the query
989
1024
  #
1025
+ # @example
990
1026
  # PlacesIndex.query(...).filter(...).exists?
991
1027
  #
992
1028
  def exists?
@@ -995,6 +1031,7 @@ module Chewy
995
1031
 
996
1032
  # Sets limit to be equal to total documents count
997
1033
  #
1034
+ # @example
998
1035
  # PlacesIndex.query(...).filter(...).unlimited
999
1036
  #
1000
1037
 
@@ -1005,6 +1042,7 @@ module Chewy
1005
1042
 
1006
1043
  # Returns request total time elapsed as reported by elasticsearch
1007
1044
  #
1045
+ # @example
1008
1046
  # UsersIndex.query(...).filter(...).took
1009
1047
  #
1010
1048
  def took
@@ -1019,6 +1057,7 @@ module Chewy
1019
1057
  # important to you than complete results, you can specify a timeout as 10 or
1020
1058
  # "10ms" (10 milliseconds), or "1s" (1 second). See #timeout method.
1021
1059
  #
1060
+ # @example
1022
1061
  # UsersIndex.query(...).filter(...).timed_out
1023
1062
  #
1024
1063
  def timed_out