chewy 0.8.4 → 7.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
- data/.github/workflows/ruby.yml +74 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +132 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +554 -245
- data/CODE_OF_CONDUCT.md +14 -0
- data/CONTRIBUTING.md +63 -0
- data/Gemfile +14 -11
- data/Guardfile +8 -6
- data/LICENSE.txt +1 -1
- data/README.md +748 -623
- data/Rakefile +11 -1
- data/chewy.gemspec +15 -19
- data/gemfiles/rails.5.2.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +11 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +13 -0
- data/gemfiles/rails.7.0.activerecord.gemfile +13 -0
- data/lib/chewy/config.rb +64 -50
- data/lib/chewy/errors.rb +10 -16
- data/lib/chewy/fields/base.rb +122 -32
- data/lib/chewy/fields/root.rb +48 -23
- data/lib/chewy/index/actions.rb +140 -54
- data/lib/chewy/index/adapter/active_record.rb +112 -0
- data/lib/chewy/{type → index}/adapter/base.rb +31 -12
- data/lib/chewy/index/adapter/object.rb +249 -0
- data/lib/chewy/index/adapter/orm.rb +194 -0
- data/lib/chewy/index/aliases.rb +14 -4
- data/lib/chewy/index/crutch.rb +40 -0
- data/lib/chewy/index/import/bulk_builder.rb +311 -0
- data/lib/chewy/index/import/bulk_request.rb +77 -0
- data/lib/chewy/index/import/journal_builder.rb +44 -0
- data/lib/chewy/index/import/routine.rb +139 -0
- data/lib/chewy/index/import.rb +243 -0
- data/lib/chewy/{type → index}/mapping.rb +79 -68
- data/lib/chewy/index/observe/active_record_methods.rb +87 -0
- data/lib/chewy/index/observe/callback.rb +34 -0
- data/lib/chewy/index/observe.rb +17 -0
- data/lib/chewy/index/settings.rb +10 -5
- data/lib/chewy/index/specification.rb +61 -0
- data/lib/chewy/index/syncer.rb +221 -0
- data/lib/chewy/{type → index}/witchcraft.rb +100 -39
- data/lib/chewy/index/wrapper.rb +95 -0
- data/lib/chewy/index.rb +216 -140
- data/lib/chewy/journal.rb +66 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +150 -0
- data/lib/chewy/minitest/search_index_receiver.rb +76 -0
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/multi_search.rb +62 -0
- data/lib/chewy/railtie.rb +12 -25
- data/lib/chewy/rake_helper.rb +335 -37
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec/build_query.rb +12 -0
- data/lib/chewy/rspec/helpers.rb +55 -0
- data/lib/chewy/rspec/update_index.rb +106 -90
- data/lib/chewy/rspec.rb +3 -1
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/runtime.rb +1 -1
- data/lib/chewy/search/loader.rb +61 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/parameters/aggs.rb +16 -0
- data/lib/chewy/search/parameters/allow_partial_search_results.rb +27 -0
- data/lib/chewy/search/parameters/collapse.rb +16 -0
- data/lib/chewy/search/parameters/concerns/bool_storage.rb +24 -0
- data/lib/chewy/search/parameters/concerns/hash_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/integer_storage.rb +14 -0
- data/lib/chewy/search/parameters/concerns/query_storage.rb +238 -0
- data/lib/chewy/search/parameters/concerns/string_array_storage.rb +23 -0
- data/lib/chewy/search/parameters/concerns/string_storage.rb +14 -0
- data/lib/chewy/search/parameters/docvalue_fields.rb +12 -0
- data/lib/chewy/search/parameters/explain.rb +16 -0
- data/lib/chewy/search/parameters/filter.rb +47 -0
- data/lib/chewy/search/parameters/highlight.rb +16 -0
- data/lib/chewy/search/parameters/ignore_unavailable.rb +27 -0
- data/lib/chewy/search/parameters/indices.rb +78 -0
- data/lib/chewy/search/parameters/indices_boost.rb +52 -0
- data/lib/chewy/search/parameters/limit.rb +17 -0
- data/lib/chewy/search/parameters/load.rb +32 -0
- data/lib/chewy/search/parameters/min_score.rb +16 -0
- data/lib/chewy/search/parameters/none.rb +25 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +51 -0
- data/lib/chewy/search/parameters/post_filter.rb +19 -0
- data/lib/chewy/search/parameters/preference.rb +16 -0
- data/lib/chewy/search/parameters/profile.rb +16 -0
- data/lib/chewy/search/parameters/query.rb +19 -0
- data/lib/chewy/search/parameters/request_cache.rb +27 -0
- data/lib/chewy/search/parameters/rescore.rb +29 -0
- data/lib/chewy/search/parameters/script_fields.rb +16 -0
- data/lib/chewy/search/parameters/search_after.rb +20 -0
- data/lib/chewy/search/parameters/search_type.rb +16 -0
- data/lib/chewy/search/parameters/source.rb +77 -0
- data/lib/chewy/search/parameters/storage.rb +95 -0
- data/lib/chewy/search/parameters/stored_fields.rb +63 -0
- data/lib/chewy/search/parameters/suggest.rb +16 -0
- data/lib/chewy/search/parameters/terminate_after.rb +16 -0
- data/lib/chewy/search/parameters/timeout.rb +16 -0
- data/lib/chewy/search/parameters/track_scores.rb +16 -0
- data/lib/chewy/search/parameters/track_total_hits.rb +16 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/parameters.rb +170 -0
- data/lib/chewy/search/query_proxy.rb +264 -0
- data/lib/chewy/search/request.rb +1071 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +49 -0
- data/lib/chewy/search/scrolling.rb +137 -0
- data/lib/chewy/search.rb +68 -28
- data/lib/chewy/stash.rb +68 -0
- data/lib/chewy/strategy/active_job.rb +3 -2
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/atomic_no_refresh.rb +18 -0
- data/lib/chewy/strategy/base.rb +13 -3
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/delayed_sidekiq/scheduler.rb +148 -0
- data/lib/chewy/strategy/delayed_sidekiq/worker.rb +52 -0
- data/lib/chewy/strategy/delayed_sidekiq.rb +17 -0
- data/lib/chewy/strategy/lazy_sidekiq.rb +64 -0
- data/lib/chewy/strategy/sidekiq.rb +15 -2
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/strategy.rb +16 -20
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +81 -82
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +99 -32
- data/migration_guide.md +56 -0
- data/spec/chewy/config_spec.rb +87 -15
- data/spec/chewy/fields/base_spec.rb +542 -233
- data/spec/chewy/fields/root_spec.rb +115 -17
- data/spec/chewy/fields/time_fields_spec.rb +13 -12
- data/spec/chewy/index/actions_spec.rb +595 -77
- data/spec/chewy/index/adapter/active_record_spec.rb +601 -0
- data/spec/chewy/index/adapter/object_spec.rb +243 -0
- data/spec/chewy/index/aliases_spec.rb +5 -5
- data/spec/chewy/index/import/bulk_builder_spec.rb +494 -0
- data/spec/chewy/index/import/bulk_request_spec.rb +95 -0
- data/spec/chewy/index/import/journal_builder_spec.rb +87 -0
- data/spec/chewy/index/import/routine_spec.rb +110 -0
- data/spec/chewy/index/import_spec.rb +615 -0
- data/spec/chewy/index/mapping_spec.rb +135 -0
- data/spec/chewy/index/observe/active_record_methods_spec.rb +68 -0
- data/spec/chewy/index/observe/callback_spec.rb +139 -0
- data/spec/chewy/index/observe_spec.rb +143 -0
- data/spec/chewy/index/settings_spec.rb +103 -50
- data/spec/chewy/index/specification_spec.rb +159 -0
- data/spec/chewy/index/syncer_spec.rb +118 -0
- data/spec/chewy/index/witchcraft_spec.rb +245 -0
- data/spec/chewy/index/wrapper_spec.rb +100 -0
- data/spec/chewy/index_spec.rb +149 -121
- data/spec/chewy/journal_spec.rb +223 -0
- data/spec/chewy/minitest/helpers_spec.rb +198 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +118 -0
- data/spec/chewy/multi_search_spec.rb +84 -0
- data/spec/chewy/rake_helper_spec.rb +656 -0
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/build_query_spec.rb +34 -0
- data/spec/chewy/rspec/helpers_spec.rb +61 -0
- data/spec/chewy/rspec/update_index_spec.rb +220 -114
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +83 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +69 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
- data/spec/chewy/search/parameters/aggs_spec.rb +5 -0
- data/spec/chewy/search/parameters/bool_storage_examples.rb +53 -0
- data/spec/chewy/search/parameters/collapse_spec.rb +5 -0
- data/spec/chewy/search/parameters/docvalue_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/explain_spec.rb +5 -0
- data/spec/chewy/search/parameters/filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/hash_storage_examples.rb +59 -0
- data/spec/chewy/search/parameters/highlight_spec.rb +5 -0
- data/spec/chewy/search/parameters/ignore_unavailable_spec.rb +67 -0
- data/spec/chewy/search/parameters/indices_spec.rb +99 -0
- data/spec/chewy/search/parameters/integer_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/limit_spec.rb +5 -0
- data/spec/chewy/search/parameters/load_spec.rb +60 -0
- data/spec/chewy/search/parameters/min_score_spec.rb +32 -0
- data/spec/chewy/search/parameters/none_spec.rb +5 -0
- data/spec/chewy/search/parameters/offset_spec.rb +5 -0
- data/spec/chewy/search/parameters/order_spec.rb +72 -0
- data/spec/chewy/search/parameters/post_filter_spec.rb +5 -0
- data/spec/chewy/search/parameters/preference_spec.rb +5 -0
- data/spec/chewy/search/parameters/profile_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_spec.rb +5 -0
- data/spec/chewy/search/parameters/query_storage_examples.rb +434 -0
- data/spec/chewy/search/parameters/request_cache_spec.rb +67 -0
- data/spec/chewy/search/parameters/rescore_spec.rb +62 -0
- data/spec/chewy/search/parameters/script_fields_spec.rb +5 -0
- data/spec/chewy/search/parameters/search_after_spec.rb +35 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +162 -0
- data/spec/chewy/search/parameters/storage_spec.rb +60 -0
- data/spec/chewy/search/parameters/stored_fields_spec.rb +126 -0
- data/spec/chewy/search/parameters/string_array_storage_examples.rb +63 -0
- data/spec/chewy/search/parameters/string_storage_examples.rb +32 -0
- data/spec/chewy/search/parameters/suggest_spec.rb +5 -0
- data/spec/chewy/search/parameters/terminate_after_spec.rb +5 -0
- data/spec/chewy/search/parameters/timeout_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_scores_spec.rb +5 -0
- data/spec/chewy/search/parameters/track_total_hits_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +161 -0
- data/spec/chewy/search/query_proxy_spec.rb +119 -0
- data/spec/chewy/search/request_spec.rb +880 -0
- data/spec/chewy/search/response_spec.rb +202 -0
- data/spec/chewy/search/scrolling_spec.rb +171 -0
- data/spec/chewy/search_spec.rb +82 -55
- data/spec/chewy/stash_spec.rb +85 -0
- data/spec/chewy/strategy/active_job_spec.rb +27 -8
- data/spec/chewy/strategy/atomic_no_refresh_spec.rb +60 -0
- data/spec/chewy/strategy/atomic_spec.rb +13 -11
- data/spec/chewy/strategy/delayed_sidekiq_spec.rb +190 -0
- data/spec/chewy/strategy/lazy_sidekiq_spec.rb +214 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +19 -7
- data/spec/chewy/strategy_spec.rb +19 -15
- data/spec/chewy_spec.rb +65 -88
- data/spec/spec_helper.rb +11 -20
- data/spec/support/active_record.rb +48 -6
- data/spec/support/class_helpers.rb +4 -19
- metadata +299 -183
- data/.travis.yml +0 -76
- data/Appraisals +0 -76
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.0.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.2.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.5.0.0.beta3.activerecord.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.0.beta3.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/sequel.4.31.gemfile +0 -13
- data/lib/chewy/backports/deep_dup.rb +0 -46
- data/lib/chewy/backports/duplicable.rb +0 -90
- data/lib/chewy/query/compose.rb +0 -69
- data/lib/chewy/query/criteria.rb +0 -181
- data/lib/chewy/query/filters.rb +0 -227
- data/lib/chewy/query/loading.rb +0 -111
- data/lib/chewy/query/nodes/and.rb +0 -25
- data/lib/chewy/query/nodes/base.rb +0 -17
- data/lib/chewy/query/nodes/bool.rb +0 -32
- data/lib/chewy/query/nodes/equal.rb +0 -34
- data/lib/chewy/query/nodes/exists.rb +0 -20
- data/lib/chewy/query/nodes/expr.rb +0 -28
- data/lib/chewy/query/nodes/field.rb +0 -106
- data/lib/chewy/query/nodes/has_child.rb +0 -14
- data/lib/chewy/query/nodes/has_parent.rb +0 -14
- data/lib/chewy/query/nodes/has_relation.rb +0 -61
- data/lib/chewy/query/nodes/match_all.rb +0 -11
- data/lib/chewy/query/nodes/missing.rb +0 -20
- data/lib/chewy/query/nodes/not.rb +0 -25
- data/lib/chewy/query/nodes/or.rb +0 -25
- data/lib/chewy/query/nodes/prefix.rb +0 -18
- data/lib/chewy/query/nodes/query.rb +0 -20
- data/lib/chewy/query/nodes/range.rb +0 -63
- data/lib/chewy/query/nodes/raw.rb +0 -15
- data/lib/chewy/query/nodes/regexp.rb +0 -31
- data/lib/chewy/query/nodes/script.rb +0 -20
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/pagination.rb +0 -16
- data/lib/chewy/query/scoping.rb +0 -20
- data/lib/chewy/query.rb +0 -1026
- data/lib/chewy/strategy/resque.rb +0 -26
- data/lib/chewy/type/actions.rb +0 -19
- data/lib/chewy/type/adapter/active_record.rb +0 -72
- data/lib/chewy/type/adapter/mongoid.rb +0 -58
- data/lib/chewy/type/adapter/object.rb +0 -89
- data/lib/chewy/type/adapter/orm.rb +0 -156
- data/lib/chewy/type/adapter/sequel.rb +0 -75
- data/lib/chewy/type/crutch.rb +0 -31
- data/lib/chewy/type/import.rb +0 -224
- data/lib/chewy/type/observe.rb +0 -76
- data/lib/chewy/type/wrapper.rb +0 -53
- data/lib/chewy/type.rb +0 -89
- data/lib/sequel/plugins/chewy_observe.rb +0 -78
- data/spec/chewy/query/criteria_spec.rb +0 -433
- data/spec/chewy/query/filters_spec.rb +0 -173
- data/spec/chewy/query/loading_spec.rb +0 -86
- data/spec/chewy/query/nodes/and_spec.rb +0 -16
- data/spec/chewy/query/nodes/bool_spec.rb +0 -22
- data/spec/chewy/query/nodes/equal_spec.rb +0 -32
- data/spec/chewy/query/nodes/exists_spec.rb +0 -18
- data/spec/chewy/query/nodes/has_child_spec.rb +0 -40
- data/spec/chewy/query/nodes/has_parent_spec.rb +0 -40
- data/spec/chewy/query/nodes/match_all_spec.rb +0 -11
- data/spec/chewy/query/nodes/missing_spec.rb +0 -15
- data/spec/chewy/query/nodes/not_spec.rb +0 -16
- data/spec/chewy/query/nodes/or_spec.rb +0 -16
- data/spec/chewy/query/nodes/prefix_spec.rb +0 -16
- data/spec/chewy/query/nodes/query_spec.rb +0 -12
- data/spec/chewy/query/nodes/range_spec.rb +0 -32
- data/spec/chewy/query/nodes/raw_spec.rb +0 -11
- data/spec/chewy/query/nodes/regexp_spec.rb +0 -31
- data/spec/chewy/query/nodes/script_spec.rb +0 -15
- data/spec/chewy/query/pagination/kaminari_spec.rb +0 -57
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
- data/spec/chewy/query/pagination_spec.rb +0 -36
- data/spec/chewy/query_spec.rb +0 -632
- data/spec/chewy/strategy/resque_spec.rb +0 -40
- data/spec/chewy/type/actions_spec.rb +0 -31
- data/spec/chewy/type/adapter/active_record_spec.rb +0 -317
- data/spec/chewy/type/adapter/mongoid_spec.rb +0 -253
- data/spec/chewy/type/adapter/object_spec.rb +0 -139
- data/spec/chewy/type/adapter/sequel_spec.rb +0 -320
- data/spec/chewy/type/import_spec.rb +0 -433
- data/spec/chewy/type/mapping_spec.rb +0 -106
- data/spec/chewy/type/observe_spec.rb +0 -127
- data/spec/chewy/type/witchcraft_spec.rb +0 -154
- data/spec/chewy/type/wrapper_spec.rb +0 -58
- data/spec/chewy/type_spec.rb +0 -33
- data/spec/support/mongoid.rb +0 -81
- 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 '
|
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
|
5
|
+
# Simple usage - just pass index as argument.
|
6
6
|
#
|
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
|
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
|
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
|
21
|
+
# .to update_index(UsersIndex).and_reindex(user2).and_delete(user1) }
|
22
22
|
#
|
23
|
-
RSpec::Matchers.define :update_index do |
|
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
|
-
|
27
|
-
|
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
|
33
|
-
# specify { expect { user.save! }.to update_index(UsersIndex
|
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
|
34
|
+
# .to update_index(UsersIndex).and_reindex(user1, user2) }
|
36
35
|
# specify { expect { [user1, user2].map(&:save!) }
|
37
|
-
# .to update_index(UsersIndex
|
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
|
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
|
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
|
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
|
67
|
-
# specify { expect { user.destroy! }.to update_index(UsersIndex
|
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
|
76
|
+
# .to update_index(UsersIndex).and_reindex(user1, user2).only }
|
78
77
|
# specify { expect { [user1, user2].map(&:destroy!) }
|
79
|
-
# .to update_index(UsersIndex
|
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
|
83
|
+
# .to update_index(UsersIndex).and_reindex(user1).only }
|
85
84
|
#
|
86
|
-
chain(:only) do |*
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
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
|
-
|
121
|
-
@missed_reindex.push(body[:_id].to_s)
|
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
|
-
|
127
|
-
@missed_delete.push(body[:_id].to_s)
|
130
|
+
elsif @only
|
131
|
+
@missed_delete.push(body[:_id].to_s)
|
128
132
|
end
|
129
133
|
end
|
130
134
|
end
|
131
135
|
|
132
|
-
@reindex.
|
133
|
-
document[:match_count] = (!document[:expected_count] && document[:real_count]
|
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.
|
139
|
-
document[:match_count] = (!document[:expected_count] && document[:real_count]
|
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
|
-
|
144
|
-
|
145
|
-
|
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
|
152
|
-
output << "Expected index `#{
|
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 `#{
|
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),
|
173
|
+
output << @reindex.each.with_object('') do |(id, document), result|
|
170
174
|
unless document[:match_count] && document[:match_attributes]
|
171
|
-
|
172
|
-
if document[:real_count]
|
173
|
-
|
174
|
-
|
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
|
-
|
184
|
+
result << ', but it was not'
|
177
185
|
end
|
178
|
-
|
186
|
+
result << "\n"
|
179
187
|
end
|
180
188
|
end
|
181
189
|
|
182
|
-
output << @delete.each.with_object('') do |(id, document),
|
190
|
+
output << @delete.each.with_object('') do |(id, document), result|
|
183
191
|
unless document[:match_count]
|
184
|
-
|
185
|
-
if document[:real_count]
|
186
|
-
|
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
|
-
|
196
|
+
', but it was not'
|
189
197
|
end
|
190
|
-
|
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
|
199
|
-
"Expected index `#{
|
200
|
-
|
201
|
-
|
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
|
208
|
-
|
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
|
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
|
-
|
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
|
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
|
248
|
+
def array_difference(first, second)
|
247
249
|
difference = first.to_ary.dup
|
248
250
|
second.to_ary.each do |element|
|
249
|
-
|
250
|
-
|
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
@@ -4,21 +4,21 @@ module Chewy
|
|
4
4
|
include Comparable
|
5
5
|
attr_reader :major, :minor, :patch
|
6
6
|
|
7
|
-
def initialize
|
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 <=>
|
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
|
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
|
-
|
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
|
-
|
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
|
-
(
|
26
|
+
(raw_limit_value || default_per_page).to_i
|
21
27
|
end
|
22
28
|
|
23
29
|
def offset_value
|
24
|
-
|
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
|