chewy 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +24 -2
  4. data/.rubocop_todo.yml +2 -2
  5. data/.travis.yml +38 -21
  6. data/.yardopts +5 -0
  7. data/Appraisals +55 -27
  8. data/CHANGELOG.md +57 -12
  9. data/Gemfile +14 -10
  10. data/LEGACY_DSL.md +497 -0
  11. data/README.md +249 -515
  12. data/chewy.gemspec +5 -4
  13. data/gemfiles/rails.4.0.activerecord.gemfile +14 -0
  14. data/gemfiles/rails.4.1.activerecord.gemfile +14 -0
  15. data/gemfiles/rails.4.2.activerecord.gemfile +8 -10
  16. data/gemfiles/rails.4.2.mongoid.5.1.gemfile +9 -10
  17. data/gemfiles/rails.5.0.activerecord.gemfile +8 -10
  18. data/gemfiles/rails.5.0.mongoid.6.0.gemfile +15 -0
  19. data/gemfiles/rails.5.1.activerecord.gemfile +15 -0
  20. data/gemfiles/rails.5.1.mongoid.6.1.gemfile +15 -0
  21. data/gemfiles/sequel.4.45.gemfile +11 -0
  22. data/lib/chewy.rb +77 -43
  23. data/lib/chewy/config.rb +44 -7
  24. data/lib/chewy/errors.rb +2 -2
  25. data/lib/chewy/fields/base.rb +39 -32
  26. data/lib/chewy/fields/root.rb +33 -7
  27. data/lib/chewy/index.rb +237 -149
  28. data/lib/chewy/index/actions.rb +85 -28
  29. data/lib/chewy/index/aliases.rb +2 -1
  30. data/lib/chewy/index/settings.rb +9 -5
  31. data/lib/chewy/index/specification.rb +58 -0
  32. data/lib/chewy/journal.rb +40 -92
  33. data/lib/chewy/query.rb +43 -27
  34. data/lib/chewy/query/compose.rb +13 -13
  35. data/lib/chewy/query/criteria.rb +13 -13
  36. data/lib/chewy/query/filters.rb +1 -1
  37. data/lib/chewy/query/loading.rb +1 -1
  38. data/lib/chewy/query/nodes/and.rb +2 -2
  39. data/lib/chewy/query/nodes/bool.rb +1 -1
  40. data/lib/chewy/query/nodes/equal.rb +2 -2
  41. data/lib/chewy/query/nodes/exists.rb +1 -1
  42. data/lib/chewy/query/nodes/has_relation.rb +2 -2
  43. data/lib/chewy/query/nodes/match_all.rb +1 -1
  44. data/lib/chewy/query/nodes/missing.rb +1 -1
  45. data/lib/chewy/query/nodes/not.rb +2 -2
  46. data/lib/chewy/query/nodes/or.rb +2 -2
  47. data/lib/chewy/query/nodes/prefix.rb +1 -1
  48. data/lib/chewy/query/nodes/query.rb +2 -2
  49. data/lib/chewy/query/nodes/range.rb +4 -4
  50. data/lib/chewy/query/nodes/regexp.rb +4 -4
  51. data/lib/chewy/query/nodes/script.rb +3 -3
  52. data/lib/chewy/query/pagination.rb +10 -1
  53. data/lib/chewy/railtie.rb +1 -0
  54. data/lib/chewy/rake_helper.rb +265 -48
  55. data/lib/chewy/rspec/update_index.rb +30 -22
  56. data/lib/chewy/search.rb +78 -21
  57. data/lib/chewy/search/loader.rb +83 -0
  58. data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
  59. data/lib/chewy/search/pagination/will_paginate.rb +41 -0
  60. data/lib/chewy/search/parameters.rb +150 -0
  61. data/lib/chewy/search/parameters/aggs.rb +16 -0
  62. data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
  63. data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
  64. data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
  65. data/lib/chewy/search/parameters/concerns/query_storage.rb +237 -0
  66. data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
  67. data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
  68. data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
  69. data/lib/chewy/search/parameters/explain.rb +16 -0
  70. data/lib/chewy/search/parameters/filter.rb +47 -0
  71. data/lib/chewy/search/parameters/highlight.rb +16 -0
  72. data/lib/chewy/search/parameters/indices_boost.rb +52 -0
  73. data/lib/chewy/search/parameters/limit.rb +17 -0
  74. data/lib/chewy/search/parameters/load.rb +32 -0
  75. data/lib/chewy/search/parameters/min_score.rb +16 -0
  76. data/lib/chewy/search/parameters/none.rb +27 -0
  77. data/lib/chewy/search/parameters/offset.rb +17 -0
  78. data/lib/chewy/search/parameters/order.rb +64 -0
  79. data/lib/chewy/search/parameters/post_filter.rb +19 -0
  80. data/lib/chewy/search/parameters/preference.rb +16 -0
  81. data/lib/chewy/search/parameters/profile.rb +16 -0
  82. data/lib/chewy/search/parameters/query.rb +19 -0
  83. data/lib/chewy/search/parameters/request_cache.rb +27 -0
  84. data/lib/chewy/search/parameters/rescore.rb +29 -0
  85. data/lib/chewy/search/parameters/script_fields.rb +16 -0
  86. data/lib/chewy/search/parameters/search_after.rb +20 -0
  87. data/lib/chewy/search/parameters/search_type.rb +16 -0
  88. data/lib/chewy/search/parameters/source.rb +73 -0
  89. data/lib/chewy/search/parameters/storage.rb +95 -0
  90. data/lib/chewy/search/parameters/stored_fields.rb +63 -0
  91. data/lib/chewy/search/parameters/suggest.rb +16 -0
  92. data/lib/chewy/search/parameters/terminate_after.rb +16 -0
  93. data/lib/chewy/search/parameters/timeout.rb +16 -0
  94. data/lib/chewy/search/parameters/track_scores.rb +16 -0
  95. data/lib/chewy/search/parameters/types.rb +20 -0
  96. data/lib/chewy/search/parameters/version.rb +16 -0
  97. data/lib/chewy/search/query_proxy.rb +257 -0
  98. data/lib/chewy/search/request.rb +1021 -0
  99. data/lib/chewy/search/response.rb +119 -0
  100. data/lib/chewy/search/scoping.rb +50 -0
  101. data/lib/chewy/search/scrolling.rb +136 -0
  102. data/lib/chewy/stash.rb +70 -0
  103. data/lib/chewy/strategy.rb +10 -3
  104. data/lib/chewy/strategy/active_job.rb +1 -0
  105. data/lib/chewy/strategy/atomic.rb +1 -3
  106. data/lib/chewy/strategy/bypass.rb +1 -1
  107. data/lib/chewy/strategy/resque.rb +1 -0
  108. data/lib/chewy/strategy/shoryuken.rb +40 -0
  109. data/lib/chewy/strategy/sidekiq.rb +13 -3
  110. data/lib/chewy/type.rb +29 -7
  111. data/lib/chewy/type/actions.rb +26 -2
  112. data/lib/chewy/type/adapter/active_record.rb +44 -29
  113. data/lib/chewy/type/adapter/base.rb +27 -7
  114. data/lib/chewy/type/adapter/mongoid.rb +18 -7
  115. data/lib/chewy/type/adapter/object.rb +187 -26
  116. data/lib/chewy/type/adapter/orm.rb +59 -32
  117. data/lib/chewy/type/adapter/sequel.rb +32 -16
  118. data/lib/chewy/type/import.rb +145 -191
  119. data/lib/chewy/type/import/bulk_builder.rb +122 -0
  120. data/lib/chewy/type/import/bulk_request.rb +76 -0
  121. data/lib/chewy/type/import/journal_builder.rb +45 -0
  122. data/lib/chewy/type/import/routine.rb +138 -0
  123. data/lib/chewy/type/mapping.rb +11 -1
  124. data/lib/chewy/type/observe.rb +1 -1
  125. data/lib/chewy/type/syncer.rb +220 -0
  126. data/lib/chewy/type/witchcraft.rb +27 -13
  127. data/lib/chewy/type/wrapper.rb +28 -2
  128. data/lib/chewy/version.rb +1 -1
  129. data/lib/tasks/chewy.rake +84 -26
  130. data/spec/chewy/config_spec.rb +82 -1
  131. data/spec/chewy/fields/base_spec.rb +147 -112
  132. data/spec/chewy/fields/root_spec.rb +75 -18
  133. data/spec/chewy/fields/time_fields_spec.rb +2 -3
  134. data/spec/chewy/index/actions_spec.rb +180 -50
  135. data/spec/chewy/index/aliases_spec.rb +2 -2
  136. data/spec/chewy/index/settings_spec.rb +67 -38
  137. data/spec/chewy/index/specification_spec.rb +160 -0
  138. data/spec/chewy/index_spec.rb +57 -66
  139. data/spec/chewy/journal_spec.rb +149 -54
  140. data/spec/chewy/minitest/helpers_spec.rb +4 -4
  141. data/spec/chewy/minitest/search_index_receiver_spec.rb +1 -1
  142. data/spec/chewy/query/criteria_spec.rb +179 -179
  143. data/spec/chewy/query/filters_spec.rb +15 -15
  144. data/spec/chewy/query/loading_spec.rb +22 -20
  145. data/spec/chewy/query/nodes/and_spec.rb +2 -2
  146. data/spec/chewy/query/nodes/bool_spec.rb +4 -4
  147. data/spec/chewy/query/nodes/equal_spec.rb +19 -19
  148. data/spec/chewy/query/nodes/exists_spec.rb +6 -6
  149. data/spec/chewy/query/nodes/has_child_spec.rb +19 -19
  150. data/spec/chewy/query/nodes/has_parent_spec.rb +19 -19
  151. data/spec/chewy/query/nodes/missing_spec.rb +5 -5
  152. data/spec/chewy/query/nodes/not_spec.rb +3 -2
  153. data/spec/chewy/query/nodes/or_spec.rb +2 -2
  154. data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
  155. data/spec/chewy/query/nodes/query_spec.rb +2 -2
  156. data/spec/chewy/query/nodes/range_spec.rb +18 -18
  157. data/spec/chewy/query/nodes/raw_spec.rb +1 -1
  158. data/spec/chewy/query/nodes/regexp_spec.rb +14 -14
  159. data/spec/chewy/query/nodes/script_spec.rb +4 -4
  160. data/spec/chewy/query/pagination/kaminari_spec.rb +3 -55
  161. data/spec/chewy/query/pagination/will_paginate_spec.rb +5 -0
  162. data/spec/chewy/query/pagination_spec.rb +25 -21
  163. data/spec/chewy/query_spec.rb +501 -560
  164. data/spec/chewy/rake_helper_spec.rb +368 -0
  165. data/spec/chewy/repository_spec.rb +4 -4
  166. data/spec/chewy/rspec/update_index_spec.rb +89 -56
  167. data/spec/chewy/runtime_spec.rb +2 -2
  168. data/spec/chewy/search/loader_spec.rb +117 -0
  169. data/spec/chewy/search/pagination/kaminari_examples.rb +71 -0
  170. data/spec/chewy/search/pagination/kaminari_spec.rb +17 -0
  171. data/spec/chewy/search/pagination/will_paginate_examples.rb +63 -0
  172. data/spec/chewy/search/pagination/will_paginate_spec.rb +17 -0
  173. data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
  174. data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
  175. data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
  176. data/spec/chewy/search/parameters/explain_spec.rb +5 -0
  177. data/spec/chewy/search/parameters/filter_spec.rb +5 -0
  178. data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
  179. data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
  180. data/spec/chewy/search/parameters/indices_boost_spec.rb +83 -0
  181. data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
  182. data/spec/chewy/search/parameters/limit_spec.rb +5 -0
  183. data/spec/chewy/search/parameters/load_spec.rb +60 -0
  184. data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
  185. data/spec/chewy/search/parameters/none_spec.rb +5 -0
  186. data/spec/chewy/search/parameters/offset_spec.rb +5 -0
  187. data/spec/chewy/search/parameters/order_spec.rb +65 -0
  188. data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
  189. data/spec/chewy/search/parameters/preference_spec.rb +5 -0
  190. data/spec/chewy/search/parameters/profile_spec.rb +5 -0
  191. data/spec/chewy/search/parameters/query_spec.rb +5 -0
  192. data/spec/chewy/search/parameters/query_storage_examples.rb +388 -0
  193. data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
  194. data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
  195. data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
  196. data/spec/chewy/search/parameters/search_after_spec.rb +32 -0
  197. data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
  198. data/spec/chewy/search/parameters/source_spec.rb +156 -0
  199. data/spec/chewy/search/parameters/storage_spec.rb +60 -0
  200. data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
  201. data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
  202. data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
  203. data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
  204. data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
  205. data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
  206. data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
  207. data/spec/chewy/search/parameters/types_spec.rb +5 -0
  208. data/spec/chewy/search/parameters/version_spec.rb +5 -0
  209. data/spec/chewy/search/parameters_spec.rb +130 -0
  210. data/spec/chewy/search/query_proxy_spec.rb +68 -0
  211. data/spec/chewy/search/request_spec.rb +669 -0
  212. data/spec/chewy/search/response_spec.rb +192 -0
  213. data/spec/chewy/search/scrolling_spec.rb +169 -0
  214. data/spec/chewy/search_spec.rb +13 -6
  215. data/spec/chewy/stash_spec.rb +95 -0
  216. data/spec/chewy/strategy/active_job_spec.rb +6 -0
  217. data/spec/chewy/strategy/resque_spec.rb +6 -0
  218. data/spec/chewy/strategy/shoryuken_spec.rb +64 -0
  219. data/spec/chewy/strategy/sidekiq_spec.rb +8 -0
  220. data/spec/chewy/strategy_spec.rb +6 -6
  221. data/spec/chewy/type/actions_spec.rb +29 -10
  222. data/spec/chewy/type/adapter/active_record_spec.rb +203 -91
  223. data/spec/chewy/type/adapter/mongoid_spec.rb +112 -54
  224. data/spec/chewy/type/adapter/object_spec.rb +101 -28
  225. data/spec/chewy/type/adapter/sequel_spec.rb +149 -82
  226. data/spec/chewy/type/import/bulk_builder_spec.rb +279 -0
  227. data/spec/chewy/type/import/bulk_request_spec.rb +102 -0
  228. data/spec/chewy/type/import/journal_builder_spec.rb +95 -0
  229. data/spec/chewy/type/import/routine_spec.rb +110 -0
  230. data/spec/chewy/type/import_spec.rb +350 -271
  231. data/spec/chewy/type/mapping_spec.rb +54 -18
  232. data/spec/chewy/type/observe_spec.rb +5 -1
  233. data/spec/chewy/type/syncer_spec.rb +123 -0
  234. data/spec/chewy/type/witchcraft_spec.rb +45 -29
  235. data/spec/chewy/type/wrapper_spec.rb +63 -23
  236. data/spec/chewy/type_spec.rb +28 -7
  237. data/spec/chewy_spec.rb +75 -7
  238. data/spec/spec_helper.rb +5 -2
  239. data/spec/support/active_record.rb +5 -1
  240. data/spec/support/class_helpers.rb +0 -14
  241. data/spec/support/mongoid.rb +15 -3
  242. data/spec/support/sequel.rb +6 -1
  243. metadata +198 -37
  244. data/gemfiles/rails.3.2.activerecord.gemfile +0 -16
  245. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -15
  246. data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -15
  247. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -16
  248. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -16
  249. data/gemfiles/rails.4.2.mongoid.4.0.gemfile +0 -16
  250. data/gemfiles/rails.4.2.mongoid.4.0.kaminari.gemfile +0 -15
  251. data/gemfiles/rails.4.2.mongoid.4.0.will_paginate.gemfile +0 -15
  252. data/gemfiles/rails.4.2.mongoid.5.1.kaminari.gemfile +0 -15
  253. data/gemfiles/rails.4.2.mongoid.5.1.will_paginate.gemfile +0 -15
  254. data/gemfiles/rails.5.0.activerecord.kaminari.gemfile +0 -16
  255. data/gemfiles/rails.5.0.activerecord.will_paginate.gemfile +0 -16
  256. data/gemfiles/sequel.4.38.gemfile +0 -14
  257. data/lib/chewy/journal/apply.rb +0 -31
  258. data/lib/chewy/journal/clean.rb +0 -24
  259. data/lib/chewy/journal/entry.rb +0 -83
  260. data/lib/chewy/journal/query.rb +0 -87
  261. data/lib/chewy/query/pagination/will_paginate.rb +0 -27
  262. data/lib/chewy/query/scoping.rb +0 -20
  263. data/spec/chewy/journal/apply_spec.rb +0 -120
  264. data/spec/chewy/journal/entry_spec.rb +0 -237
  265. data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -59
@@ -28,7 +28,7 @@ describe :minitest_helper do
28
28
  specify 'doesn\'t fail when index updates correctly' do
29
29
  expect do
30
30
  assert_indexes DummiesIndex::Dummy do
31
- DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }]
31
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
32
32
  end
33
33
  end.to_not raise_error
34
34
  end
@@ -42,7 +42,7 @@ describe :minitest_helper do
42
42
 
43
43
  specify 'SearchIndexReceiver catches the indexes' do
44
44
  receiver = assert_indexes DummiesIndex::Dummy do
45
- DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }]
45
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
46
46
  end
47
47
 
48
48
  expect(receiver).to be_a(SearchIndexReceiver)
@@ -57,7 +57,7 @@ describe :minitest_helper do
57
57
  expect(DummiesIndex::Dummy).not_to receive(:bulk)
58
58
 
59
59
  assert_indexes DummiesIndex::Dummy do
60
- DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }]
60
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
61
61
  end
62
62
  end
63
63
 
@@ -65,7 +65,7 @@ describe :minitest_helper do
65
65
  expect(DummiesIndex::Dummy).to receive(:bulk)
66
66
 
67
67
  assert_indexes DummiesIndex::Dummy, bypass_actual_index: false do
68
- DummiesIndex::Dummy.bulk body: [{ index: { _id: 42, data: {} } }, { index: { _id: 41, data: {} } }]
68
+ DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
69
69
  end
70
70
  end
71
71
  end
@@ -5,7 +5,7 @@ describe :search_index_receiver do
5
5
  def search_request(item_count = 2, verb: :index)
6
6
  items = Array.new(item_count) do |i|
7
7
  {
8
- verb => { _id: i + 1, data: {} }
8
+ verb => {_id: i + 1, data: {}}
9
9
  }
10
10
  end
11
11
 
@@ -46,10 +46,10 @@ describe Chewy::Query::Criteria do
46
46
  describe '#update_scores' do
47
47
  specify { expect { subject.update_scores(:score) }.to change { subject.scores? }.to(true) }
48
48
  specify { expect { subject.update_scores(:score) }.to change { subject.scores }.to([:score]) }
49
- specify { expect { subject.update_scores([:score, :score2]) }.to change { subject.scores }.to([:score, :score2]) }
49
+ specify { expect { subject.update_scores(%i[score score2]) }.to change { subject.scores }.to(%i[score score2]) }
50
50
  specify do
51
- expect { subject.tap { |s| s.update_scores(:score1) }.update_scores([:score2, :score3]) }
52
- .to change { subject.scores }.to([:score1, :score2, :score3])
51
+ expect { subject.tap { |s| s.update_scores(:score1) }.update_scores(%i[score2 score3]) }
52
+ .to change { subject.scores }.to(%i[score1 score2 score3])
53
53
  end
54
54
  end
55
55
 
@@ -60,12 +60,12 @@ describe Chewy::Query::Criteria do
60
60
 
61
61
  describe '#update_script_fields' do
62
62
  specify do
63
- expect { subject.update_script_fields(distance: { script: "doc['coordinates'].distanceInMiles(lat, lon)" }) }
63
+ expect { subject.update_script_fields(distance: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }
64
64
  .to change { subject.script_fields? }.to(true)
65
65
  end
66
66
  specify do
67
- expect { subject.update_script_fields(distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" }) }
68
- .to change { subject.script_fields }.to(distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" })
67
+ expect { subject.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }
68
+ .to change { subject.script_fields }.to(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"})
69
69
  end
70
70
  end
71
71
 
@@ -83,43 +83,43 @@ describe Chewy::Query::Criteria do
83
83
  subject.update_queries(field: 'hello')
84
84
  subject.update_queries(field: 'world')
85
85
  end
86
- .to change { subject.queries }.to([{ field: 'hello' }, { field: 'world' }])
86
+ .to change { subject.queries }.to([{field: 'hello'}, {field: 'world'}])
87
87
  end
88
88
  specify do
89
- expect { subject.update_queries([{ field: 'hello' }, { field: 'world' }, nil]) }
90
- .to change { subject.queries }.to([{ field: 'hello' }, { field: 'world' }])
89
+ expect { subject.update_queries([{field: 'hello'}, {field: 'world'}, nil]) }
90
+ .to change { subject.queries }.to([{field: 'hello'}, {field: 'world'}])
91
91
  end
92
92
  end
93
93
 
94
94
  describe '#update_filters' do
95
95
  specify { expect { subject.update_filters(field: 'hello') }.to change { subject.filters? }.to(true) }
96
- specify { expect { subject.update_filters(field: 'hello') }.to change { subject.filters }.to([{ field: 'hello' }]) }
96
+ specify { expect { subject.update_filters(field: 'hello') }.to change { subject.filters }.to([{field: 'hello'}]) }
97
97
  specify do
98
98
  expect do
99
99
  subject.update_filters(field: 'hello')
100
100
  subject.update_filters(field: 'world')
101
101
  end
102
- .to change { subject.filters }.to([{ field: 'hello' }, { field: 'world' }])
102
+ .to change { subject.filters }.to([{field: 'hello'}, {field: 'world'}])
103
103
  end
104
104
  specify do
105
- expect { subject.update_filters([{ field: 'hello' }, { field: 'world' }, nil]) }
106
- .to change { subject.filters }.to([{ field: 'hello' }, { field: 'world' }])
105
+ expect { subject.update_filters([{field: 'hello'}, {field: 'world'}, nil]) }
106
+ .to change { subject.filters }.to([{field: 'hello'}, {field: 'world'}])
107
107
  end
108
108
  end
109
109
 
110
110
  describe '#update_post_filters' do
111
111
  specify { expect { subject.update_post_filters(field: 'hello') }.to change { subject.post_filters? }.to(true) }
112
- specify { expect { subject.update_post_filters(field: 'hello') }.to change { subject.post_filters }.to([{ field: 'hello' }]) }
112
+ specify { expect { subject.update_post_filters(field: 'hello') }.to change { subject.post_filters }.to([{field: 'hello'}]) }
113
113
  specify do
114
114
  expect do
115
115
  subject.update_post_filters(field: 'hello')
116
116
  subject.update_post_filters(field: 'world')
117
117
  end
118
- .to change { subject.post_filters }.to([{ field: 'hello' }, { field: 'world' }])
118
+ .to change { subject.post_filters }.to([{field: 'hello'}, {field: 'world'}])
119
119
  end
120
120
  specify do
121
- expect { subject.update_post_filters([{ field: 'hello' }, { field: 'world' }, nil]) }
122
- .to change { subject.post_filters }.to([{ field: 'hello' }, { field: 'world' }])
121
+ expect { subject.update_post_filters([{field: 'hello'}, {field: 'world'}, nil]) }
122
+ .to change { subject.post_filters }.to([{field: 'hello'}, {field: 'world'}])
123
123
  end
124
124
  end
125
125
 
@@ -134,78 +134,78 @@ describe Chewy::Query::Criteria do
134
134
  .to change { subject.sort }.to([:field])
135
135
  end
136
136
  specify do
137
- expect { subject.update_sort([:field1, :field2]) }
138
- .to change { subject.sort }.to([:field1, :field2])
137
+ expect { subject.update_sort(%i[field1 field2]) }
138
+ .to change { subject.sort }.to(%i[field1 field2])
139
139
  end
140
140
  specify do
141
- expect { subject.update_sort([{ field: :asc }]) }
142
- .to change { subject.sort }.to([{ field: :asc }])
141
+ expect { subject.update_sort([{field: :asc}]) }
142
+ .to change { subject.sort }.to([{field: :asc}])
143
143
  end
144
144
  specify do
145
- expect { subject.update_sort([:field1, field2: { order: :asc }]) }
146
- .to change { subject.sort }.to([:field1, { field2: { order: :asc } }])
145
+ expect { subject.update_sort([:field1, field2: {order: :asc}]) }
146
+ .to change { subject.sort }.to([:field1, {field2: {order: :asc}}])
147
147
  end
148
148
  specify do
149
- expect { subject.update_sort([{ field1: { order: :asc } }, :field2]) }
150
- .to change { subject.sort }.to([{ field1: { order: :asc } }, :field2])
149
+ expect { subject.update_sort([{field1: {order: :asc}}, :field2]) }
150
+ .to change { subject.sort }.to([{field1: {order: :asc}}, :field2])
151
151
  end
152
152
  specify do
153
- expect { subject.update_sort([field1: :asc, field2: { order: :asc }]) }
154
- .to change { subject.sort }.to([{ field1: :asc }, { field2: { order: :asc } }])
153
+ expect { subject.update_sort([field1: :asc, field2: {order: :asc}]) }
154
+ .to change { subject.sort }.to([{field1: :asc}, {field2: {order: :asc}}])
155
155
  end
156
156
  specify do
157
- expect { subject.update_sort([{ field1: { order: :asc } }, :field2, :field3]) }
158
- .to change { subject.sort }.to([{ field1: { order: :asc } }, :field2, :field3])
157
+ expect { subject.update_sort([{field1: {order: :asc}}, :field2, :field3]) }
158
+ .to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3])
159
159
  end
160
160
  specify do
161
- expect { subject.update_sort([{ field1: { order: :asc } }, [:field2, :field3]]) }
162
- .to change { subject.sort }.to([{ field1: { order: :asc } }, :field2, :field3])
161
+ expect { subject.update_sort([{field1: {order: :asc}}, %i[field2 field3]]) }
162
+ .to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3])
163
163
  end
164
164
  specify do
165
- expect { subject.update_sort([{ field1: { order: :asc } }, [:field2], :field3]) }
166
- .to change { subject.sort }.to([{ field1: { order: :asc } }, :field2, :field3])
165
+ expect { subject.update_sort([{field1: {order: :asc}}, [:field2], :field3]) }
166
+ .to change { subject.sort }.to([{field1: {order: :asc}}, :field2, :field3])
167
167
  end
168
168
  specify do
169
- expect { subject.update_sort([{ field1: { order: :asc }, field2: :desc }, [:field3], :field4]) }
170
- .to change { subject.sort }.to([{ field1: { order: :asc } }, { field2: :desc }, :field3, :field4])
169
+ expect { subject.update_sort([{field1: {order: :asc}, field2: :desc}, [:field3], :field4]) }
170
+ .to change { subject.sort }.to([{field1: {order: :asc}}, {field2: :desc}, :field3, :field4])
171
171
  end
172
172
  specify do
173
- expect { subject.tap { |s| s.update_sort([field1: { order: :asc }, field2: :desc]) }.update_sort([[:field3], :field4]) }
174
- .to change { subject.sort }.to([{ field1: { order: :asc } }, { field2: :desc }, :field3, :field4])
173
+ expect { subject.tap { |s| s.update_sort([field1: {order: :asc}, field2: :desc]) }.update_sort([[:field3], :field4]) }
174
+ .to change { subject.sort }.to([{field1: {order: :asc}}, {field2: :desc}, :field3, :field4])
175
175
  end
176
176
  specify do
177
- expect { subject.tap { |s| s.update_sort([field1: { order: :asc }, field2: :desc]) }.update_sort([[:field3], :field4], purge: true) }
178
- .to change { subject.sort }.to([:field3, :field4])
177
+ expect { subject.tap { |s| s.update_sort([field1: {order: :asc}, field2: :desc]) }.update_sort([[:field3], :field4], purge: true) }
178
+ .to change { subject.sort }.to(%i[field3 field4])
179
179
  end
180
180
  end
181
181
 
182
182
  describe '#update_fields' do
183
183
  specify { expect { subject.update_fields(:field) }.to change { subject.fields? }.to(true) }
184
184
  specify { expect { subject.update_fields(:field) }.to change { subject.fields }.to(['field']) }
185
- specify { expect { subject.update_fields([:field, :field]) }.to change { subject.fields }.to(['field']) }
186
- specify { expect { subject.update_fields([:field1, :field2]) }.to change { subject.fields }.to(%w(field1 field2)) }
185
+ specify { expect { subject.update_fields(%i[field field]) }.to change { subject.fields }.to(['field']) }
186
+ specify { expect { subject.update_fields(%i[field1 field2]) }.to change { subject.fields }.to(%w[field1 field2]) }
187
187
  specify do
188
- expect { subject.tap { |s| s.update_fields(:field1) }.update_fields([:field2, :field3]) }
189
- .to change { subject.fields }.to(%w(field1 field2 field3))
188
+ expect { subject.tap { |s| s.update_fields(:field1) }.update_fields(%i[field2 field3]) }
189
+ .to change { subject.fields }.to(%w[field1 field2 field3])
190
190
  end
191
191
  specify do
192
- expect { subject.tap { |s| s.update_fields(:field1) }.update_fields([:field2, :field3], purge: true) }
193
- .to change { subject.fields }.to(%w(field2 field3))
192
+ expect { subject.tap { |s| s.update_fields(:field1) }.update_fields(%i[field2 field3], purge: true) }
193
+ .to change { subject.fields }.to(%w[field2 field3])
194
194
  end
195
195
  end
196
196
 
197
197
  describe '#update_types' do
198
198
  specify { expect { subject.update_types(:type) }.to change { subject.types? }.to(true) }
199
199
  specify { expect { subject.update_types(:type) }.to change { subject.types }.to(['type']) }
200
- specify { expect { subject.update_types([:type, :type]) }.to change { subject.types }.to(['type']) }
201
- specify { expect { subject.update_types([:type1, :type2]) }.to change { subject.types }.to(%w(type1 type2)) }
200
+ specify { expect { subject.update_types(%i[type type]) }.to change { subject.types }.to(['type']) }
201
+ specify { expect { subject.update_types(%i[type1 type2]) }.to change { subject.types }.to(%w[type1 type2]) }
202
202
  specify do
203
- expect { subject.tap { |s| s.update_types(:type1) }.update_types([:type2, :type3]) }
204
- .to change { subject.types }.to(%w(type1 type2 type3))
203
+ expect { subject.tap { |s| s.update_types(:type1) }.update_types(%i[type2 type3]) }
204
+ .to change { subject.types }.to(%w[type1 type2 type3])
205
205
  end
206
206
  specify do
207
- expect { subject.tap { |s| s.update_types(:type1) }.update_types([:type2, :type3], purge: true) }
208
- .to change { subject.types }.to(%w(type2 type3))
207
+ expect { subject.tap { |s| s.update_types(:type1) }.update_types(%i[type2 type3], purge: true) }
208
+ .to change { subject.types }.to(%w[type2 type3])
209
209
  end
210
210
  end
211
211
 
@@ -231,14 +231,14 @@ describe Chewy::Query::Criteria do
231
231
  .to eq(field1: 'hello')
232
232
  end
233
233
  specify do
234
- expect(subject.tap { |c| c.update_script_fields(distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" }) }
235
- .merge(criteria.tap { |c| c.update_script_fields(distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" }) }).script_fields)
236
- .to eq(distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" }, distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" })
234
+ expect(subject.tap { |c| c.update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }
235
+ .merge(criteria.tap { |c| c.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }).script_fields)
236
+ .to eq(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}, distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"})
237
237
  end
238
238
  specify do
239
239
  expect(subject.tap { |c| c.update_scores(script: 'hello') }
240
240
  .merge(criteria.tap { |c| c.update_scores(script: 'foobar') }).scores)
241
- .to eq([{ script: 'hello' }, { script: 'foobar' }])
241
+ .to eq([{script: 'hello'}, {script: 'foobar'}])
242
242
  end
243
243
  specify do
244
244
  expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
@@ -248,29 +248,29 @@ describe Chewy::Query::Criteria do
248
248
  specify do
249
249
  expect(subject.tap { |c| c.update_queries(field1: 'hello') }
250
250
  .merge(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries)
251
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
251
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
252
252
  end
253
253
  specify do
254
254
  expect(subject.tap { |c| c.update_filters(field1: 'hello') }
255
255
  .merge(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters)
256
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
256
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
257
257
  end
258
258
  specify do
259
259
  expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
260
260
  .merge(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters)
261
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
261
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
262
262
  end
263
263
  specify do
264
264
  expect(subject.tap { |c| c.update_sort(:field1) }
265
- .merge(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq([:field1, :field2])
265
+ .merge(criteria.tap { |c| c.update_sort(:field2) }).sort).to eq(%i[field1 field2])
266
266
  end
267
267
  specify do
268
268
  expect(subject.tap { |c| c.update_fields(:field1) }
269
- .merge(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(%w(field1 field2))
269
+ .merge(criteria.tap { |c| c.update_fields(:field2) }).fields).to eq(%w[field1 field2])
270
270
  end
271
271
  specify do
272
272
  expect(subject.tap { |c| c.update_types(:type1) }
273
- .merge(criteria.tap { |c| c.update_types(:type2) }).types).to eq(%w(type1 type2))
273
+ .merge(criteria.tap { |c| c.update_types(:type2) }).types).to eq(%w[type1 type2])
274
274
  end
275
275
  end
276
276
 
@@ -296,9 +296,9 @@ describe Chewy::Query::Criteria do
296
296
  .to eq(field1: 'hello')
297
297
  end
298
298
  specify do
299
- expect(subject.tap { |c| c.update_script_fields(distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" }) }
300
- .merge(criteria.tap { |c| c.update_script_fields(distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" }) }).script_fields)
301
- .to eq(distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" }, distance_km: { script: "doc['coordinates'].distanceInKm(lat, lon)" })
299
+ expect(subject.tap { |c| c.update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}) }
300
+ .merge(criteria.tap { |c| c.update_script_fields(distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"}) }).script_fields)
301
+ .to eq(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}, distance_km: {script: "doc['coordinates'].distanceInKm(lat, lon)"})
302
302
  end
303
303
  specify do
304
304
  expect(subject.tap { |c| c.update_aggregations(field1: 'hello') }
@@ -308,32 +308,32 @@ describe Chewy::Query::Criteria do
308
308
  specify do
309
309
  expect(subject.tap { |c| c.update_queries(field1: 'hello') }
310
310
  .merge!(criteria.tap { |c| c.update_queries(field2: 'hello') }).queries)
311
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
311
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
312
312
  end
313
313
  specify do
314
314
  expect(subject.tap { |c| c.update_filters(field1: 'hello') }
315
315
  .merge!(criteria.tap { |c| c.update_filters(field2: 'hello') }).filters)
316
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
316
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
317
317
  end
318
318
  specify do
319
319
  expect(subject.tap { |c| c.update_post_filters(field1: 'hello') }
320
320
  .merge!(criteria.tap { |c| c.update_post_filters(field2: 'hello') }).post_filters)
321
- .to eq([{ field1: 'hello' }, { field2: 'hello' }])
321
+ .to eq([{field1: 'hello'}, {field2: 'hello'}])
322
322
  end
323
323
  specify do
324
324
  expect(subject.tap { |c| c.update_sort(:field1) }
325
325
  .merge!(criteria.tap { |c| c.update_sort(:field2) }).sort)
326
- .to eq([:field1, :field2])
326
+ .to eq(%i[field1 field2])
327
327
  end
328
328
  specify do
329
329
  expect(subject.tap { |c| c.update_fields(:field1) }
330
330
  .merge!(criteria.tap { |c| c.update_fields(:field2) }).fields)
331
- .to eq(%w(field1 field2))
331
+ .to eq(%w[field1 field2])
332
332
  end
333
333
  specify do
334
334
  expect(subject.tap { |c| c.update_types(:type1) }
335
335
  .merge!(criteria.tap { |c| c.update_types(:type2) }).types)
336
- .to eq(%w(type1 type2))
336
+ .to eq(%w[type1 type2])
337
337
  end
338
338
  end
339
339
 
@@ -344,30 +344,30 @@ describe Chewy::Query::Criteria do
344
344
  end
345
345
 
346
346
  specify { expect(request_body).to eq(body: {}) }
347
- specify { expect(request_body { update_request_options(size: 10) }).to eq(body: { size: 10 }) }
348
- specify { expect(request_body { update_request_options(from: 10) }).to eq(body: { from: 10 }) }
349
- specify { expect(request_body { update_request_options(explain: true) }).to eq(body: { explain: true }) }
350
- specify { expect(request_body { update_queries(:query) }).to eq(body: { query: :query }) }
347
+ specify { expect(request_body { update_request_options(size: 10) }).to eq(body: {size: 10}) }
348
+ specify { expect(request_body { update_request_options(from: 10) }).to eq(body: {from: 10}) }
349
+ specify { expect(request_body { update_request_options(explain: true) }).to eq(body: {explain: true}) }
350
+ specify { expect(request_body { update_queries(:query) }).to eq(body: {query: :query}) }
351
351
  specify do
352
352
  expect(request_body do
353
- update_scores(script_score: { script: '_score' })
354
- end).to eq(body: { query: { function_score: { functions: [{ script_score: { script: '_score' } }] } } }) end
353
+ update_scores(script_score: {script: '_score'})
354
+ end).to eq(body: {query: {function_score: {functions: [{script_score: {script: '_score'}}]}}}) end
355
355
  specify do
356
356
  expect(request_body do
357
- update_scores(script_score: { script: 'boost_me' })
357
+ update_scores(script_score: {script: 'boost_me'})
358
358
  update_queries(:query)
359
359
  update_options(boost_mode: :add)
360
360
  update_options(score_mode: :avg)
361
- end).to eq(body: { query: {
362
- function_score: {
363
- functions: [{
364
- script_score: { script: 'boost_me' }
365
- }],
366
- query: :query,
367
- boost_mode: :add,
368
- score_mode: :avg
369
- }
370
- } })
361
+ end).to eq(body: {query: {
362
+ function_score: {
363
+ functions: [{
364
+ script_score: {script: 'boost_me'}
365
+ }],
366
+ query: :query,
367
+ boost_mode: :add,
368
+ score_mode: :avg
369
+ }
370
+ }})
371
371
  end
372
372
  specify do
373
373
  expect(request_body do
@@ -375,22 +375,22 @@ describe Chewy::Query::Criteria do
375
375
  update_sort(:field)
376
376
  update_fields(:field)
377
377
  update_queries(:query)
378
- end).to eq(body: { query: :query, from: 10, sort: [:field], _source: ['field'] }) end
378
+ end).to eq(body: {query: :query, from: 10, sort: [:field], _source: ['field']}) end
379
379
 
380
380
  specify do
381
381
  expect(request_body do
382
382
  update_queries(:query)
383
383
  update_filters(:filters)
384
- end).to eq(body: { query: { filtered: { query: :query, filter: :filters } } }) end
384
+ end).to eq(body: {query: {filtered: {query: :query, filter: :filters}}}) end
385
385
  specify do
386
386
  expect(request_body do
387
387
  update_queries(:query)
388
388
  update_post_filters(:post_filter)
389
- end).to eq(body: { query: :query, post_filter: :post_filter }) end
389
+ end).to eq(body: {query: :query, post_filter: :post_filter}) end
390
390
  specify do
391
391
  expect(request_body do
392
- update_script_fields(distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" })
393
- end).to eq(body: { script_fields: { distance_m: { script: "doc['coordinates'].distanceInMiles(lat, lon)" } } }) end
392
+ update_script_fields(distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"})
393
+ end).to eq(body: {script_fields: {distance_m: {script: "doc['coordinates'].distanceInMiles(lat, lon)"}}}) end
394
394
  end
395
395
 
396
396
  describe '#_filtered_query' do
@@ -403,64 +403,64 @@ describe Chewy::Query::Criteria do
403
403
  specify { expect(_filtered_query { update_queries(:query) }).to eq(query: :query) }
404
404
  specify { expect(_filtered_query(strategy: 'query_first') { update_queries(:query) }).to eq(query: :query) }
405
405
  specify do
406
- expect(_filtered_query { update_queries([:query1, :query2]) })
407
- .to eq(query: { bool: { must: [:query1, :query2] } })
406
+ expect(_filtered_query { update_queries(%i[query1 query2]) })
407
+ .to eq(query: {bool: {must: %i[query1 query2]}})
408
408
  end
409
409
  specify do
410
410
  expect(_filtered_query do
411
411
  update_options(query_mode: :should)
412
- update_queries([:query1, :query2])
412
+ update_queries(%i[query1 query2])
413
413
  end)
414
- .to eq(query: { bool: { should: [:query1, :query2] } })
414
+ .to eq(query: {bool: {should: %i[query1 query2]}})
415
415
  end
416
416
  specify do
417
417
  expect(_filtered_query do
418
418
  update_options(query_mode: :dis_max)
419
- update_queries([:query1, :query2])
419
+ update_queries(%i[query1 query2])
420
420
  end)
421
- .to eq(query: { dis_max: { queries: [:query1, :query2] } })
421
+ .to eq(query: {dis_max: {queries: %i[query1 query2]}})
422
422
  end
423
423
 
424
424
  specify do
425
- expect(_filtered_query(strategy: 'query_first') { update_filters([:filter1, :filter2]) })
426
- .to eq(query: { filtered: { query: { match_all: {} }, filter: { and: [:filter1, :filter2] }, strategy: 'query_first' } })
425
+ expect(_filtered_query(strategy: 'query_first') { update_filters(%i[filter1 filter2]) })
426
+ .to eq(query: {filtered: {query: {match_all: {}}, filter: {and: %i[filter1 filter2]}, strategy: 'query_first'}})
427
427
  end
428
428
  specify do
429
- expect(_filtered_query { update_filters([:filter1, :filter2]) })
430
- .to eq(query: { filtered: { query: { match_all: {} }, filter: { and: [:filter1, :filter2] } } })
429
+ expect(_filtered_query { update_filters(%i[filter1 filter2]) })
430
+ .to eq(query: {filtered: {query: {match_all: {}}, filter: {and: %i[filter1 filter2]}}})
431
431
  end
432
432
 
433
433
  specify do
434
434
  expect(_filtered_query do
435
- update_filters([:filter1, :filter2])
436
- update_queries([:query1, :query2])
435
+ update_filters(%i[filter1 filter2])
436
+ update_queries(%i[query1 query2])
437
437
  end)
438
- .to eq(query: { filtered: {
439
- query: { bool: { must: [:query1, :query2] } },
440
- filter: { and: [:filter1, :filter2] }
441
- } })
438
+ .to eq(query: {filtered: {
439
+ query: {bool: {must: %i[query1 query2]}},
440
+ filter: {and: %i[filter1 filter2]}
441
+ }})
442
442
  end
443
443
  specify do
444
444
  expect(_filtered_query(strategy: 'query_first') do
445
- update_filters([:filter1, :filter2])
446
- update_queries([:query1, :query2])
445
+ update_filters(%i[filter1 filter2])
446
+ update_queries(%i[query1 query2])
447
447
  end)
448
- .to eq(query: { filtered: {
449
- query: { bool: { must: [:query1, :query2] } },
450
- filter: { and: [:filter1, :filter2] },
451
- strategy: 'query_first'
452
- } })
448
+ .to eq(query: {filtered: {
449
+ query: {bool: {must: %i[query1 query2]}},
450
+ filter: {and: %i[filter1 filter2]},
451
+ strategy: 'query_first'
452
+ }})
453
453
  end
454
454
  specify do
455
455
  expect(_filtered_query do
456
456
  update_options(query_mode: :should)
457
457
  update_options(filter_mode: :or)
458
- update_filters([:filter1, :filter2])
459
- update_queries([:query1, :query2])
460
- end).to eq(query: { filtered: {
461
- query: { bool: { should: [:query1, :query2] } },
462
- filter: { or: [:filter1, :filter2] }
463
- } })
458
+ update_filters(%i[filter1 filter2])
459
+ update_queries(%i[query1 query2])
460
+ end).to eq(query: {filtered: {
461
+ query: {bool: {should: %i[query1 query2]}},
462
+ filter: {or: %i[filter1 filter2]}
463
+ }})
464
464
  end
465
465
  end
466
466
 
@@ -472,19 +472,19 @@ describe Chewy::Query::Criteria do
472
472
  specify do
473
473
  subject.update_scores(boost_factor: 5)
474
474
  expect(subject.send(:_boost_query, query: :query))
475
- .to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query } })
475
+ .to eq(query: {function_score: {functions: [{boost_factor: 5}], query: :query}})
476
476
  end
477
477
  specify do
478
478
  subject.update_scores(boost_factor: 5)
479
479
  subject.update_options(boost_mode: :multiply)
480
480
  subject.update_options(score_mode: :add)
481
481
  expect(subject.send(:_boost_query, query: :query))
482
- .to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: :query, boost_mode: :multiply, score_mode: :add } })
482
+ .to eq(query: {function_score: {functions: [{boost_factor: 5}], query: :query, boost_mode: :multiply, score_mode: :add}})
483
483
  end
484
484
  specify do
485
485
  subject.update_scores(boost_factor: 5)
486
486
  expect(subject.send(:_boost_query, query: :query, filter: :filter))
487
- .to eq(query: { function_score: { functions: [{ boost_factor: 5 }], query: { filtered: { query: :query, filter: :filter } } } })
487
+ .to eq(query: {function_score: {functions: [{boost_factor: 5}], query: {filtered: {query: :query, filter: :filter}}}})
488
488
  end
489
489
  end
490
490
 
@@ -496,83 +496,83 @@ describe Chewy::Query::Criteria do
496
496
 
497
497
  specify { expect(_request_filter).to be_nil }
498
498
 
499
- specify { expect(_request_filter { update_types(:type) }).to eq(type: { value: 'type' }) }
499
+ specify { expect(_request_filter { update_types(:type) }).to eq(type: {value: 'type'}) }
500
500
  specify do
501
- expect(_request_filter { update_types([:type1, :type2]) })
502
- .to eq(or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }])
501
+ expect(_request_filter { update_types(%i[type1 type2]) })
502
+ .to eq(or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}])
503
503
  end
504
504
 
505
505
  specify do
506
- expect(_request_filter { update_filters([:filter1, :filter2]) })
507
- .to eq(and: [:filter1, :filter2])
506
+ expect(_request_filter { update_filters(%i[filter1 filter2]) })
507
+ .to eq(and: %i[filter1 filter2])
508
508
  end
509
509
  specify do
510
510
  expect(_request_filter do
511
511
  update_options(filter_mode: :or)
512
- update_filters([:filter1, :filter2])
512
+ update_filters(%i[filter1 filter2])
513
513
  end)
514
- .to eq(or: [:filter1, :filter2])
514
+ .to eq(or: %i[filter1 filter2])
515
515
  end
516
516
  specify do
517
517
  expect(_request_filter do
518
518
  update_options(filter_mode: :must)
519
- update_filters([:filter1, :filter2])
519
+ update_filters(%i[filter1 filter2])
520
520
  end)
521
- .to eq(bool: { must: [:filter1, :filter2] })
521
+ .to eq(bool: {must: %i[filter1 filter2]})
522
522
  end
523
523
  specify do
524
524
  expect(_request_filter do
525
525
  update_options(filter_mode: :should)
526
- update_filters([:filter1, :filter2])
526
+ update_filters(%i[filter1 filter2])
527
527
  end)
528
- .to eq(bool: { should: [:filter1, :filter2] })
528
+ .to eq(bool: {should: %i[filter1 filter2]})
529
529
  end
530
530
  specify do
531
531
  expect(_request_filter do
532
532
  update_options(filter_mode: :must_not)
533
- update_filters([:filter1, :filter2])
533
+ update_filters(%i[filter1 filter2])
534
534
  end)
535
- .to eq(bool: { must_not: [:filter1, :filter2] })
535
+ .to eq(bool: {must_not: %i[filter1 filter2]})
536
536
  end
537
537
 
538
538
  specify do
539
539
  expect(_request_filter do
540
- update_types([:type1, :type2])
541
- update_filters([:filter1, :filter2])
540
+ update_types(%i[type1 type2])
541
+ update_filters(%i[filter1 filter2])
542
542
  end)
543
- .to eq(and: [{ or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }] }, :filter1, :filter2])
543
+ .to eq(and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, :filter1, :filter2])
544
544
  end
545
545
  specify do
546
546
  expect(_request_filter do
547
547
  update_options(filter_mode: :or)
548
- update_types([:type1, :type2])
549
- update_filters([:filter1, :filter2])
548
+ update_types(%i[type1 type2])
549
+ update_filters(%i[filter1 filter2])
550
550
  end)
551
- .to eq(and: [{ or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }] }, { or: [:filter1, :filter2] }])
551
+ .to eq(and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {or: %i[filter1 filter2]}])
552
552
  end
553
553
  specify do
554
554
  expect(_request_filter do
555
555
  update_options(filter_mode: :must)
556
- update_types([:type1, :type2])
557
- update_filters([:filter1, :filter2])
556
+ update_types(%i[type1 type2])
557
+ update_filters(%i[filter1 filter2])
558
558
  end)
559
- .to eq(and: [{ or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }] }, { bool: { must: [:filter1, :filter2] } }])
559
+ .to eq(and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must: %i[filter1 filter2]}}])
560
560
  end
561
561
  specify do
562
562
  expect(_request_filter do
563
563
  update_options(filter_mode: :should)
564
- update_types([:type1, :type2])
565
- update_filters([:filter1, :filter2])
564
+ update_types(%i[type1 type2])
565
+ update_filters(%i[filter1 filter2])
566
566
  end)
567
- .to eq(and: [{ or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }] }, { bool: { should: [:filter1, :filter2] } }])
567
+ .to eq(and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {should: %i[filter1 filter2]}}])
568
568
  end
569
569
  specify do
570
570
  expect(_request_filter do
571
571
  update_options(filter_mode: :must_not)
572
- update_types([:type1, :type2])
573
- update_filters([:filter1, :filter2])
572
+ update_types(%i[type1 type2])
573
+ update_filters(%i[filter1 filter2])
574
574
  end)
575
- .to eq(and: [{ or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }] }, { bool: { must_not: [:filter1, :filter2] } }])
575
+ .to eq(and: [{or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}]}, {bool: {must_not: %i[filter1 filter2]}}])
576
576
  end
577
577
  end
578
578
 
@@ -585,37 +585,37 @@ describe Chewy::Query::Criteria do
585
585
  specify { expect(_request_post_filter).to be_nil }
586
586
 
587
587
  specify do
588
- expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
589
- .to eq(and: [:post_filter1, :post_filter2])
588
+ expect(_request_post_filter { update_post_filters(%i[post_filter1 post_filter2]) })
589
+ .to eq(and: %i[post_filter1 post_filter2])
590
590
  end
591
591
  specify do
592
592
  expect(_request_post_filter do
593
593
  update_options(post_filter_mode: :or)
594
- update_post_filters([:post_filter1, :post_filter2])
594
+ update_post_filters(%i[post_filter1 post_filter2])
595
595
  end)
596
- .to eq(or: [:post_filter1, :post_filter2])
596
+ .to eq(or: %i[post_filter1 post_filter2])
597
597
  end
598
598
  specify do
599
599
  expect(_request_post_filter do
600
600
  update_options(post_filter_mode: :must)
601
- update_post_filters([:post_filter1, :post_filter2])
601
+ update_post_filters(%i[post_filter1 post_filter2])
602
602
  end)
603
- .to eq(bool: { must: [:post_filter1, :post_filter2] })
603
+ .to eq(bool: {must: %i[post_filter1 post_filter2]})
604
604
  end
605
605
  specify do
606
606
  expect(_request_post_filter do
607
607
  update_options(post_filter_mode: :should)
608
- update_post_filters([:post_filter1, :post_filter2])
608
+ update_post_filters(%i[post_filter1 post_filter2])
609
609
  end)
610
- .to eq(bool: { should: [:post_filter1, :post_filter2] })
610
+ .to eq(bool: {should: %i[post_filter1 post_filter2]})
611
611
  end
612
612
 
613
613
  context do
614
614
  before { allow(Chewy).to receive_messages(filter_mode: :or) }
615
615
 
616
616
  specify do
617
- expect(_request_post_filter { update_post_filters([:post_filter1, :post_filter2]) })
618
- .to eq(or: [:post_filter1, :post_filter2])
617
+ expect(_request_post_filter { update_post_filters(%i[post_filter1 post_filter2]) })
618
+ .to eq(or: %i[post_filter1 post_filter2])
619
619
  end
620
620
  end
621
621
  end
@@ -627,10 +627,10 @@ describe Chewy::Query::Criteria do
627
627
  end
628
628
 
629
629
  specify { expect(_request_types).to be_nil }
630
- specify { expect(_request_types { update_types(:type1) }).to eq(type: { value: 'type1' }) }
630
+ specify { expect(_request_types { update_types(:type1) }).to eq(type: {value: 'type1'}) }
631
631
  specify do
632
- expect(_request_types { update_types([:type1, :type2]) })
633
- .to eq(or: [{ type: { value: 'type1' } }, { type: { value: 'type2' } }])
632
+ expect(_request_types { update_types(%i[type1 type2]) })
633
+ .to eq(or: [{type: {value: 'type1'}}, {type: {value: 'type2'}}])
634
634
  end
635
635
  end
636
636
 
@@ -639,31 +639,31 @@ describe Chewy::Query::Criteria do
639
639
  subject.send(:_queries_join, *args)
640
640
  end
641
641
 
642
- let(:query) { { term: { field: 'value' } } }
642
+ let(:query) { {term: {field: 'value'}} }
643
643
 
644
644
  specify { expect(_queries_join([], :dis_max)).to be_nil }
645
645
  specify { expect(_queries_join([query], :dis_max)).to eq(query) }
646
- specify { expect(_queries_join([query, query], :dis_max)).to eq(dis_max: { queries: [query, query] }) }
646
+ specify { expect(_queries_join([query, query], :dis_max)).to eq(dis_max: {queries: [query, query]}) }
647
647
 
648
648
  specify { expect(_queries_join([], 0.7)).to be_nil }
649
649
  specify { expect(_queries_join([query], 0.7)).to eq(query) }
650
- specify { expect(_queries_join([query, query], 0.7)).to eq(dis_max: { queries: [query, query], tie_breaker: 0.7 }) }
650
+ specify { expect(_queries_join([query, query], 0.7)).to eq(dis_max: {queries: [query, query], tie_breaker: 0.7}) }
651
651
 
652
652
  specify { expect(_queries_join([], :must)).to be_nil }
653
653
  specify { expect(_queries_join([query], :must)).to eq(query) }
654
- specify { expect(_queries_join([query, query], :must)).to eq(bool: { must: [query, query] }) }
654
+ specify { expect(_queries_join([query, query], :must)).to eq(bool: {must: [query, query]}) }
655
655
 
656
656
  specify { expect(_queries_join([], :should)).to be_nil }
657
657
  specify { expect(_queries_join([query], :should)).to eq(query) }
658
- specify { expect(_queries_join([query, query], :should)).to eq(bool: { should: [query, query] }) }
658
+ specify { expect(_queries_join([query, query], :should)).to eq(bool: {should: [query, query]}) }
659
659
 
660
660
  specify { expect(_queries_join([], :must_not)).to be_nil }
661
- specify { expect(_queries_join([query], :must_not)).to eq(bool: { must_not: [query] }) }
662
- specify { expect(_queries_join([query, query], :must_not)).to eq(bool: { must_not: [query, query] }) }
661
+ specify { expect(_queries_join([query], :must_not)).to eq(bool: {must_not: [query]}) }
662
+ specify { expect(_queries_join([query, query], :must_not)).to eq(bool: {must_not: [query, query]}) }
663
663
 
664
664
  specify { expect(_queries_join([], '25%')).to be_nil }
665
665
  specify { expect(_queries_join([query], '25%')).to eq(query) }
666
- specify { expect(_queries_join([query, query], '25%')).to eq(bool: { should: [query, query], minimum_should_match: '25%' }) }
666
+ specify { expect(_queries_join([query, query], '25%')).to eq(bool: {should: [query, query], minimum_should_match: '25%'}) }
667
667
  end
668
668
 
669
669
  describe '#_filters_join' do
@@ -671,7 +671,7 @@ describe Chewy::Query::Criteria do
671
671
  subject.send(:_filters_join, *args)
672
672
  end
673
673
 
674
- let(:filter) { { term: { field: 'value' } } }
674
+ let(:filter) { {term: {field: 'value'}} }
675
675
 
676
676
  specify { expect(_filters_join([], :and)).to be_nil }
677
677
  specify { expect(_filters_join([filter], :and)).to eq(filter) }
@@ -683,18 +683,18 @@ describe Chewy::Query::Criteria do
683
683
 
684
684
  specify { expect(_filters_join([], :must)).to be_nil }
685
685
  specify { expect(_filters_join([filter], :must)).to eq(filter) }
686
- specify { expect(_filters_join([filter, filter], :must)).to eq(bool: { must: [filter, filter] }) }
686
+ specify { expect(_filters_join([filter, filter], :must)).to eq(bool: {must: [filter, filter]}) }
687
687
 
688
688
  specify { expect(_filters_join([], :should)).to be_nil }
689
689
  specify { expect(_filters_join([filter], :should)).to eq(filter) }
690
- specify { expect(_filters_join([filter, filter], :should)).to eq(bool: { should: [filter, filter] }) }
690
+ specify { expect(_filters_join([filter, filter], :should)).to eq(bool: {should: [filter, filter]}) }
691
691
 
692
692
  specify { expect(_filters_join([], :must_not)).to be_nil }
693
- specify { expect(_filters_join([filter], :must_not)).to eq(bool: { must_not: [filter] }) }
694
- specify { expect(_filters_join([filter, filter], :must_not)).to eq(bool: { must_not: [filter, filter] }) }
693
+ specify { expect(_filters_join([filter], :must_not)).to eq(bool: {must_not: [filter]}) }
694
+ specify { expect(_filters_join([filter, filter], :must_not)).to eq(bool: {must_not: [filter, filter]}) }
695
695
 
696
696
  specify { expect(_filters_join([], '25%')).to be_nil }
697
697
  specify { expect(_filters_join([filter], '25%')).to eq(filter) }
698
- specify { expect(_filters_join([filter, filter], '25%')).to eq(bool: { should: [filter, filter], minimum_should_match: '25%' }) }
698
+ specify { expect(_filters_join([filter, filter], '25%')).to eq(bool: {should: [filter, filter], minimum_should_match: '25%'}) }
699
699
  end
700
700
  end