chewy 0.8.4 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +56 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +36 -67
- data/.yardopts +5 -0
- data/Appraisals +63 -58
- data/CHANGELOG.md +168 -11
- data/Gemfile +16 -9
- data/Guardfile +5 -5
- data/LEGACY_DSL.md +497 -0
- data/README.md +403 -470
- data/Rakefile +11 -1
- data/chewy.gemspec +12 -15
- data/gemfiles/rails.4.0.activerecord.gemfile +9 -9
- data/gemfiles/rails.4.1.activerecord.gemfile +9 -9
- data/gemfiles/rails.4.2.activerecord.gemfile +8 -8
- data/gemfiles/rails.4.2.mongoid.5.2.gemfile +16 -0
- data/gemfiles/rails.5.0.activerecord.gemfile +16 -0
- data/gemfiles/rails.5.0.mongoid.6.1.gemfile +16 -0
- data/gemfiles/rails.5.1.activerecord.gemfile +16 -0
- data/gemfiles/rails.5.1.mongoid.6.3.gemfile +16 -0
- data/gemfiles/rails.5.2.activerecord.gemfile +16 -0
- data/gemfiles/sequel.4.45.gemfile +11 -0
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +53 -21
- data/lib/chewy/errors.rb +6 -6
- data/lib/chewy/fields/base.rb +59 -29
- data/lib/chewy/fields/root.rb +49 -14
- data/lib/chewy/index/actions.rb +95 -36
- data/lib/chewy/index/aliases.rb +2 -1
- data/lib/chewy/index/settings.rb +10 -5
- data/lib/chewy/index/specification.rb +60 -0
- data/lib/chewy/index.rb +239 -138
- data/lib/chewy/journal.rb +55 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/query/compose.rb +18 -19
- data/lib/chewy/query/criteria.rb +34 -24
- data/lib/chewy/query/filters.rb +28 -11
- data/lib/chewy/query/loading.rb +3 -4
- data/lib/chewy/query/nodes/and.rb +1 -1
- data/lib/chewy/query/nodes/base.rb +1 -1
- data/lib/chewy/query/nodes/bool.rb +6 -4
- data/lib/chewy/query/nodes/equal.rb +4 -4
- data/lib/chewy/query/nodes/exists.rb +1 -1
- data/lib/chewy/query/nodes/expr.rb +2 -2
- data/lib/chewy/query/nodes/field.rb +35 -31
- data/lib/chewy/query/nodes/has_child.rb +1 -0
- data/lib/chewy/query/nodes/has_parent.rb +1 -0
- data/lib/chewy/query/nodes/has_relation.rb +10 -12
- data/lib/chewy/query/nodes/missing.rb +1 -1
- data/lib/chewy/query/nodes/not.rb +1 -1
- data/lib/chewy/query/nodes/or.rb +1 -1
- data/lib/chewy/query/nodes/prefix.rb +3 -2
- data/lib/chewy/query/nodes/query.rb +1 -1
- data/lib/chewy/query/nodes/range.rb +9 -9
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +13 -9
- data/lib/chewy/query/nodes/script.rb +4 -4
- data/lib/chewy/query/pagination.rb +10 -1
- data/lib/chewy/query.rb +286 -170
- data/lib/chewy/railtie.rb +7 -6
- data/lib/chewy/rake_helper.rb +275 -37
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec/update_index.rb +70 -65
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/runtime/version.rb +4 -4
- 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/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/parameters.rb +167 -0
- data/lib/chewy/search/query_proxy.rb +257 -0
- data/lib/chewy/search/request.rb +1045 -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/search.rb +81 -26
- data/lib/chewy/stash.rb +79 -0
- data/lib/chewy/strategy/active_job.rb +1 -0
- data/lib/chewy/strategy/atomic.rb +2 -4
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/resque.rb +1 -0
- data/lib/chewy/strategy/shoryuken.rb +40 -0
- data/lib/chewy/strategy/sidekiq.rb +13 -1
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/strategy.rb +19 -10
- data/lib/chewy/type/actions.rb +26 -2
- data/lib/chewy/type/adapter/active_record.rb +50 -24
- data/lib/chewy/type/adapter/base.rb +29 -9
- data/lib/chewy/type/adapter/mongoid.rb +19 -10
- data/lib/chewy/type/adapter/object.rb +195 -31
- data/lib/chewy/type/adapter/orm.rb +69 -33
- data/lib/chewy/type/adapter/sequel.rb +37 -19
- data/lib/chewy/type/crutch.rb +5 -4
- 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/import.rb +150 -176
- data/lib/chewy/type/mapping.rb +58 -42
- data/lib/chewy/type/observe.rb +21 -15
- data/lib/chewy/type/syncer.rb +222 -0
- data/lib/chewy/type/witchcraft.rb +89 -34
- data/lib/chewy/type/wrapper.rb +48 -16
- data/lib/chewy/type.rb +77 -49
- data/lib/chewy/version.rb +1 -1
- data/lib/chewy.rb +95 -52
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/sequel/plugins/chewy_observe.rb +4 -19
- data/lib/tasks/chewy.rake +91 -28
- data/spec/chewy/config_spec.rb +130 -12
- data/spec/chewy/fields/base_spec.rb +194 -172
- data/spec/chewy/fields/root_spec.rb +123 -17
- data/spec/chewy/fields/time_fields_spec.rb +10 -9
- data/spec/chewy/index/actions_spec.rb +228 -43
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +100 -49
- data/spec/chewy/index/specification_spec.rb +169 -0
- data/spec/chewy/index_spec.rb +159 -63
- data/spec/chewy/journal_spec.rb +268 -0
- data/spec/chewy/minitest/helpers_spec.rb +90 -0
- data/spec/chewy/minitest/search_index_receiver_spec.rb +120 -0
- data/spec/chewy/query/criteria_spec.rb +503 -236
- data/spec/chewy/query/filters_spec.rb +96 -68
- data/spec/chewy/query/loading_spec.rb +80 -42
- data/spec/chewy/query/nodes/and_spec.rb +3 -7
- data/spec/chewy/query/nodes/bool_spec.rb +5 -13
- data/spec/chewy/query/nodes/equal_spec.rb +20 -20
- data/spec/chewy/query/nodes/exists_spec.rb +7 -7
- data/spec/chewy/query/nodes/has_child_spec.rb +42 -23
- data/spec/chewy/query/nodes/has_parent_spec.rb +42 -23
- data/spec/chewy/query/nodes/match_all_spec.rb +2 -2
- data/spec/chewy/query/nodes/missing_spec.rb +6 -5
- data/spec/chewy/query/nodes/not_spec.rb +5 -7
- data/spec/chewy/query/nodes/or_spec.rb +3 -7
- data/spec/chewy/query/nodes/prefix_spec.rb +6 -6
- data/spec/chewy/query/nodes/query_spec.rb +3 -3
- data/spec/chewy/query/nodes/range_spec.rb +19 -19
- data/spec/chewy/query/nodes/raw_spec.rb +2 -2
- data/spec/chewy/query/nodes/regexp_spec.rb +31 -19
- data/spec/chewy/query/nodes/script_spec.rb +5 -5
- 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 -22
- data/spec/chewy/query_spec.rb +510 -505
- data/spec/chewy/rake_helper_spec.rb +381 -0
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +215 -113
- 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 +145 -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 +192 -0
- data/spec/chewy/search/scrolling_spec.rb +169 -0
- data/spec/chewy/search_spec.rb +37 -20
- data/spec/chewy/stash_spec.rb +95 -0
- data/spec/chewy/strategy/active_job_spec.rb +8 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +8 -2
- data/spec/chewy/strategy/shoryuken_spec.rb +66 -0
- data/spec/chewy/strategy/sidekiq_spec.rb +10 -2
- 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 +357 -139
- data/spec/chewy/type/adapter/mongoid_spec.rb +220 -101
- data/spec/chewy/type/adapter/object_spec.rb +129 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +304 -152
- 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 +360 -244
- data/spec/chewy/type/mapping_spec.rb +96 -29
- data/spec/chewy/type/observe_spec.rb +25 -15
- data/spec/chewy/type/syncer_spec.rb +123 -0
- data/spec/chewy/type/witchcraft_spec.rb +122 -44
- data/spec/chewy/type/wrapper_spec.rb +63 -23
- data/spec/chewy/type_spec.rb +32 -10
- data/spec/chewy_spec.rb +82 -12
- data/spec/spec_helper.rb +16 -2
- data/spec/support/active_record.rb +6 -2
- data/spec/support/class_helpers.rb +4 -19
- data/spec/support/mongoid.rb +17 -5
- data/spec/support/sequel.rb +6 -1
- metadata +250 -57
- 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.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.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.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/query/pagination/will_paginate.rb +0 -27
- data/lib/chewy/query/scoping.rb +0 -20
- data/spec/chewy/query/pagination/will_paginage_spec.rb +0 -60
@@ -1,44 +1,150 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Chewy::Fields::Root do
|
4
|
-
specify { expect(described_class.new('name').value).to be_a(Proc) }
|
5
|
-
# TODO: add 'should_behave_like base_field'
|
6
|
-
|
7
4
|
subject(:field) { described_class.new('product') }
|
8
5
|
|
9
6
|
describe '#dynamic_template' do
|
10
7
|
specify do
|
11
|
-
field.dynamic_template 'hello', type: '
|
8
|
+
field.dynamic_template 'hello', type: 'keyword'
|
12
9
|
field.dynamic_template 'hello*', :integer
|
13
10
|
field.dynamic_template 'hello.*'
|
14
|
-
field.dynamic_template
|
15
|
-
field.dynamic_template
|
11
|
+
field.dynamic_template(/hello/)
|
12
|
+
field.dynamic_template(/hello.*/)
|
16
13
|
field.dynamic_template template_42: {mapping: {}, match: ''}
|
17
|
-
field.dynamic_template
|
14
|
+
field.dynamic_template(/hello\..*/)
|
18
15
|
|
19
|
-
expect(field.mappings_hash).to eq(
|
20
|
-
{template_1: {mapping: {type: '
|
16
|
+
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
17
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}},
|
21
18
|
{template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
|
22
19
|
{template_3: {mapping: {}, path_match: 'hello.*'}},
|
23
20
|
{template_4: {mapping: {}, match: 'hello', match_pattern: 'regexp'}},
|
24
21
|
{template_5: {mapping: {}, match: 'hello.*', match_pattern: 'regexp'}},
|
25
22
|
{template_42: {mapping: {}, match: ''}},
|
26
23
|
{template_7: {mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp'}}
|
27
|
-
]}
|
24
|
+
]})
|
28
25
|
end
|
29
26
|
|
30
27
|
context do
|
31
|
-
subject(:field)
|
32
|
-
|
33
|
-
|
28
|
+
subject(:field) do
|
29
|
+
described_class.new('product', dynamic_templates: [
|
30
|
+
{template_42: {mapping: {}, match: ''}}
|
31
|
+
])
|
32
|
+
end
|
34
33
|
|
35
34
|
specify do
|
36
|
-
field.dynamic_template 'hello', type: '
|
37
|
-
expect(field.mappings_hash).to eq(
|
35
|
+
field.dynamic_template 'hello', type: 'keyword'
|
36
|
+
expect(field.mappings_hash).to eq(product: {dynamic_templates: [
|
38
37
|
{template_42: {mapping: {}, match: ''}},
|
39
|
-
{template_1: {mapping: {type: '
|
40
|
-
]}
|
38
|
+
{template_1: {mapping: {type: 'keyword'}, match: 'hello'}}
|
39
|
+
]})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#compose' do
|
45
|
+
context 'empty children', :orm do
|
46
|
+
before do
|
47
|
+
stub_model(:city)
|
48
|
+
stub_index(:places) do
|
49
|
+
define_type City
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:city) { City.new(name: 'London', rating: 100) }
|
54
|
+
|
55
|
+
specify do
|
56
|
+
expect(PlacesIndex::City.root.compose(city))
|
57
|
+
.to match(hash_including('name' => 'London', 'rating' => 100))
|
58
|
+
end
|
59
|
+
specify do
|
60
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
61
|
+
.to eq('name' => 'London')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'has children' do
|
66
|
+
before do
|
67
|
+
stub_index(:places) do
|
68
|
+
define_type :city do
|
69
|
+
field :name, :rating
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:city) { double(name: 'London', rating: 100) }
|
75
|
+
|
76
|
+
specify do
|
77
|
+
expect(PlacesIndex::City.root.compose(city))
|
78
|
+
.to eq('name' => 'London', 'rating' => 100)
|
79
|
+
end
|
80
|
+
specify do
|
81
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
82
|
+
.to eq('name' => 'London')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'root value provided' do
|
87
|
+
before do
|
88
|
+
stub_index(:places) do
|
89
|
+
define_type :city do
|
90
|
+
root value: ->(o) { {name: o.name + 'Modified', rating: o.rating.next} }
|
91
|
+
end
|
92
|
+
end
|
41
93
|
end
|
94
|
+
|
95
|
+
let(:city) { double(name: 'London', rating: 100) }
|
96
|
+
|
97
|
+
specify do
|
98
|
+
expect(PlacesIndex::City.root.compose(city))
|
99
|
+
.to eq('name' => 'LondonModified', 'rating' => 101)
|
100
|
+
end
|
101
|
+
|
102
|
+
specify do
|
103
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
104
|
+
.to eq('name' => 'LondonModified')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'complex evaluations' do
|
109
|
+
before do
|
110
|
+
stub_index(:places) do
|
111
|
+
define_type :city do
|
112
|
+
root value: ->(o) { {name: o.name + 'Modified', rating: o.rating.next} } do
|
113
|
+
field :name, value: ->(o) { o[:name] + 'Modified' }
|
114
|
+
field :rating
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:city) { double(name: 'London', rating: 100) }
|
121
|
+
|
122
|
+
specify do
|
123
|
+
expect(PlacesIndex::City.root.compose(city))
|
124
|
+
.to eq('name' => 'LondonModifiedModified', 'rating' => 101)
|
125
|
+
end
|
126
|
+
|
127
|
+
specify do
|
128
|
+
expect(PlacesIndex::City.root.compose(city, fields: %i[name borogoves]))
|
129
|
+
.to eq('name' => 'LondonModifiedModified')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#child_hash' do
|
135
|
+
before do
|
136
|
+
stub_index(:places) do
|
137
|
+
define_type :city do
|
138
|
+
field :name, :rating
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
specify do
|
144
|
+
expect(PlacesIndex::City.root.child_hash).to match(
|
145
|
+
name: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :name)),
|
146
|
+
rating: an_instance_of(Chewy::Fields::Base).and(have_attributes(name: :rating))
|
147
|
+
)
|
42
148
|
end
|
43
149
|
end
|
44
150
|
end
|
@@ -11,17 +11,18 @@ describe 'Time fields' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
before
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
before do
|
15
|
+
PostsIndex::Post.import(
|
16
|
+
double(published_at: ActiveSupport::TimeZone[-28_800].parse('2014/12/18 19:00')),
|
17
|
+
double(published_at: ActiveSupport::TimeZone[-21_600].parse('2014/12/18 20:00')),
|
18
|
+
double(published_at: ActiveSupport::TimeZone[-21_600].parse('2014/12/17 20:00'))
|
19
|
+
)
|
20
|
+
end
|
19
21
|
|
20
|
-
let(:time) { ActiveSupport::TimeZone[-
|
22
|
+
let(:time) { ActiveSupport::TimeZone[-14_400].parse('2014/12/18 22:00') }
|
21
23
|
let(:range) { (time - 1.minute)..(time + 1.minute) }
|
22
24
|
|
23
25
|
specify { expect(PostsIndex.total).to eq(3) }
|
24
|
-
specify { expect(PostsIndex.filter {
|
25
|
-
specify { expect(PostsIndex.filter {
|
26
|
-
specify { expect(PostsIndex.filter { published_at == o{[range.min..range.max]} }.count).to eq(1) }
|
26
|
+
specify { expect(PostsIndex.filter(range: {published_at: {gte: range.min, lte: range.max}}).size).to eq(1) }
|
27
|
+
specify { expect(PostsIndex.filter(range: {published_at: {gt: range.min.utc, lt: (range.max + 1.hour).utc}}).size).to eq(2) }
|
27
28
|
end
|
@@ -35,7 +35,7 @@ describe Chewy::Index::Actions do
|
|
35
35
|
|
36
36
|
context do
|
37
37
|
before { DummiesIndex.create '2014' }
|
38
|
-
specify { expect(DummiesIndex.indexes).to match_array([
|
38
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -55,11 +55,6 @@ describe Chewy::Index::Actions do
|
|
55
55
|
context do
|
56
56
|
before { DummiesIndex.create }
|
57
57
|
specify do
|
58
|
-
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
59
|
-
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies\] already exists\]/)
|
60
|
-
end
|
61
|
-
specify do
|
62
|
-
skip_on_version_lt('2.0', 'format of exception was changed')
|
63
58
|
expect { DummiesIndex.create! }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies/)
|
64
59
|
end
|
65
60
|
specify { expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/Invalid alias name \[dummies\]/) }
|
@@ -72,18 +67,13 @@ describe Chewy::Index::Actions do
|
|
72
67
|
specify { expect(DummiesIndex.aliases).to eq([]) }
|
73
68
|
specify { expect(DummiesIndex.indexes).to eq(['dummies_2013']) }
|
74
69
|
specify do
|
75
|
-
skip_on_version_gte('2.0', 'format of exception changed in 2.x')
|
76
|
-
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/\[\[dummies_2013\] already exists\]/)
|
77
|
-
end
|
78
|
-
specify do
|
79
|
-
skip_on_version_lt('2.0', 'format of exception was changed')
|
80
70
|
expect { DummiesIndex.create!('2013') }.to raise_error(Elasticsearch::Transport::Transport::Errors::BadRequest).with_message(/index_already_exists_exception.*dummies_2013/)
|
81
71
|
end
|
82
72
|
specify { expect(DummiesIndex.create!('2014')['acknowledged']).to eq(true) }
|
83
73
|
|
84
74
|
context do
|
85
75
|
before { DummiesIndex.create! '2014' }
|
86
|
-
specify { expect(DummiesIndex.indexes).to match_array([
|
76
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
87
77
|
end
|
88
78
|
end
|
89
79
|
|
@@ -287,7 +277,7 @@ describe Chewy::Index::Actions do
|
|
287
277
|
define_type City
|
288
278
|
end
|
289
279
|
end
|
290
|
-
let!(:dummy_cities) { 3
|
280
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
291
281
|
|
292
282
|
specify { expect(CitiesIndex.import).to eq(true) }
|
293
283
|
|
@@ -311,7 +301,7 @@ describe Chewy::Index::Actions do
|
|
311
301
|
define_type City
|
312
302
|
end
|
313
303
|
end
|
314
|
-
let!(:dummy_cities) { 3
|
304
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
315
305
|
|
316
306
|
specify { expect(CitiesIndex.import!).to eq(true) }
|
317
307
|
|
@@ -336,59 +326,254 @@ describe Chewy::Index::Actions do
|
|
336
326
|
end
|
337
327
|
end
|
338
328
|
|
339
|
-
before { City.create!(id: 1, name: 'Moscow') }
|
340
|
-
|
341
|
-
specify { expect(CitiesIndex.reset!).to eq(true) }
|
342
|
-
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
343
|
-
|
344
329
|
context do
|
345
|
-
before {
|
330
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
346
331
|
|
347
|
-
specify { expect(CitiesIndex.
|
348
|
-
specify { expect(CitiesIndex.
|
349
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
332
|
+
specify { expect(CitiesIndex.reset!).to eq(true) }
|
333
|
+
specify { expect(CitiesIndex.reset!('2013')).to eq(true) }
|
350
334
|
|
351
335
|
context do
|
352
|
-
before { CitiesIndex.reset!
|
336
|
+
before { CitiesIndex.reset! }
|
353
337
|
|
354
338
|
specify { expect(CitiesIndex.all).to have(1).item }
|
355
339
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
356
|
-
specify { expect(CitiesIndex.indexes).to eq([
|
340
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
341
|
+
|
342
|
+
context do
|
343
|
+
before { CitiesIndex.reset!('2013') }
|
344
|
+
|
345
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
346
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
347
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
348
|
+
end
|
349
|
+
|
350
|
+
context do
|
351
|
+
before { CitiesIndex.reset! }
|
352
|
+
|
353
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
354
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
355
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
356
|
+
end
|
357
357
|
end
|
358
358
|
|
359
359
|
context do
|
360
|
-
before { CitiesIndex.reset! }
|
360
|
+
before { CitiesIndex.reset!('2013') }
|
361
361
|
|
362
362
|
specify { expect(CitiesIndex.all).to have(1).item }
|
363
363
|
specify { expect(CitiesIndex.aliases).to eq([]) }
|
364
|
-
specify { expect(CitiesIndex.indexes).to eq([]) }
|
364
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2013']) }
|
365
|
+
|
366
|
+
context do
|
367
|
+
before { CitiesIndex.reset!('2014') }
|
368
|
+
|
369
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
370
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
371
|
+
specify { expect(CitiesIndex.indexes).to eq(['cities_2014']) }
|
372
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
373
|
+
end
|
374
|
+
|
375
|
+
context do
|
376
|
+
before { CitiesIndex.reset! }
|
377
|
+
|
378
|
+
specify { expect(CitiesIndex.all).to have(1).item }
|
379
|
+
specify { expect(CitiesIndex.aliases).to eq([]) }
|
380
|
+
specify { expect(CitiesIndex.indexes).to eq([]) }
|
381
|
+
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
382
|
+
end
|
365
383
|
end
|
366
384
|
end
|
367
385
|
|
368
|
-
context do
|
386
|
+
context 'reset_disable_refresh_interval' do
|
387
|
+
let(:suffix) { Time.now.to_i }
|
388
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
389
|
+
let(:before_import_body) do
|
390
|
+
{
|
391
|
+
index: {refresh_interval: -1}
|
392
|
+
}
|
393
|
+
end
|
394
|
+
let(:after_import_body) do
|
395
|
+
{
|
396
|
+
index: {refresh_interval: '1s'}
|
397
|
+
}
|
398
|
+
end
|
399
|
+
|
369
400
|
before { CitiesIndex.reset!('2013') }
|
401
|
+
before { allow(Chewy).to receive(:reset_disable_refresh_interval).and_return(reset_disable_refresh_interval) }
|
402
|
+
|
403
|
+
context 'activated' do
|
404
|
+
let(:reset_disable_refresh_interval) { true }
|
405
|
+
specify do
|
406
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
407
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
408
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
409
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
410
|
+
end
|
411
|
+
|
412
|
+
context 'refresh_interval already defined' do
|
413
|
+
before do
|
414
|
+
stub_index(:cities) do
|
415
|
+
settings index: {refresh_interval: '2s'}
|
416
|
+
define_type City
|
417
|
+
end
|
418
|
+
end
|
370
419
|
|
371
|
-
|
372
|
-
|
373
|
-
|
420
|
+
let(:after_import_body) do
|
421
|
+
{
|
422
|
+
index: {refresh_interval: '2s'}
|
423
|
+
}
|
424
|
+
end
|
374
425
|
|
375
|
-
|
376
|
-
|
426
|
+
specify do
|
427
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
428
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
429
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: false).and_call_original
|
430
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
431
|
+
end
|
377
432
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
433
|
+
specify 'uses empty index settings if not defined' do
|
434
|
+
allow(Chewy).to receive(:wait_for_status).and_return(nil)
|
435
|
+
allow(CitiesIndex).to receive(:settings_hash).and_return({})
|
436
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
437
|
+
end
|
438
|
+
end
|
382
439
|
end
|
383
440
|
|
384
|
-
context do
|
385
|
-
|
441
|
+
context 'not activated' do
|
442
|
+
let(:reset_disable_refresh_interval) { false }
|
443
|
+
specify do
|
444
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
445
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
446
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
386
450
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
451
|
+
context 'reset_no_replicas' do
|
452
|
+
let(:suffix) { Time.now.to_i }
|
453
|
+
let(:name) { CitiesIndex.index_name(suffix: suffix) }
|
454
|
+
let(:before_import_body) do
|
455
|
+
{
|
456
|
+
index: {number_of_replicas: 0}
|
457
|
+
}
|
458
|
+
end
|
459
|
+
let(:after_import_body) do
|
460
|
+
{
|
461
|
+
index: {number_of_replicas: 0}
|
462
|
+
}
|
463
|
+
end
|
464
|
+
|
465
|
+
before { allow(Chewy).to receive(:reset_no_replicas).and_return(reset_no_replicas) }
|
466
|
+
|
467
|
+
context 'activated' do
|
468
|
+
let(:reset_no_replicas) { true }
|
469
|
+
specify do
|
470
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: before_import_body).once
|
471
|
+
expect(CitiesIndex.client.indices).to receive(:put_settings).with(index: name, body: after_import_body).once
|
472
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
473
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context 'not activated' do
|
478
|
+
let(:reset_no_replicas) { false }
|
479
|
+
specify do
|
480
|
+
expect(CitiesIndex.client.indices).not_to receive(:put_settings)
|
481
|
+
expect(CitiesIndex).to receive(:import).with(suffix: suffix, journal: false, refresh: true).and_call_original
|
482
|
+
expect(CitiesIndex.reset!(suffix)).to eq(true)
|
483
|
+
end
|
391
484
|
end
|
392
485
|
end
|
486
|
+
|
487
|
+
xcontext 'applying journal' do
|
488
|
+
before do
|
489
|
+
stub_index(:cities) do
|
490
|
+
define_type City do
|
491
|
+
field :name, value: (lambda do
|
492
|
+
sleep(rating)
|
493
|
+
name
|
494
|
+
end)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
let!(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "Name#{i + 1}", rating: 1) } }
|
500
|
+
|
501
|
+
let(:parallel_update) do
|
502
|
+
Thread.new do
|
503
|
+
p 'start parallel'
|
504
|
+
sleep(1.5)
|
505
|
+
cities.first.update(name: 'NewName1', rating: 0)
|
506
|
+
cities.last.update(name: 'NewName3', rating: 0)
|
507
|
+
CitiesIndex::City.import!([cities.first, cities.last], journal: true)
|
508
|
+
p 'end parallel'
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
specify 'with journal application' do
|
513
|
+
cities
|
514
|
+
p 'cities created1'
|
515
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
516
|
+
[
|
517
|
+
parallel_update,
|
518
|
+
Thread.new do
|
519
|
+
p 'start reset1'
|
520
|
+
CitiesIndex.reset!('suffix')
|
521
|
+
p 'end reset1'
|
522
|
+
end
|
523
|
+
].map(&:join)
|
524
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
525
|
+
p 'expect1'
|
526
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
|
527
|
+
p 'end expect1'
|
528
|
+
end
|
529
|
+
|
530
|
+
specify 'without journal application' do
|
531
|
+
cities
|
532
|
+
p 'cities created2'
|
533
|
+
::ActiveRecord::Base.connection.close if defined?(::ActiveRecord::Base)
|
534
|
+
[
|
535
|
+
parallel_update,
|
536
|
+
Thread.new do
|
537
|
+
p 'start reset2'
|
538
|
+
CitiesIndex.reset!('suffix', apply_journal: false)
|
539
|
+
p 'end reset2'
|
540
|
+
end
|
541
|
+
].map(&:join)
|
542
|
+
::ActiveRecord::Base.connection.reconnect! if defined?(::ActiveRecord::Base)
|
543
|
+
p 'expect2'
|
544
|
+
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
|
545
|
+
p 'end expect2'
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
context 'journaling' do
|
550
|
+
before { City.create!(id: 1, name: 'Moscow') }
|
551
|
+
|
552
|
+
specify do
|
553
|
+
CitiesIndex.reset!
|
554
|
+
expect(Chewy::Stash::Journal.count).to eq(0)
|
555
|
+
end
|
556
|
+
|
557
|
+
specify do
|
558
|
+
CitiesIndex.reset! journal: true
|
559
|
+
expect(Chewy::Stash::Journal.count).to be > 0
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
context 'other options' do
|
564
|
+
specify do
|
565
|
+
expect(CitiesIndex::City).to receive(:import).with(parallel: true, journal: false).once.and_return(true)
|
566
|
+
expect(CitiesIndex.reset!(parallel: true)).to eq(true)
|
567
|
+
end
|
568
|
+
|
569
|
+
specify do
|
570
|
+
expect(CitiesIndex::City).to receive(:import).with(suffix: 'suffix', parallel: true, journal: false, refresh: true).once.and_return(true)
|
571
|
+
expect(CitiesIndex.reset!('suffix', parallel: true)).to eq(true)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
describe '.journal' do
|
577
|
+
specify { expect(DummiesIndex.journal).to be_a(Chewy::Journal) }
|
393
578
|
end
|
394
579
|
end
|
@@ -22,7 +22,7 @@ describe Chewy::Index::Aliases do
|
|
22
22
|
context do
|
23
23
|
before { DummiesIndex.create! '2013' }
|
24
24
|
before { DummiesIndex.create! '2014' }
|
25
|
-
specify { expect(DummiesIndex.indexes).to match_array([
|
25
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w[dummies_2013 dummies_2014]) }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -38,7 +38,7 @@ describe Chewy::Index::Aliases do
|
|
38
38
|
before { DummiesIndex.create! }
|
39
39
|
before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2013' }
|
40
40
|
before { Chewy.client.indices.put_alias index: 'dummies', name: 'dummies_2014' }
|
41
|
-
specify { expect(DummiesIndex.aliases).to match_array([
|
41
|
+
specify { expect(DummiesIndex.aliases).to match_array(%w[dummies_2013 dummies_2014]) }
|
42
42
|
end
|
43
43
|
|
44
44
|
context do
|