chewy 0.9.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +214 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +41 -19
- data/.rubocop_todo.yml +2 -2
- data/.yardopts +5 -0
- data/Appraisals +58 -28
- data/CHANGELOG.md +153 -12
- data/Gemfile +20 -12
- data/LEGACY_DSL.md +497 -0
- data/LICENSE.txt +1 -1
- data/README.md +338 -528
- data/chewy.gemspec +11 -12
- data/gemfiles/rails.5.2.activerecord.gemfile +17 -0
- data/gemfiles/rails.5.2.mongoid.6.4.gemfile +17 -0
- data/gemfiles/rails.6.0.activerecord.gemfile +17 -0
- data/gemfiles/rails.6.1.activerecord.gemfile +19 -0
- data/gemfiles/ruby3.gemfile +10 -0
- data/gemfiles/sequel.4.45.gemfile +11 -0
- data/lib/chewy.rb +79 -44
- data/lib/chewy/backports/duplicable.rb +1 -1
- data/lib/chewy/config.rb +43 -17
- data/lib/chewy/errors.rb +2 -2
- data/lib/chewy/fields/base.rb +56 -31
- data/lib/chewy/fields/root.rb +44 -11
- data/lib/chewy/index.rb +237 -149
- data/lib/chewy/index/actions.rb +100 -35
- data/lib/chewy/index/aliases.rb +2 -1
- data/lib/chewy/index/settings.rb +11 -5
- data/lib/chewy/index/specification.rb +60 -0
- data/lib/chewy/journal.rb +40 -92
- data/lib/chewy/minitest/helpers.rb +6 -6
- data/lib/chewy/minitest/search_index_receiver.rb +17 -17
- data/lib/chewy/query.rb +182 -122
- data/lib/chewy/query/compose.rb +13 -13
- data/lib/chewy/query/criteria.rb +13 -13
- data/lib/chewy/query/filters.rb +21 -4
- data/lib/chewy/query/loading.rb +1 -2
- data/lib/chewy/query/nodes/and.rb +2 -2
- data/lib/chewy/query/nodes/bool.rb +1 -1
- data/lib/chewy/query/nodes/equal.rb +2 -2
- data/lib/chewy/query/nodes/exists.rb +1 -1
- data/lib/chewy/query/nodes/field.rb +1 -1
- data/lib/chewy/query/nodes/has_relation.rb +2 -2
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +1 -1
- data/lib/chewy/query/nodes/not.rb +2 -2
- data/lib/chewy/query/nodes/or.rb +2 -2
- data/lib/chewy/query/nodes/prefix.rb +1 -1
- data/lib/chewy/query/nodes/query.rb +2 -2
- data/lib/chewy/query/nodes/range.rb +4 -4
- data/lib/chewy/query/nodes/regexp.rb +4 -4
- data/lib/chewy/query/nodes/script.rb +3 -3
- data/lib/chewy/query/pagination.rb +10 -1
- data/lib/chewy/railtie.rb +4 -3
- data/lib/chewy/rake_helper.rb +265 -48
- data/lib/chewy/rspec/update_index.rb +33 -27
- data/lib/chewy/search.rb +79 -26
- data/lib/chewy/search/loader.rb +83 -0
- data/lib/chewy/{query → search}/pagination/kaminari.rb +13 -5
- data/lib/chewy/search/pagination/will_paginate.rb +43 -0
- data/lib/chewy/search/parameters.rb +168 -0
- 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/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/indices.rb +123 -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 +27 -0
- data/lib/chewy/search/parameters/offset.rb +17 -0
- data/lib/chewy/search/parameters/order.rb +64 -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 +73 -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/types.rb +20 -0
- data/lib/chewy/search/parameters/version.rb +16 -0
- data/lib/chewy/search/query_proxy.rb +257 -0
- data/lib/chewy/search/request.rb +1046 -0
- data/lib/chewy/search/response.rb +119 -0
- data/lib/chewy/search/scoping.rb +50 -0
- data/lib/chewy/search/scrolling.rb +134 -0
- data/lib/chewy/stash.rb +79 -0
- data/lib/chewy/strategy.rb +10 -3
- data/lib/chewy/strategy/active_job.rb +2 -1
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/bypass.rb +1 -1
- data/lib/chewy/strategy/resque.rb +1 -0
- data/lib/chewy/strategy/shoryuken.rb +40 -0
- data/lib/chewy/strategy/sidekiq.rb +13 -3
- data/lib/chewy/type.rb +29 -7
- data/lib/chewy/type/actions.rb +26 -2
- data/lib/chewy/type/adapter/active_record.rb +44 -29
- data/lib/chewy/type/adapter/base.rb +27 -7
- data/lib/chewy/type/adapter/mongoid.rb +19 -10
- data/lib/chewy/type/adapter/object.rb +187 -26
- data/lib/chewy/type/adapter/orm.rb +59 -32
- data/lib/chewy/type/adapter/sequel.rb +33 -19
- data/lib/chewy/type/crutch.rb +1 -1
- data/lib/chewy/type/import.rb +146 -191
- data/lib/chewy/type/import/bulk_builder.rb +122 -0
- data/lib/chewy/type/import/bulk_request.rb +78 -0
- data/lib/chewy/type/import/journal_builder.rb +45 -0
- data/lib/chewy/type/import/routine.rb +138 -0
- data/lib/chewy/type/mapping.rb +51 -35
- data/lib/chewy/type/observe.rb +17 -13
- data/lib/chewy/type/syncer.rb +222 -0
- data/lib/chewy/type/witchcraft.rb +32 -16
- data/lib/chewy/type/wrapper.rb +30 -4
- data/lib/chewy/version.rb +1 -1
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/lib/tasks/chewy.rake +84 -26
- data/spec/chewy/config_spec.rb +98 -1
- data/spec/chewy/fields/base_spec.rb +170 -135
- data/spec/chewy/fields/root_spec.rb +124 -20
- data/spec/chewy/fields/time_fields_spec.rb +2 -3
- data/spec/chewy/index/actions_spec.rb +214 -52
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +67 -38
- data/spec/chewy/index/specification_spec.rb +169 -0
- data/spec/chewy/index_spec.rb +108 -64
- data/spec/chewy/journal_spec.rb +150 -55
- data/spec/chewy/minitest/helpers_spec.rb +4 -4
- data/spec/chewy/minitest/search_index_receiver_spec.rb +1 -1
- data/spec/chewy/query/criteria_spec.rb +179 -179
- data/spec/chewy/query/filters_spec.rb +16 -16
- data/spec/chewy/query/loading_spec.rb +22 -20
- data/spec/chewy/query/nodes/and_spec.rb +2 -2
- data/spec/chewy/query/nodes/bool_spec.rb +4 -4
- data/spec/chewy/query/nodes/equal_spec.rb +19 -19
- data/spec/chewy/query/nodes/exists_spec.rb +6 -6
- data/spec/chewy/query/nodes/has_child_spec.rb +19 -19
- data/spec/chewy/query/nodes/has_parent_spec.rb +19 -19
- data/spec/chewy/query/nodes/missing_spec.rb +5 -5
- data/spec/chewy/query/nodes/not_spec.rb +4 -2
- data/spec/chewy/query/nodes/or_spec.rb +2 -2
- data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
- data/spec/chewy/query/nodes/query_spec.rb +2 -2
- data/spec/chewy/query/nodes/range_spec.rb +18 -18
- data/spec/chewy/query/nodes/raw_spec.rb +1 -1
- data/spec/chewy/query/nodes/regexp_spec.rb +14 -14
- data/spec/chewy/query/nodes/script_spec.rb +4 -4
- data/spec/chewy/query/pagination/kaminari_spec.rb +3 -55
- data/spec/chewy/query/pagination/will_paginate_spec.rb +5 -0
- data/spec/chewy/query/pagination_spec.rb +25 -21
- data/spec/chewy/query_spec.rb +503 -561
- data/spec/chewy/rake_helper_spec.rb +381 -0
- data/spec/chewy/repository_spec.rb +4 -4
- data/spec/chewy/rspec/update_index_spec.rb +89 -56
- data/spec/chewy/runtime_spec.rb +2 -2
- data/spec/chewy/search/loader_spec.rb +117 -0
- data/spec/chewy/search/pagination/kaminari_examples.rb +71 -0
- data/spec/chewy/search/pagination/kaminari_spec.rb +21 -0
- data/spec/chewy/search/pagination/will_paginate_examples.rb +63 -0
- data/spec/chewy/search/pagination/will_paginate_spec.rb +23 -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/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/indices_spec.rb +191 -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 +65 -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 +388 -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 +32 -0
- data/spec/chewy/search/parameters/search_type_spec.rb +5 -0
- data/spec/chewy/search/parameters/source_spec.rb +156 -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/types_spec.rb +5 -0
- data/spec/chewy/search/parameters/version_spec.rb +5 -0
- data/spec/chewy/search/parameters_spec.rb +147 -0
- data/spec/chewy/search/query_proxy_spec.rb +68 -0
- data/spec/chewy/search/request_spec.rb +685 -0
- data/spec/chewy/search/response_spec.rb +198 -0
- data/spec/chewy/search/scrolling_spec.rb +169 -0
- data/spec/chewy/search_spec.rb +33 -16
- data/spec/chewy/stash_spec.rb +95 -0
- data/spec/chewy/strategy/active_job_spec.rb +21 -2
- data/spec/chewy/strategy/resque_spec.rb +6 -0
- data/spec/chewy/strategy/shoryuken_spec.rb +70 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +13 -1
- data/spec/chewy/strategy_spec.rb +6 -6
- data/spec/chewy/type/actions_spec.rb +29 -10
- data/spec/chewy/type/adapter/active_record_spec.rb +203 -91
- data/spec/chewy/type/adapter/mongoid_spec.rb +112 -54
- data/spec/chewy/type/adapter/object_spec.rb +101 -28
- data/spec/chewy/type/adapter/sequel_spec.rb +149 -82
- data/spec/chewy/type/import/bulk_builder_spec.rb +279 -0
- data/spec/chewy/type/import/bulk_request_spec.rb +102 -0
- data/spec/chewy/type/import/journal_builder_spec.rb +95 -0
- data/spec/chewy/type/import/routine_spec.rb +110 -0
- data/spec/chewy/type/import_spec.rb +356 -271
- data/spec/chewy/type/mapping_spec.rb +96 -29
- data/spec/chewy/type/observe_spec.rb +9 -5
- data/spec/chewy/type/syncer_spec.rb +123 -0
- data/spec/chewy/type/witchcraft_spec.rb +61 -29
- data/spec/chewy/type/wrapper_spec.rb +63 -23
- data/spec/chewy/type_spec.rb +28 -7
- data/spec/chewy_spec.rb +75 -7
- data/spec/spec_helper.rb +17 -3
- data/spec/support/active_record.rb +5 -1
- data/spec/support/class_helpers.rb +0 -14
- data/spec/support/mongoid.rb +15 -3
- data/spec/support/sequel.rb +6 -1
- metadata +219 -58
- data/.travis.yml +0 -36
- data/gemfiles/rails.3.2.activerecord.gemfile +0 -16
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +0 -15
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.activerecord.gemfile +0 -17
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.4.0.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.4.0.will_paginate.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.gemfile +0 -16
- data/gemfiles/rails.4.2.mongoid.5.1.kaminari.gemfile +0 -15
- data/gemfiles/rails.4.2.mongoid.5.1.will_paginate.gemfile +0 -15
- data/gemfiles/rails.5.0.activerecord.gemfile +0 -17
- data/gemfiles/rails.5.0.activerecord.kaminari.gemfile +0 -16
- data/gemfiles/rails.5.0.activerecord.will_paginate.gemfile +0 -16
- data/gemfiles/sequel.4.38.gemfile +0 -14
- data/lib/chewy/journal/apply.rb +0 -31
- data/lib/chewy/journal/clean.rb +0 -24
- data/lib/chewy/journal/entry.rb +0 -83
- data/lib/chewy/journal/query.rb +0 -87
- data/lib/chewy/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/scoping.rb +0 -20
- data/spec/chewy/journal/apply_spec.rb +0 -120
- data/spec/chewy/journal/entry_spec.rb +0 -237
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -59
data/spec/chewy/journal_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Chewy::Journal do
|
4
|
-
context 'journaling', orm
|
4
|
+
context 'journaling', :orm do
|
5
5
|
['', 'namespace/'].each do |namespace|
|
6
6
|
context namespace.present? ? 'with namespace' : 'without namespace' do
|
7
7
|
before do
|
@@ -22,11 +22,6 @@ describe Chewy::Journal do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
Chewy.massacre
|
25
|
-
begin
|
26
|
-
Chewy.client.indices.delete(index: Chewy::Journal.index_name)
|
27
|
-
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
28
|
-
nil
|
29
|
-
end
|
30
25
|
Chewy.settings[:prefix] = 'some_prefix'
|
31
26
|
Timecop.freeze(time)
|
32
27
|
end
|
@@ -56,115 +51,215 @@ describe Chewy::Journal do
|
|
56
51
|
|
57
52
|
places_index.import
|
58
53
|
|
59
|
-
expect(Chewy.
|
54
|
+
expect(Chewy::Stash::Journal.exists?).to eq true
|
60
55
|
|
61
56
|
Timecop.freeze(update_time)
|
62
|
-
cities.first.
|
57
|
+
cities.first.update!(name: 'Supername')
|
63
58
|
|
64
59
|
Timecop.freeze(destroy_time)
|
65
60
|
countries.last.destroy
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
journal_entries = Chewy::Stash::Journal.order(:created_at).hits.map { |r| r['_source'] }
|
69
63
|
expected_journal = [
|
70
64
|
{
|
71
65
|
'index_name' => "#{namespace}places",
|
72
66
|
'type_name' => 'city',
|
73
67
|
'action' => 'index',
|
74
|
-
'
|
75
|
-
'created_at' => time.
|
68
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
69
|
+
'created_at' => time.utc.as_json
|
76
70
|
},
|
77
71
|
{
|
78
72
|
'index_name' => "#{namespace}places",
|
79
73
|
'type_name' => 'city',
|
80
74
|
'action' => 'index',
|
81
|
-
'
|
82
|
-
'created_at' => time.
|
75
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
76
|
+
'created_at' => time.utc.as_json
|
83
77
|
},
|
84
78
|
{
|
85
79
|
'index_name' => "#{namespace}places",
|
86
80
|
'type_name' => 'country',
|
87
81
|
'action' => 'index',
|
88
|
-
'
|
89
|
-
'created_at' => time.
|
82
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
83
|
+
'created_at' => time.utc.as_json
|
90
84
|
},
|
91
85
|
{
|
92
86
|
'index_name' => "#{namespace}places",
|
93
87
|
'type_name' => 'country',
|
94
88
|
'action' => 'index',
|
95
|
-
'
|
96
|
-
'created_at' => time.
|
89
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
90
|
+
'created_at' => time.utc.as_json
|
97
91
|
},
|
98
92
|
{
|
99
93
|
'index_name' => "#{namespace}places",
|
100
94
|
'type_name' => 'country',
|
101
95
|
'action' => 'index',
|
102
|
-
'
|
103
|
-
'created_at' => time.
|
96
|
+
'references' => ['3'].map(&Base64.method(:encode64)),
|
97
|
+
'created_at' => time.utc.as_json
|
104
98
|
},
|
105
99
|
{
|
106
100
|
'index_name' => "#{namespace}places",
|
107
101
|
'type_name' => 'city',
|
108
102
|
'action' => 'index',
|
109
|
-
'
|
110
|
-
'created_at' => import_time.
|
103
|
+
'references' => %w[1 2].map(&Base64.method(:encode64)),
|
104
|
+
'created_at' => import_time.utc.as_json
|
111
105
|
},
|
112
106
|
{
|
113
107
|
'index_name' => "#{namespace}places",
|
114
108
|
'type_name' => 'country',
|
115
109
|
'action' => 'index',
|
116
|
-
'
|
117
|
-
'created_at' => import_time.
|
110
|
+
'references' => %w[1 2 3].map(&Base64.method(:encode64)),
|
111
|
+
'created_at' => import_time.utc.as_json
|
118
112
|
},
|
119
113
|
{
|
120
114
|
'index_name' => "#{namespace}places",
|
121
115
|
'type_name' => 'city',
|
122
116
|
'action' => 'index',
|
123
|
-
'
|
124
|
-
'created_at' => update_time.
|
117
|
+
'references' => ['1'].map(&Base64.method(:encode64)),
|
118
|
+
'created_at' => update_time.utc.as_json
|
125
119
|
},
|
126
120
|
{
|
127
121
|
'index_name' => "#{namespace}places",
|
128
122
|
'type_name' => 'country',
|
129
123
|
'action' => 'delete',
|
130
|
-
'
|
131
|
-
'created_at' => destroy_time.
|
124
|
+
'references' => ['2'].map(&Base64.method(:encode64)),
|
125
|
+
'created_at' => destroy_time.utc.as_json
|
132
126
|
}
|
133
127
|
]
|
134
128
|
|
135
|
-
expect(Chewy
|
136
|
-
expect(
|
137
|
-
|
138
|
-
journal_entries = Chewy::Journal
|
139
|
-
expect(journal_entries.
|
140
|
-
# we have only 2 types, so we can group all journal entries(4) into 2
|
141
|
-
expect(Chewy::Journal::Entry.group(journal_entries)).to eq [
|
142
|
-
Chewy::Journal::Entry.new('index_name' => "#{namespace}places",
|
143
|
-
'type_name' => 'city',
|
144
|
-
'action' => nil,
|
145
|
-
'object_ids' => [1, 2],
|
146
|
-
'created_at' => nil),
|
147
|
-
Chewy::Journal::Entry.new('index_name' => "#{namespace}places",
|
148
|
-
'type_name' => 'country',
|
149
|
-
'action' => 'delete',
|
150
|
-
'object_ids' => [1, 2, 3],
|
151
|
-
'created_at' => destroy_time.to_i)
|
152
|
-
]
|
129
|
+
expect(Chewy::Stash::Journal.count).to eq 9
|
130
|
+
expect(journal_entries).to eq expected_journal
|
131
|
+
|
132
|
+
journal_entries = Chewy::Stash::Journal.entries(import_time - 1)
|
133
|
+
expect(journal_entries.size).to eq 4
|
153
134
|
|
154
135
|
# simulate lost data
|
155
136
|
Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_places", type: 'city', id: 1, refresh: true)
|
156
|
-
expect(places_index::City.
|
137
|
+
expect(places_index::City.count).to eq 1
|
138
|
+
|
139
|
+
described_class.new.apply(time)
|
140
|
+
expect(places_index::City.count).to eq 2
|
141
|
+
|
142
|
+
clean_response = described_class.new.clean(import_time)
|
143
|
+
expect(clean_response['deleted'] || clean_response['_indices']['_all']['deleted']).to eq 7
|
144
|
+
Chewy.client.indices.refresh
|
145
|
+
expect(Chewy::Stash::Journal.count).to eq 2
|
146
|
+
|
147
|
+
Timecop.return
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context do
|
155
|
+
before { Chewy.massacre }
|
156
|
+
before do
|
157
|
+
stub_model(:city) do
|
158
|
+
update_index 'cities', :self
|
159
|
+
end
|
160
|
+
stub_model(:country) do
|
161
|
+
update_index 'countries', :self
|
162
|
+
end
|
157
163
|
|
158
|
-
|
159
|
-
|
164
|
+
stub_index(:cities) do
|
165
|
+
define_type City do
|
166
|
+
default_import_options journal: true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
stub_index(:countries) do
|
170
|
+
define_type Country do
|
171
|
+
default_import_options journal: true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
160
175
|
|
161
|
-
|
162
|
-
|
176
|
+
describe '#apply' do
|
177
|
+
specify { expect(described_class.new(CitiesIndex).apply(2.minutes.ago)).to eq(0) }
|
178
|
+
|
179
|
+
context 'with an index filter' do
|
180
|
+
let(:time) { Time.now }
|
181
|
+
|
182
|
+
before { Timecop.freeze(time) }
|
183
|
+
after { Timecop.return }
|
184
|
+
|
185
|
+
specify do
|
186
|
+
Chewy.strategy(:urgent) do
|
187
|
+
Array.new(2) { |i| City.create!(id: i + 1) }
|
188
|
+
Array.new(2) { |i| Country.create!(id: i + 1) }
|
163
189
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
expect(
|
190
|
+
# simulate lost data
|
191
|
+
Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true)
|
192
|
+
Chewy.client.delete(index: 'countries', type: 'country', id: 1, refresh: true)
|
193
|
+
expect(CitiesIndex.all.to_a.length).to eq 1
|
194
|
+
expect(CountriesIndex.all.to_a.length).to eq 1
|
195
|
+
|
196
|
+
# Replay on specific index
|
197
|
+
expect(described_class.new(CitiesIndex).apply(time)).to eq(2)
|
198
|
+
expect(CitiesIndex.all.to_a.length).to eq 2
|
199
|
+
expect(CountriesIndex.all.to_a.length).to eq 1
|
200
|
+
|
201
|
+
# Replay on both
|
202
|
+
Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true)
|
203
|
+
expect(CitiesIndex.all.to_a.length).to eq 1
|
204
|
+
expect(described_class.new(CitiesIndex, CountriesIndex).apply(time)).to eq(4)
|
205
|
+
expect(CitiesIndex.all.to_a.length).to eq 2
|
206
|
+
expect(CountriesIndex.all.to_a.length).to eq 2
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context 'retries' do
|
212
|
+
let(:time) { Time.now.to_i }
|
213
|
+
before do
|
214
|
+
Timecop.freeze
|
215
|
+
Chewy.strategy(:urgent)
|
216
|
+
City.create!(id: 1)
|
217
|
+
end
|
218
|
+
|
219
|
+
after do
|
220
|
+
Chewy.strategy.pop
|
221
|
+
Timecop.return
|
222
|
+
end
|
223
|
+
|
224
|
+
specify 'journal was cleaned after the first call' do
|
225
|
+
expect(Chewy::Stash::Journal).to receive(:entries).exactly(2).and_call_original
|
226
|
+
expect(described_class.new.apply(time)).to eq(1)
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'endless journal' do
|
230
|
+
let(:count_of_checks) { 10 } # default
|
231
|
+
let!(:journal_entries) do
|
232
|
+
record = Chewy::Stash::Journal.entries(time).first
|
233
|
+
Array.new(count_of_checks) do |i|
|
234
|
+
Chewy::Stash::Journal::Journal.new(
|
235
|
+
record.attributes.merge(
|
236
|
+
'created_at' => time.to_i + i,
|
237
|
+
'references' => [i.to_s]
|
238
|
+
)
|
239
|
+
)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
specify '10 retries by default' do
|
244
|
+
expect(Chewy::Stash::Journal)
|
245
|
+
.to receive(:entries).exactly(count_of_checks) { [journal_entries.shift].compact }
|
246
|
+
expect(described_class.new.apply(time)).to eq(10)
|
247
|
+
end
|
248
|
+
|
249
|
+
specify 'with :once parameter set' do
|
250
|
+
expect(Chewy::Stash::Journal)
|
251
|
+
.to receive(:entries).exactly(1) { [journal_entries.shift].compact }
|
252
|
+
expect(described_class.new.apply(time, retries: 1)).to eq(1)
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with retries parameter set' do
|
256
|
+
let(:retries) { 5 }
|
257
|
+
|
258
|
+
specify do
|
259
|
+
expect(Chewy::Stash::Journal)
|
260
|
+
.to receive(:entries).exactly(retries) { [journal_entries.shift].compact }
|
261
|
+
expect(described_class.new.apply(time, retries: retries)).to eq(5)
|
262
|
+
end
|
168
263
|
end
|
169
264
|
end
|
170
265
|
end
|
@@ -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: [{
|
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: [{
|
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: [{
|
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: [{
|
68
|
+
DummiesIndex::Dummy.bulk body: [{index: {_id: 42, data: {}}}, {index: {_id: 41, data: {}}}]
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -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([
|
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([
|
52
|
-
.to change { subject.scores }.to([
|
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: {
|
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: {
|
68
|
-
.to change { subject.script_fields }.to(distance_km: {
|
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([{
|
86
|
+
.to change { subject.queries }.to([{field: 'hello'}, {field: 'world'}])
|
87
87
|
end
|
88
88
|
specify do
|
89
|
-
expect { subject.update_queries([{
|
90
|
-
.to change { subject.queries }.to([{
|
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([{
|
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([{
|
102
|
+
.to change { subject.filters }.to([{field: 'hello'}, {field: 'world'}])
|
103
103
|
end
|
104
104
|
specify do
|
105
|
-
expect { subject.update_filters([{
|
106
|
-
.to change { subject.filters }.to([{
|
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([{
|
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([{
|
118
|
+
.to change { subject.post_filters }.to([{field: 'hello'}, {field: 'world'}])
|
119
119
|
end
|
120
120
|
specify do
|
121
|
-
expect { subject.update_post_filters([{
|
122
|
-
.to change { subject.post_filters }.to([{
|
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([
|
138
|
-
.to change { subject.sort }.to([
|
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([{
|
142
|
-
.to change { subject.sort }.to([{
|
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: {
|
146
|
-
.to change { subject.sort }.to([:field1, {
|
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([{
|
150
|
-
.to change { subject.sort }.to([{
|
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: {
|
154
|
-
.to change { subject.sort }.to([{
|
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([{
|
158
|
-
.to change { subject.sort }.to([{
|
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([{
|
162
|
-
.to change { subject.sort }.to([{
|
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([{
|
166
|
-
.to change { subject.sort }.to([{
|
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([{
|
170
|
-
.to change { subject.sort }.to([{
|
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: {
|
174
|
-
.to change { subject.sort }.to([{
|
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: {
|
178
|
-
.to change { subject.sort }.to([
|
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([
|
186
|
-
specify { expect { subject.update_fields([
|
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([
|
189
|
-
.to change { subject.fields }.to(%w
|
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([
|
193
|
-
.to change { subject.fields }.to(%w
|
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([
|
201
|
-
specify { expect { subject.update_types([
|
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([
|
204
|
-
.to change { subject.types }.to(%w
|
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([
|
208
|
-
.to change { subject.types }.to(%w
|
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: {
|
235
|
-
.merge(criteria.tap { |c| c.update_script_fields(distance_km: {
|
236
|
-
.to eq(distance_m: {
|
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([{
|
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([{
|
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([{
|
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([{
|
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([
|
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
|
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
|
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: {
|
300
|
-
.merge(criteria.tap { |c| c.update_script_fields(distance_km: {
|
301
|
-
.to eq(distance_m: {
|
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([{
|
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([{
|
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([{
|
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([
|
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
|
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
|
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: {
|
348
|
-
specify { expect(request_body { update_request_options(from: 10) }).to eq(body: {
|
349
|
-
specify { expect(request_body { update_request_options(explain: true) }).to eq(body: {
|
350
|
-
specify { expect(request_body { update_queries(:query) }).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}) }
|
351
351
|
specify do
|
352
352
|
expect(request_body do
|
353
|
-
update_scores(script_score: {
|
354
|
-
end).to eq(body: {
|
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: {
|
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: {
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
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: {
|
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: {
|
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: {
|
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: {
|
393
|
-
end).to eq(body: {
|
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([
|
407
|
-
.to eq(query: {
|
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([
|
412
|
+
update_queries(%i[query1 query2])
|
413
413
|
end)
|
414
|
-
.to eq(query: {
|
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([
|
419
|
+
update_queries(%i[query1 query2])
|
420
420
|
end)
|
421
|
-
.to eq(query: {
|
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([
|
426
|
-
.to eq(query: {
|
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([
|
430
|
-
.to eq(query: {
|
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([
|
436
|
-
update_queries([
|
435
|
+
update_filters(%i[filter1 filter2])
|
436
|
+
update_queries(%i[query1 query2])
|
437
437
|
end)
|
438
|
-
.to eq(query: {
|
439
|
-
|
440
|
-
|
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([
|
446
|
-
update_queries([
|
445
|
+
update_filters(%i[filter1 filter2])
|
446
|
+
update_queries(%i[query1 query2])
|
447
447
|
end)
|
448
|
-
.to eq(query: {
|
449
|
-
|
450
|
-
|
451
|
-
|
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([
|
459
|
-
update_queries([
|
460
|
-
end).to eq(query: {
|
461
|
-
|
462
|
-
|
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: {
|
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: {
|
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: {
|
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: {
|
499
|
+
specify { expect(_request_filter { update_types(:type) }).to eq(type: {value: 'type'}) }
|
500
500
|
specify do
|
501
|
-
expect(_request_filter { update_types([
|
502
|
-
.to eq(or: [{
|
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([
|
507
|
-
.to eq(and: [
|
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([
|
512
|
+
update_filters(%i[filter1 filter2])
|
513
513
|
end)
|
514
|
-
.to eq(or: [
|
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([
|
519
|
+
update_filters(%i[filter1 filter2])
|
520
520
|
end)
|
521
|
-
.to eq(bool: {
|
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([
|
526
|
+
update_filters(%i[filter1 filter2])
|
527
527
|
end)
|
528
|
-
.to eq(bool: {
|
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([
|
533
|
+
update_filters(%i[filter1 filter2])
|
534
534
|
end)
|
535
|
-
.to eq(bool: {
|
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([
|
541
|
-
update_filters([
|
540
|
+
update_types(%i[type1 type2])
|
541
|
+
update_filters(%i[filter1 filter2])
|
542
542
|
end)
|
543
|
-
.to eq(and: [{
|
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([
|
549
|
-
update_filters([
|
548
|
+
update_types(%i[type1 type2])
|
549
|
+
update_filters(%i[filter1 filter2])
|
550
550
|
end)
|
551
|
-
.to eq(and: [{
|
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([
|
557
|
-
update_filters([
|
556
|
+
update_types(%i[type1 type2])
|
557
|
+
update_filters(%i[filter1 filter2])
|
558
558
|
end)
|
559
|
-
.to eq(and: [{
|
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([
|
565
|
-
update_filters([
|
564
|
+
update_types(%i[type1 type2])
|
565
|
+
update_filters(%i[filter1 filter2])
|
566
566
|
end)
|
567
|
-
.to eq(and: [{
|
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([
|
573
|
-
update_filters([
|
572
|
+
update_types(%i[type1 type2])
|
573
|
+
update_filters(%i[filter1 filter2])
|
574
574
|
end)
|
575
|
-
.to eq(and: [{
|
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([
|
589
|
-
.to eq(and: [
|
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([
|
594
|
+
update_post_filters(%i[post_filter1 post_filter2])
|
595
595
|
end)
|
596
|
-
.to eq(or: [
|
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([
|
601
|
+
update_post_filters(%i[post_filter1 post_filter2])
|
602
602
|
end)
|
603
|
-
.to eq(bool: {
|
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([
|
608
|
+
update_post_filters(%i[post_filter1 post_filter2])
|
609
609
|
end)
|
610
|
-
.to eq(bool: {
|
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([
|
618
|
-
.to eq(or: [
|
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: {
|
630
|
+
specify { expect(_request_types { update_types(:type1) }).to eq(type: {value: 'type1'}) }
|
631
631
|
specify do
|
632
|
-
expect(_request_types { update_types([
|
633
|
-
.to eq(or: [{
|
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) { {
|
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: {
|
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: {
|
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: {
|
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: {
|
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: {
|
662
|
-
specify { expect(_queries_join([query, query], :must_not)).to eq(bool: {
|
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: {
|
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) { {
|
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: {
|
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: {
|
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: {
|
694
|
-
specify { expect(_filters_join([filter, filter], :must_not)).to eq(bool: {
|
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: {
|
698
|
+
specify { expect(_filters_join([filter, filter], '25%')).to eq(bool: {should: [filter, filter], minimum_should_match: '25%'}) }
|
699
699
|
end
|
700
700
|
end
|