chewy 0.8.4 → 7.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (340) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  6. data/.github/workflows/ruby.yml +74 -0
  7. data/.gitignore +1 -0
  8. data/.rubocop.yml +61 -0
  9. data/.rubocop_todo.yml +132 -0
  10. data/.yardopts +5 -0
  11. data/CHANGELOG.md +554 -245
  12. data/CODE_OF_CONDUCT.md +14 -0
  13. data/CONTRIBUTING.md +63 -0
  14. data/Gemfile +14 -11
  15. data/Guardfile +8 -6
  16. data/LICENSE.txt +1 -1
  17. data/README.md +748 -623
  18. data/Rakefile +11 -1
  19. data/chewy.gemspec +15 -19
  20. data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
  21. data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
  22. data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
  23. data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
  24. data/lib/chewy/config.rb +64 -50
  25. data/lib/chewy/errors.rb +10 -16
  26. data/lib/chewy/fields/base.rb +122 -32
  27. data/lib/chewy/fields/root.rb +48 -23
  28. data/lib/chewy/index/actions.rb +140 -54
  29. data/lib/chewy/index/adapter/active_record.rb +112 -0
  30. data/lib/chewy/{type → index}/adapter/base.rb +31 -12
  31. data/lib/chewy/index/adapter/object.rb +249 -0
  32. data/lib/chewy/index/adapter/orm.rb +194 -0
  33. data/lib/chewy/index/aliases.rb +14 -4
  34. data/lib/chewy/index/crutch.rb +40 -0
  35. data/lib/chewy/index/import/bulk_builder.rb +311 -0
  36. data/lib/chewy/index/import/bulk_request.rb +77 -0
  37. data/lib/chewy/index/import/journal_builder.rb +44 -0
  38. data/lib/chewy/index/import/routine.rb +139 -0
  39. data/lib/chewy/index/import.rb +243 -0
  40. data/lib/chewy/{type → index}/mapping.rb +79 -68
  41. data/lib/chewy/index/observe/active_record_methods.rb +87 -0
  42. data/lib/chewy/index/observe/callback.rb +34 -0
  43. data/lib/chewy/index/observe.rb +17 -0
  44. data/lib/chewy/index/settings.rb +10 -5
  45. data/lib/chewy/index/specification.rb +61 -0
  46. data/lib/chewy/index/syncer.rb +221 -0
  47. data/lib/chewy/{type → index}/witchcraft.rb +100 -39
  48. data/lib/chewy/index/wrapper.rb +95 -0
  49. data/lib/chewy/index.rb +216 -140
  50. data/lib/chewy/journal.rb +66 -0
  51. data/lib/chewy/log_subscriber.rb +8 -8
  52. data/lib/chewy/minitest/helpers.rb +150 -0
  53. data/lib/chewy/minitest/search_index_receiver.rb +76 -0
  54. data/lib/chewy/minitest.rb +1 -0
  55. data/lib/chewy/multi_search.rb +62 -0
  56. data/lib/chewy/railtie.rb +12 -25
  57. data/lib/chewy/rake_helper.rb +335 -37
  58. data/lib/chewy/repository.rb +2 -2
  59. data/lib/chewy/rspec/build_query.rb +12 -0
  60. data/lib/chewy/rspec/helpers.rb +55 -0
  61. data/lib/chewy/rspec/update_index.rb +106 -90
  62. data/lib/chewy/rspec.rb +3 -1
  63. data/lib/chewy/runtime/version.rb +4 -4
  64. data/lib/chewy/runtime.rb +1 -1
  65. data/lib/chewy/search/loader.rb +61 -0
  66. data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
  67. data/lib/chewy/search/parameters/aggs.rb +16 -0
  68. data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
  69. data/lib/chewy/search/parameters/collapse.rb +16 -0
  70. data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
  71. data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
  72. data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
  73. data/lib/chewy/search/parameters/concerns/query_storage.rb +238 -0
  74. data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
  75. data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
  76. data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
  77. data/lib/chewy/search/parameters/explain.rb +16 -0
  78. data/lib/chewy/search/parameters/filter.rb +47 -0
  79. data/lib/chewy/search/parameters/highlight.rb +16 -0
  80. data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
  81. data/lib/chewy/search/parameters/indices.rb +78 -0
  82. data/lib/chewy/search/parameters/indices_boost.rb +52 -0
  83. data/lib/chewy/search/parameters/limit.rb +17 -0
  84. data/lib/chewy/search/parameters/load.rb +32 -0
  85. data/lib/chewy/search/parameters/min_score.rb +16 -0
  86. data/lib/chewy/search/parameters/none.rb +25 -0
  87. data/lib/chewy/search/parameters/offset.rb +17 -0
  88. data/lib/chewy/search/parameters/order.rb +51 -0
  89. data/lib/chewy/search/parameters/post_filter.rb +19 -0
  90. data/lib/chewy/search/parameters/preference.rb +16 -0
  91. data/lib/chewy/search/parameters/profile.rb +16 -0
  92. data/lib/chewy/search/parameters/query.rb +19 -0
  93. data/lib/chewy/search/parameters/request_cache.rb +27 -0
  94. data/lib/chewy/search/parameters/rescore.rb +29 -0
  95. data/lib/chewy/search/parameters/script_fields.rb +16 -0
  96. data/lib/chewy/search/parameters/search_after.rb +20 -0
  97. data/lib/chewy/search/parameters/search_type.rb +16 -0
  98. data/lib/chewy/search/parameters/source.rb +77 -0
  99. data/lib/chewy/search/parameters/storage.rb +95 -0
  100. data/lib/chewy/search/parameters/stored_fields.rb +63 -0
  101. data/lib/chewy/search/parameters/suggest.rb +16 -0
  102. data/lib/chewy/search/parameters/terminate_after.rb +16 -0
  103. data/lib/chewy/search/parameters/timeout.rb +16 -0
  104. data/lib/chewy/search/parameters/track_scores.rb +16 -0
  105. data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
  106. data/lib/chewy/search/parameters/version.rb +16 -0
  107. data/lib/chewy/search/parameters.rb +170 -0
  108. data/lib/chewy/search/query_proxy.rb +264 -0
  109. data/lib/chewy/search/request.rb +1071 -0
  110. data/lib/chewy/search/response.rb +119 -0
  111. data/lib/chewy/search/scoping.rb +49 -0
  112. data/lib/chewy/search/scrolling.rb +137 -0
  113. data/lib/chewy/search.rb +68 -28
  114. data/lib/chewy/stash.rb +68 -0
  115. data/lib/chewy/strategy/active_job.rb +3 -2
  116. data/lib/chewy/strategy/atomic.rb +2 -4
  117. data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
  118. data/lib/chewy/strategy/base.rb +13 -3
  119. data/lib/chewy/strategy/bypass.rb +1 -2
  120. data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
  121. data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
  122. data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
  123. data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
  124. data/lib/chewy/strategy/sidekiq.rb +15 -2
  125. data/lib/chewy/strategy/urgent.rb +1 -1
  126. data/lib/chewy/strategy.rb +16 -20
  127. data/lib/chewy/version.rb +1 -1
  128. data/lib/chewy.rb +81 -82
  129. data/lib/generators/chewy/install_generator.rb +3 -3
  130. data/lib/tasks/chewy.rake +99 -32
  131. data/migration_guide.md +56 -0
  132. data/spec/chewy/config_spec.rb +87 -15
  133. data/spec/chewy/fields/base_spec.rb +542 -233
  134. data/spec/chewy/fields/root_spec.rb +115 -17
  135. data/spec/chewy/fields/time_fields_spec.rb +13 -12
  136. data/spec/chewy/index/actions_spec.rb +595 -77
  137. data/spec/chewy/index/adapter/active_record_spec.rb +601 -0
  138. data/spec/chewy/index/adapter/object_spec.rb +243 -0
  139. data/spec/chewy/index/aliases_spec.rb +5 -5
  140. data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
  141. data/spec/chewy/index/import/bulk_request_spec.rb +95 -0
  142. data/spec/chewy/index/import/journal_builder_spec.rb +87 -0
  143. data/spec/chewy/index/import/routine_spec.rb +110 -0
  144. data/spec/chewy/index/import_spec.rb +615 -0
  145. data/spec/chewy/index/mapping_spec.rb +135 -0
  146. data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
  147. data/spec/chewy/index/observe/callback_spec.rb +139 -0
  148. data/spec/chewy/index/observe_spec.rb +143 -0
  149. data/spec/chewy/index/settings_spec.rb +103 -50
  150. data/spec/chewy/index/specification_spec.rb +159 -0
  151. data/spec/chewy/index/syncer_spec.rb +118 -0
  152. data/spec/chewy/index/witchcraft_spec.rb +245 -0
  153. data/spec/chewy/index/wrapper_spec.rb +100 -0
  154. data/spec/chewy/index_spec.rb +149 -121
  155. data/spec/chewy/journal_spec.rb +223 -0
  156. data/spec/chewy/minitest/helpers_spec.rb +198 -0
  157. data/spec/chewy/minitest/search_index_receiver_spec.rb +118 -0
  158. data/spec/chewy/multi_search_spec.rb +84 -0
  159. data/spec/chewy/rake_helper_spec.rb +656 -0
  160. data/spec/chewy/repository_spec.rb +8 -8
  161. data/spec/chewy/rspec/build_query_spec.rb +34 -0
  162. data/spec/chewy/rspec/helpers_spec.rb +61 -0
  163. data/spec/chewy/rspec/update_index_spec.rb +220 -114
  164. data/spec/chewy/runtime_spec.rb +2 -2
  165. data/spec/chewy/search/loader_spec.rb +83 -0
  166. data/spec/chewy/search/pagination/kaminari_examples.rb +69 -0
  167. data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
  168. data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
  169. data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
  170. data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
  171. data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
  172. data/spec/chewy/search/parameters/explain_spec.rb +5 -0
  173. data/spec/chewy/search/parameters/filter_spec.rb +5 -0
  174. data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
  175. data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
  176. data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
  177. data/spec/chewy/search/parameters/indices_spec.rb +99 -0
  178. data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
  179. data/spec/chewy/search/parameters/limit_spec.rb +5 -0
  180. data/spec/chewy/search/parameters/load_spec.rb +60 -0
  181. data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
  182. data/spec/chewy/search/parameters/none_spec.rb +5 -0
  183. data/spec/chewy/search/parameters/offset_spec.rb +5 -0
  184. data/spec/chewy/search/parameters/order_spec.rb +72 -0
  185. data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
  186. data/spec/chewy/search/parameters/preference_spec.rb +5 -0
  187. data/spec/chewy/search/parameters/profile_spec.rb +5 -0
  188. data/spec/chewy/search/parameters/query_spec.rb +5 -0
  189. data/spec/chewy/search/parameters/query_storage_examples.rb +434 -0
  190. data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
  191. data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
  192. data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
  193. data/spec/chewy/search/parameters/search_after_spec.rb +35 -0
  194. data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
  195. data/spec/chewy/search/parameters/source_spec.rb +162 -0
  196. data/spec/chewy/search/parameters/storage_spec.rb +60 -0
  197. data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
  198. data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
  199. data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
  200. data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
  201. data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
  202. data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
  203. data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
  204. data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
  205. data/spec/chewy/search/parameters/version_spec.rb +5 -0
  206. data/spec/chewy/search/parameters_spec.rb +161 -0
  207. data/spec/chewy/search/query_proxy_spec.rb +119 -0
  208. data/spec/chewy/search/request_spec.rb +880 -0
  209. data/spec/chewy/search/response_spec.rb +202 -0
  210. data/spec/chewy/search/scrolling_spec.rb +171 -0
  211. data/spec/chewy/search_spec.rb +82 -55
  212. data/spec/chewy/stash_spec.rb +85 -0
  213. data/spec/chewy/strategy/active_job_spec.rb +27 -8
  214. data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
  215. data/spec/chewy/strategy/atomic_spec.rb +13 -11
  216. data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
  217. data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
  218. data/spec/chewy/strategy/sidekiq_spec.rb +19 -7
  219. data/spec/chewy/strategy_spec.rb +19 -15
  220. data/spec/chewy_spec.rb +65 -88
  221. data/spec/spec_helper.rb +11 -20
  222. data/spec/support/active_record.rb +48 -6
  223. data/spec/support/class_helpers.rb +4 -19
  224. metadata +299 -183
  225. data/.travis.yml +0 -76
  226. data/Appraisals +0 -76
  227. data/gemfiles/rails.3.2.activerecord.gemfile +0 -15
  228. data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -14
  229. data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -14
  230. data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
  231. data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
  232. data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
  233. data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
  234. data/gemfiles/rails.4.0.mongoid.4.0.0.kaminari.gemfile +0 -14
  235. data/gemfiles/rails.4.0.mongoid.4.0.0.will_paginate.gemfile +0 -14
  236. data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
  237. data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
  238. data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
  239. data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
  240. data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
  241. data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
  242. data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
  243. data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
  244. data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
  245. data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
  246. data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
  247. data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
  248. data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
  249. data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -15
  250. data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -15
  251. data/gemfiles/rails.4.2.mongoid.4.0.0.gemfile +0 -15
  252. data/gemfiles/rails.4.2.mongoid.4.0.0.kaminari.gemfile +0 -14
  253. data/gemfiles/rails.4.2.mongoid.4.0.0.will_paginate.gemfile +0 -14
  254. data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +0 -15
  255. data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +0 -14
  256. data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +0 -14
  257. data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
  258. data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
  259. data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
  260. data/gemfiles/sequel.4.31.gemfile +0 -13
  261. data/lib/chewy/backports/deep_dup.rb +0 -46
  262. data/lib/chewy/backports/duplicable.rb +0 -90
  263. data/lib/chewy/query/compose.rb +0 -69
  264. data/lib/chewy/query/criteria.rb +0 -181
  265. data/lib/chewy/query/filters.rb +0 -227
  266. data/lib/chewy/query/loading.rb +0 -111
  267. data/lib/chewy/query/nodes/and.rb +0 -25
  268. data/lib/chewy/query/nodes/base.rb +0 -17
  269. data/lib/chewy/query/nodes/bool.rb +0 -32
  270. data/lib/chewy/query/nodes/equal.rb +0 -34
  271. data/lib/chewy/query/nodes/exists.rb +0 -20
  272. data/lib/chewy/query/nodes/expr.rb +0 -28
  273. data/lib/chewy/query/nodes/field.rb +0 -106
  274. data/lib/chewy/query/nodes/has_child.rb +0 -14
  275. data/lib/chewy/query/nodes/has_parent.rb +0 -14
  276. data/lib/chewy/query/nodes/has_relation.rb +0 -61
  277. data/lib/chewy/query/nodes/match_all.rb +0 -11
  278. data/lib/chewy/query/nodes/missing.rb +0 -20
  279. data/lib/chewy/query/nodes/not.rb +0 -25
  280. data/lib/chewy/query/nodes/or.rb +0 -25
  281. data/lib/chewy/query/nodes/prefix.rb +0 -18
  282. data/lib/chewy/query/nodes/query.rb +0 -20
  283. data/lib/chewy/query/nodes/range.rb +0 -63
  284. data/lib/chewy/query/nodes/raw.rb +0 -15
  285. data/lib/chewy/query/nodes/regexp.rb +0 -31
  286. data/lib/chewy/query/nodes/script.rb +0 -20
  287. data/lib/chewy/query/pagination/will_paginate.rb +0 -27
  288. data/lib/chewy/query/pagination.rb +0 -16
  289. data/lib/chewy/query/scoping.rb +0 -20
  290. data/lib/chewy/query.rb +0 -1026
  291. data/lib/chewy/strategy/resque.rb +0 -26
  292. data/lib/chewy/type/actions.rb +0 -19
  293. data/lib/chewy/type/adapter/active_record.rb +0 -72
  294. data/lib/chewy/type/adapter/mongoid.rb +0 -58
  295. data/lib/chewy/type/adapter/object.rb +0 -89
  296. data/lib/chewy/type/adapter/orm.rb +0 -156
  297. data/lib/chewy/type/adapter/sequel.rb +0 -75
  298. data/lib/chewy/type/crutch.rb +0 -31
  299. data/lib/chewy/type/import.rb +0 -224
  300. data/lib/chewy/type/observe.rb +0 -76
  301. data/lib/chewy/type/wrapper.rb +0 -53
  302. data/lib/chewy/type.rb +0 -89
  303. data/lib/sequel/plugins/chewy_observe.rb +0 -78
  304. data/spec/chewy/query/criteria_spec.rb +0 -433
  305. data/spec/chewy/query/filters_spec.rb +0 -173
  306. data/spec/chewy/query/loading_spec.rb +0 -86
  307. data/spec/chewy/query/nodes/and_spec.rb +0 -16
  308. data/spec/chewy/query/nodes/bool_spec.rb +0 -22
  309. data/spec/chewy/query/nodes/equal_spec.rb +0 -32
  310. data/spec/chewy/query/nodes/exists_spec.rb +0 -18
  311. data/spec/chewy/query/nodes/has_child_spec.rb +0 -40
  312. data/spec/chewy/query/nodes/has_parent_spec.rb +0 -40
  313. data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
  314. data/spec/chewy/query/nodes/missing_spec.rb +0 -15
  315. data/spec/chewy/query/nodes/not_spec.rb +0 -16
  316. data/spec/chewy/query/nodes/or_spec.rb +0 -16
  317. data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
  318. data/spec/chewy/query/nodes/query_spec.rb +0 -12
  319. data/spec/chewy/query/nodes/range_spec.rb +0 -32
  320. data/spec/chewy/query/nodes/raw_spec.rb +0 -11
  321. data/spec/chewy/query/nodes/regexp_spec.rb +0 -31
  322. data/spec/chewy/query/nodes/script_spec.rb +0 -15
  323. data/spec/chewy/query/pagination/kaminari_spec.rb +0 -57
  324. data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
  325. data/spec/chewy/query/pagination_spec.rb +0 -36
  326. data/spec/chewy/query_spec.rb +0 -632
  327. data/spec/chewy/strategy/resque_spec.rb +0 -40
  328. data/spec/chewy/type/actions_spec.rb +0 -31
  329. data/spec/chewy/type/adapter/active_record_spec.rb +0 -317
  330. data/spec/chewy/type/adapter/mongoid_spec.rb +0 -253
  331. data/spec/chewy/type/adapter/object_spec.rb +0 -139
  332. data/spec/chewy/type/adapter/sequel_spec.rb +0 -320
  333. data/spec/chewy/type/import_spec.rb +0 -433
  334. data/spec/chewy/type/mapping_spec.rb +0 -106
  335. data/spec/chewy/type/observe_spec.rb +0 -127
  336. data/spec/chewy/type/witchcraft_spec.rb +0 -154
  337. data/spec/chewy/type/wrapper_spec.rb +0 -58
  338. data/spec/chewy/type_spec.rb +0 -33
  339. data/spec/support/mongoid.rb +0 -81
  340. data/spec/support/sequel.rb +0 -75
@@ -0,0 +1,55 @@
1
+ module Chewy
2
+ module Rspec
3
+ module Helpers
4
+ extend ActiveSupport::Concern
5
+ # Rspec helper to mock elasticsearch response
6
+ # To use it - add `require 'chewy/rspec'` to the `spec_helper.rb`
7
+ #
8
+ # mock_elasticsearch_response(CitiesIndex, raw_response)
9
+ # expect(CitiesIndex.query({}).hits).to eq(hits)
10
+ #
11
+ def mock_elasticsearch_response(index, raw_response)
12
+ mocked_request = Chewy::Search::Request.new(index)
13
+ allow(Chewy::Search::Request).to receive(:new).and_return(mocked_request)
14
+ allow(mocked_request).to receive(:perform).and_return(raw_response)
15
+ end
16
+
17
+ # Rspec helper to mock Elasticsearch response source
18
+ # To use it - add `require 'chewy/rspec'` to the `spec_helper.rb`
19
+ #
20
+ # mock_elasticsearch_response_sources(CitiesIndex, sources)
21
+ # expect(CitiesIndex.query({}).hits).to eq(hits)
22
+ #
23
+ def mock_elasticsearch_response_sources(index, hits)
24
+ raw_response = {
25
+ 'took' => 4,
26
+ 'timed_out' => false,
27
+ '_shards' => {
28
+ 'total' => 1,
29
+ 'successful' => 1,
30
+ 'skipped' => 0,
31
+ 'failed' => 0
32
+ },
33
+ 'hits' => {
34
+ 'total' => {
35
+ 'value' => hits.count,
36
+ 'relation' => 'eq'
37
+ },
38
+ 'max_score' => 1.0,
39
+ 'hits' => hits.each_with_index.map do |hit, i|
40
+ {
41
+ '_index' => index.index_name,
42
+ '_type' => '_doc',
43
+ '_id' => (i + 1).to_s,
44
+ '_score' => 3.14,
45
+ '_source' => hit
46
+ }
47
+ end
48
+ }
49
+ }
50
+
51
+ mock_elasticsearch_response(index, raw_response)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,58 +1,57 @@
1
- require 'i18n/core_ext/hash'
1
+ require 'active_support/core_ext/hash/keys'
2
2
 
3
3
  # Rspec matcher `update_index`
4
4
  # To use it - add `require 'chewy/rspec'` to the `spec_helper.rb`
5
- # Simple usage - just pass type as argument.
5
+ # Simple usage - just pass index as argument.
6
6
  #
7
- # specify { expect { user.save! }.to update_index(UsersIndex::User) }
8
- # specify { expect { user.save! }.to update_index('users#user') }
9
- # specify { expect { user.save! }.not_to update_index('users#user') }
7
+ # specify { expect { user.save! }.to update_index(UsersIndex) }
8
+ # specify { expect { user.save! }.to update_index('users') }
9
+ # specify { expect { user.save! }.not_to update_index('users') }
10
10
  #
11
11
  # This example will pass as well because user1 was reindexed
12
12
  # and nothing was said about user2:
13
13
  #
14
14
  # specify { expect { [user1, user2].map(&:save!) }
15
- # .to update_index(UsersIndex.user).and_reindex(user1) }
15
+ # .to update_index(UsersIndex).and_reindex(user1) }
16
16
  #
17
17
  # If you need to specify reindexed records strictly - use `only` chain.
18
18
  # Combined matcher chain methods:
19
19
  #
20
20
  # specify { expect { user1.destroy!; user2.save! } }
21
- # .to update_index(UsersIndex::User).and_reindex(user2).and_delete(user1) }
21
+ # .to update_index(UsersIndex).and_reindex(user2).and_delete(user1) }
22
22
  #
23
- RSpec::Matchers.define :update_index do |type_name, options = {}|
24
-
23
+ RSpec::Matchers.define :update_index do |index_name, options = {}| # rubocop:disable Metrics/BlockLength
25
24
  if !respond_to?(:failure_message) && respond_to?(:failure_message_for_should)
26
- alias :failure_message :failure_message_for_should
27
- alias :failure_message_when_negated :failure_message_for_should_not
25
+ alias_method :failure_message, :failure_message_for_should
26
+ alias_method :failure_message_when_negated, :failure_message_for_should_not
28
27
  end
29
28
 
30
29
  # Specify indexed records by passing record itself or id.
31
30
  #
32
- # specify { expect { user.save! }.to update_index(UsersIndex::User).and_reindex(user)
33
- # specify { expect { user.save! }.to update_index(UsersIndex::User).and_reindex(42)
31
+ # specify { expect { user.save! }.to update_index(UsersIndex).and_reindex(user)
32
+ # specify { expect { user.save! }.to update_index(UsersIndex).and_reindex(42)
34
33
  # specify { expect { [user1, user2].map(&:save!) }
35
- # .to update_index(UsersIndex::User).and_reindex(user1, user2) }
34
+ # .to update_index(UsersIndex).and_reindex(user1, user2) }
36
35
  # specify { expect { [user1, user2].map(&:save!) }
37
- # .to update_index(UsersIndex::User).and_reindex(user1).and_reindex(user2) }
36
+ # .to update_index(UsersIndex).and_reindex(user1).and_reindex(user2) }
38
37
  #
39
38
  # Specify indexing count for every particular record. Useful in case
40
39
  # urgent index updates.
41
40
  #
42
41
  # specify { expect { 2.times { user.save! } }
43
- # .to update_index(UsersIndex::User).and_reindex(user, times: 2) }
42
+ # .to update_index(UsersIndex).and_reindex(user, times: 2) }
44
43
  #
45
44
  # Specify reindexed attributes. Note that arrays are
46
45
  # compared position-independently.
47
46
  #
48
47
  # specify { expect { user.update_attributes!(name: 'Duke') }
49
- # .to update_index(UsersIndex.user).and_reindex(user, with: {name: 'Duke'}) }
48
+ # .to update_index(UsersIndex).and_reindex(user, with: {name: 'Duke'}) }
50
49
  #
51
50
  # You can combine all the options and chain `and_reindex` method to
52
51
  # specify options for every indexed record:
53
52
  #
54
53
  # specify { expect { 2.times { [user1, user2].map { |u| u.update_attributes!(name: "Duke#{u.id}") } } }
55
- # .to update_index(UsersIndex.user)
54
+ # .to update_index(UsersIndex)
56
55
  # .and_reindex(user1, with: {name: 'Duke42'}) }
57
56
  # .and_reindex(user2, times: 1, with: {name: 'Duke43'}) }
58
57
  #
@@ -63,8 +62,8 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
63
62
 
64
63
  # Specify deleted records with record itself or id passed.
65
64
  #
66
- # specify { expect { user.destroy! }.to update_index(UsersIndex::User).and_delete(user) }
67
- # specify { expect { user.destroy! }.to update_index(UsersIndex::User).and_delete(user.id) }
65
+ # specify { expect { user.destroy! }.to update_index(UsersIndex).and_delete(user) }
66
+ # specify { expect { user.destroy! }.to update_index(UsersIndex).and_delete(user.id) }
68
67
  #
69
68
  chain(:and_delete) do |*args|
70
69
  @delete ||= {}
@@ -74,84 +73,89 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
74
73
  # Used for specifying than no other records would be indexed or deleted:
75
74
  #
76
75
  # specify { expect { [user1, user2].map(&:save!) }
77
- # .to update_index(UsersIndex.user).and_reindex(user1, user2).only }
76
+ # .to update_index(UsersIndex).and_reindex(user1, user2).only }
78
77
  # specify { expect { [user1, user2].map(&:destroy!) }
79
- # .to update_index(UsersIndex.user).and_delete(user1, user2).only }
78
+ # .to update_index(UsersIndex).and_delete(user1, user2).only }
80
79
  #
81
80
  # This example will fail:
82
81
  #
83
82
  # specify { expect { [user1, user2].map(&:save!) }
84
- # .to update_index(UsersIndex.user).and_reindex(user1).only }
83
+ # .to update_index(UsersIndex).and_reindex(user1).only }
85
84
  #
86
- chain(:only) do |*args|
85
+ chain(:only) do |*_args|
86
+ raise 'Use `only` in conjunction with `and_reindex` or `and_delete`' if @reindex.blank? && @delete.blank?
87
+
87
88
  @only = true
88
89
  end
89
90
 
91
+ # Expect import to be called with refresh=false parameter
92
+ chain(:no_refresh) do
93
+ @no_refresh = true
94
+ end
95
+
90
96
  def supports_block_expectations?
91
97
  true
92
98
  end
93
99
 
94
- match do |block|
100
+ match do |block| # rubocop:disable Metrics/BlockLength
95
101
  @reindex ||= {}
96
102
  @delete ||= {}
97
103
  @missed_reindex = []
98
104
  @missed_delete = []
99
- @updated = []
100
-
101
- type = Chewy.derive_type(type_name)
102
105
 
103
- instance_eval <<-RUBY, __FILE__, __LINE__ + 1
104
- #{agnostic_stub} do |bulk_options|
105
- @updated += bulk_options[:body].map do |updated_document|
106
- updated_document.deep_symbolize_keys
107
- end
108
- {}
109
- end
110
- RUBY
106
+ index = Chewy.derive_name(index_name)
107
+ if defined?(Mocha) && RSpec.configuration.mock_framework.to_s == 'RSpec::Core::MockingAdapters::Mocha'
108
+ params_matcher = @no_refresh ? has_entry(refresh: false) : any_parameters
109
+ Chewy::Index::Import::BulkRequest.stubs(:new).with(index, params_matcher).returns(mock_bulk_request)
110
+ else
111
+ mocked_already = ::RSpec::Mocks.space.proxy_for(Chewy::Index::Import::BulkRequest).method_double_if_exists_for_message(:new)
112
+ allow(Chewy::Index::Import::BulkRequest).to receive(:new).and_call_original unless mocked_already
113
+ params_matcher = @no_refresh ? hash_including(refresh: false) : any_args
114
+ allow(Chewy::Index::Import::BulkRequest).to receive(:new).with(index, params_matcher).and_return(mock_bulk_request)
115
+ end
111
116
 
112
- ActiveSupport::Deprecation.warn('`atomic: false` option is removed and not effective anymore, use `strategy: :atomic` option instead') if options.key?(:atomic)
113
117
  Chewy.strategy(options[:strategy] || :atomic) { block.call }
114
118
 
115
- @updated.each do |updated_document|
116
- if body = updated_document[:index]
117
- if document = @reindex[body[:_id].to_s]
119
+ mock_bulk_request.updates.each do |updated_document|
120
+ if (body = updated_document[:index])
121
+ if (document = @reindex[body[:_id].to_s])
118
122
  document[:real_count] += 1
119
123
  document[:real_attributes].merge!(body[:data])
120
- else
121
- @missed_reindex.push(body[:_id].to_s) if @only
124
+ elsif @only
125
+ @missed_reindex.push(body[:_id].to_s)
122
126
  end
123
- elsif body = updated_document[:delete]
124
- if document = @delete[body[:_id].to_s]
127
+ elsif (body = updated_document[:delete])
128
+ if (document = @delete[body[:_id].to_s])
125
129
  document[:real_count] += 1
126
- else
127
- @missed_delete.push(body[:_id].to_s) if @only
130
+ elsif @only
131
+ @missed_delete.push(body[:_id].to_s)
128
132
  end
129
133
  end
130
134
  end
131
135
 
132
- @reindex.each do |_, document|
133
- document[:match_count] = (!document[:expected_count] && document[:real_count] > 0) ||
136
+ @reindex.each_value do |document|
137
+ document[:match_count] = (!document[:expected_count] && (document[:real_count]).positive?) ||
134
138
  (document[:expected_count] && document[:expected_count] == document[:real_count])
135
139
  document[:match_attributes] = document[:expected_attributes].blank? ||
136
140
  compare_attributes(document[:expected_attributes], document[:real_attributes])
137
141
  end
138
- @delete.each do |_, document|
139
- document[:match_count] = (!document[:expected_count] && document[:real_count] > 0) ||
142
+ @delete.each_value do |document|
143
+ document[:match_count] = (!document[:expected_count] && (document[:real_count]).positive?) ||
140
144
  (document[:expected_count] && document[:expected_count] == document[:real_count])
141
145
  end
142
146
 
143
- @updated.present? && @missed_reindex.none? && @missed_delete.none? &&
144
- @reindex.all? { |_, document| document[:match_count] && document[:match_attributes] } &&
145
- @delete.all? { |_, document| document[:match_count] }
147
+ mock_bulk_request.updates.present? && @missed_reindex.none? && @missed_delete.none? &&
148
+ @reindex.all? { |_, document| document[:match_count] && document[:match_attributes] } &&
149
+ @delete.all? { |_, document| document[:match_count] }
146
150
  end
147
151
 
148
- failure_message do
152
+ failure_message do # rubocop:disable Metrics/BlockLength
149
153
  output = ''
150
154
 
151
- if @updated.none?
152
- output << "Expected index `#{type_name}` to be updated, but it was not\n"
155
+ if mock_bulk_request.updates.none?
156
+ output << "Expected index `#{index_name}` to be updated#{' with no refresh' if @no_refresh}, but it was not\n"
153
157
  elsif @missed_reindex.present? || @missed_delete.present?
154
- message = "Expected index `#{type_name}` "
158
+ message = "Expected index `#{index_name}` "
155
159
  message << [
156
160
  ("to update documents #{@reindex.keys}" if @reindex.present?),
157
161
  ("to delete documents #{@delete.keys}" if @delete.present?)
@@ -166,28 +170,32 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
166
170
  output << message
167
171
  end
168
172
 
169
- output << @reindex.each.with_object('') do |(id, document), output|
173
+ output << @reindex.each.with_object('') do |(id, document), result|
170
174
  unless document[:match_count] && document[:match_attributes]
171
- output << "Expected document with id `#{id}` to be reindexed"
172
- if document[:real_count] > 0
173
- output << "\n #{document[:expected_count]} times, but was reindexed #{document[:real_count]} times" if document[:expected_count] && !document[:match_count]
174
- output << "\n with #{document[:expected_attributes]}, but it was reindexed with #{document[:real_attributes]}" if document[:expected_attributes].present? && !document[:match_attributes]
175
+ result << "Expected document with id `#{id}` to be reindexed"
176
+ if (document[:real_count]).positive?
177
+ if document[:expected_count] && !document[:match_count]
178
+ result << "\n #{document[:expected_count]} times, but was reindexed #{document[:real_count]} times"
179
+ end
180
+ if document[:expected_attributes].present? && !document[:match_attributes]
181
+ result << "\n with #{document[:expected_attributes]}, but it was reindexed with #{document[:real_attributes]}"
182
+ end
175
183
  else
176
- output << ", but it was not"
184
+ result << ', but it was not'
177
185
  end
178
- output << "\n"
186
+ result << "\n"
179
187
  end
180
188
  end
181
189
 
182
- output << @delete.each.with_object('') do |(id, document), output|
190
+ output << @delete.each.with_object('') do |(id, document), result|
183
191
  unless document[:match_count]
184
- output << "Expected document with id `#{id}` to be deleted"
185
- if document[:real_count] > 0 && document[:expected_count] && !document[:match_count]
186
- output << "\n #{document[:expected_count]} times, but was deleted #{document[:real_count]} times"
192
+ result << "Expected document with id `#{id}` to be deleted"
193
+ result << if (document[:real_count]).positive? && document[:expected_count]
194
+ "\n #{document[:expected_count]} times, but was deleted #{document[:real_count]} times"
187
195
  else
188
- output << ", but it was not"
196
+ ', but it was not'
189
197
  end
190
- output << "\n"
198
+ result << "\n"
191
199
  end
192
200
  end
193
201
 
@@ -195,30 +203,24 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
195
203
  end
196
204
 
197
205
  failure_message_when_negated do
198
- if @updated.present?
199
- "Expected index `#{type_name}` not to be updated, but it was with #{
200
- @updated.map(&:values).flatten.group_by { |documents| documents[:_id] }.map do |id, documents|
201
- "\n document id `#{id}` (#{documents.count} times)"
202
- end.join
203
- }\n"
206
+ if mock_bulk_request.updates.present?
207
+ "Expected index `#{index_name}` not to be updated, but it was with #{mock_bulk_request.updates.map(&:values).flatten.group_by { |documents| documents[:_id] }.map do |id, documents|
208
+ "\n document id `#{id}` (#{documents.count} times)"
209
+ end.join}\n"
204
210
  end
205
211
  end
206
212
 
207
- def agnostic_stub
208
- if defined?(Mocha) && RSpec.configuration.mock_framework.to_s == 'RSpec::Core::MockingAdapters::Mocha'
209
- "type.stubs(:bulk).with"
210
- else
211
- "allow(type).to receive(:bulk)"
212
- end
213
+ def mock_bulk_request
214
+ @mock_bulk_request ||= MockBulkRequest.new
213
215
  end
214
216
 
215
- def extract_documents *args
217
+ def extract_documents(*args)
216
218
  options = args.extract_options!
217
219
 
218
220
  expected_count = options[:times] || options[:count]
219
221
  expected_attributes = (options[:with] || options[:attributes] || {}).deep_symbolize_keys
220
222
 
221
- Hash[args.flatten.map do |document|
223
+ args.flatten.map do |document|
222
224
  id = document.respond_to?(:id) ? document.id.to_s : document.to_s
223
225
  [id, {
224
226
  document: document,
@@ -227,10 +229,10 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
227
229
  real_count: 0,
228
230
  real_attributes: {}
229
231
  }]
230
- end]
232
+ end.to_h
231
233
  end
232
234
 
233
- def compare_attributes expected, real
235
+ def compare_attributes(expected, real)
234
236
  expected.inject(true) do |result, (key, value)|
235
237
  equal = if value.is_a?(Array) && real[key].is_a?(Array)
236
238
  array_difference(value, real[key]) && array_difference(real[key], value)
@@ -243,13 +245,27 @@ RSpec::Matchers.define :update_index do |type_name, options = {}|
243
245
  end
244
246
  end
245
247
 
246
- def array_difference first, second
248
+ def array_difference(first, second)
247
249
  difference = first.to_ary.dup
248
250
  second.to_ary.each do |element|
249
- if index = difference.index(element)
250
- difference.delete_at(index)
251
- end
251
+ index = difference.index(element)
252
+ difference.delete_at(index) if index
252
253
  end
253
254
  difference.none?
254
255
  end
256
+
257
+ # Collects request bodies coming through the perform method for
258
+ # the further analysis.
259
+ class MockBulkRequest
260
+ attr_reader :updates
261
+
262
+ def initialize
263
+ @updates = []
264
+ end
265
+
266
+ def perform(body)
267
+ @updates.concat(body.map(&:deep_symbolize_keys))
268
+ []
269
+ end
270
+ end
255
271
  end
data/lib/chewy/rspec.rb CHANGED
@@ -1 +1,3 @@
1
- require 'chewy/rspec/update_index'
1
+ require 'chewy/rspec/build_query'
2
+ require 'chewy/rspec/helpers'
3
+ require 'chewy/rspec/update_index'
@@ -4,21 +4,21 @@ module Chewy
4
4
  include Comparable
5
5
  attr_reader :major, :minor, :patch
6
6
 
7
- def initialize version
8
- @major, @minor, @patch = *(version.to_s.split('.', 3) + [0]*3).first(3).map(&:to_i)
7
+ def initialize(version)
8
+ @major, @minor, @patch = *(version.to_s.split('.', 3) + [0] * 3).first(3).map(&:to_i)
9
9
  end
10
10
 
11
11
  def to_s
12
12
  [major, minor, patch].join('.')
13
13
  end
14
14
 
15
- def <=> other
15
+ def <=>(other)
16
16
  other = self.class.new(other) unless other.is_a?(self.class)
17
17
  [
18
18
  major <=> other.major,
19
19
  minor <=> other.minor,
20
20
  patch <=> other.patch
21
- ].detect { |c| c != 0 } || 0
21
+ ].detect(&:nonzero?) || 0
22
22
  end
23
23
  end
24
24
  end
data/lib/chewy/runtime.rb CHANGED
@@ -3,7 +3,7 @@ require 'chewy/runtime/version'
3
3
  module Chewy
4
4
  module Runtime
5
5
  def self.version
6
- Thread.current[:chewy_runtime_version] ||= Version.new(Chewy.client.info['version']['number'])
6
+ Chewy.current[:chewy_runtime_version] ||= Version.new(Chewy.client.info['version']['number'])
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,61 @@
1
+ module Chewy
2
+ module Search
3
+ # This class is used for two different purposes: load ORM/ODM
4
+ # source objects.
5
+ #
6
+ # @see Chewy::Index::Import
7
+ # @see Chewy::Search::Request#load
8
+ # @see Chewy::Search::Response#objects
9
+ # @see Chewy::Search::Scrolling#scroll_objects
10
+ class Loader
11
+ # @param indexes [Array<Chewy::Index>] list of indexes to lookup
12
+ # @param options [Hash] adapter-specific load options
13
+ # @see Chewy::Index::Adapter::Base#load
14
+ def initialize(indexes: [], **options)
15
+ @indexes = indexes
16
+ @options = options
17
+ end
18
+
19
+ def derive_index(index_name)
20
+ index = (@derive_index ||= {})[index_name] ||= indexes_hash[index_name] ||
21
+ indexes_hash[indexes_hash.keys.sort_by(&:length)
22
+ .reverse.detect do |name|
23
+ index_name.match(/#{name}(_.+|\z)/)
24
+ end]
25
+ raise Chewy::UndefinedIndex, "Can not find index named `#{index}`" unless index
26
+
27
+ index
28
+ end
29
+
30
+ # For each passed hit this method loads an ORM/ORD source object
31
+ # using `hit['_id']`. The returned array is exactly in the same order
32
+ # as hits were. If source object was not found for some hit, `nil`
33
+ # will be returned at the corresponding position in array.
34
+ #
35
+ # Records/documents are loaded in an efficient manner, performing
36
+ # a single query for each index present.
37
+ #
38
+ # @param hits [Array<Hash>] ES hits array
39
+ # @return [Array<Object, nil>] the array of corresponding ORM/ODM objects
40
+ def load(hits)
41
+ hit_groups = hits.group_by { |hit| hit['_index'] }
42
+ loaded_objects = hit_groups.each_with_object({}) do |(index_name, hit_group), result|
43
+ index = derive_index(index_name)
44
+ ids = hit_group.map { |hit| hit['_id'] }
45
+ loaded = index.adapter.load(ids, **@options.merge(_index: index.base_name))
46
+ loaded ||= hit_group.map { |hit| index.build(hit) }
47
+
48
+ result.merge!(hit_group.zip(loaded).to_h)
49
+ end
50
+
51
+ hits.map { |hit| loaded_objects[hit] }
52
+ end
53
+
54
+ private
55
+
56
+ def indexes_hash
57
+ @indexes_hash ||= @indexes.index_by(&:index_name)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,6 +1,12 @@
1
1
  module Chewy
2
- class Query
2
+ module Search
3
3
  module Pagination
4
+ # This module provides `Kaminari` support for {Chewy::Search::Request}
5
+ # It is included automatically if `Kaminari` is available.
6
+ #
7
+ # @example
8
+ # PlacesIndex.all.page(3).per(10).order(:name)
9
+ # # => <PlacesIndex::Query {..., :body=>{:size=>10, :from=>20, :sort=>["name"]}}>
4
10
  module Kaminari
5
11
  extend ActiveSupport::Concern
6
12
 
@@ -17,11 +23,11 @@ module Chewy
17
23
  end
18
24
 
19
25
  def limit_value
20
- (criteria.request_options[:size].presence || default_per_page).to_i
26
+ (raw_limit_value || default_per_page).to_i
21
27
  end
22
28
 
23
29
  def offset_value
24
- criteria.request_options[:from].to_i
30
+ raw_offset_value.to_i
25
31
  end
26
32
 
27
33
  private
@@ -29,9 +35,11 @@ module Chewy
29
35
  def _kaminari_config
30
36
  ::Kaminari.config
31
37
  end
38
+
39
+ def paginated_collection(collection)
40
+ ::Kaminari.paginate_array(collection, limit: limit_value, offset: offset_value, total_count: total_count)
41
+ end
32
42
  end
33
43
  end
34
44
  end
35
45
  end
36
-
37
- Chewy::Query.send :include, Chewy::Query::Pagination::Kaminari
@@ -0,0 +1,16 @@
1
+ require 'chewy/search/parameters/storage'
2
+
3
+ module Chewy
4
+ module Search
5
+ class Parameters
6
+ # Just a standard hash storage. Nothing to see here.
7
+ #
8
+ # @see Chewy::Search::Parameters::HashStorage
9
+ # @see Chewy::Search::Request#aggregations
10
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
11
+ class Aggs < Storage
12
+ include HashStorage
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require 'chewy/search/parameters/storage'
2
+
3
+ module Chewy
4
+ module Search
5
+ class Parameters
6
+ # Stores boolean value, but has 3 states: `true`, `false` and `nil`.
7
+ #
8
+ # @see Chewy::Search::Request#allow_partial_search_results
9
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-request-body.html#_parameters_4
10
+ class AllowPartialSearchResults < Storage
11
+ # We don't want to render `nil`, but render `true` and `false` values.
12
+ #
13
+ # @see Chewy::Search::Parameters::Storage#render
14
+ # @return [{Symbol => Object}, nil]
15
+ def render
16
+ {self.class.param_name => value} unless value.nil?
17
+ end
18
+
19
+ private
20
+
21
+ def normalize(value)
22
+ !!value unless value.nil?
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require 'chewy/search/parameters/storage'
2
+
3
+ module Chewy
4
+ module Search
5
+ class Parameters
6
+ # Just a standard hash storage. Nothing to see here.
7
+ #
8
+ # @see Chewy::Search::Parameters::HashStorage
9
+ # @see Chewy::Search::Request#collapse
10
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
11
+ class Collapse < Storage
12
+ include HashStorage
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module Chewy
2
+ module Search
3
+ class Parameters
4
+ # Stores a boolean value. Any passed value is coerced to
5
+ # a boolean value.
6
+ module BoolStorage
7
+ # Performs values disjunction on update.
8
+ #
9
+ # @see Chewy::Search::Parameters::Storage#update!
10
+ # @param other_value [true, false, Object] any acceptable storage value
11
+ # @return [true, false] updated value
12
+ def update!(other_value)
13
+ replace!(value || normalize(other_value))
14
+ end
15
+
16
+ private
17
+
18
+ def normalize(value)
19
+ !!value
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Chewy
2
+ module Search
3
+ class Parameters
4
+ # Stores hashes with stringified keys.
5
+ module HashStorage
6
+ # Simply merges two value hashes on update
7
+ #
8
+ # @see Chewy::Search::Parameters::Storage#update!
9
+ # @param other_value [{String, Symbol => Object}] any acceptable storage value
10
+ # @return [{String => Object}] updated value
11
+ def update!(other_value)
12
+ value.merge!(normalize(other_value))
13
+ end
14
+
15
+ private
16
+
17
+ def normalize(value)
18
+ (value || {}).stringify_keys
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end