chewy 0.8.4 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +34 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +20 -60
- data/Appraisals +15 -40
- data/CHANGELOG.md +42 -0
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/README.md +155 -6
- data/Rakefile +11 -1
- data/chewy.gemspec +5 -7
- data/gemfiles/rails.3.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.3.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.kaminari.gemfile +1 -0
- data/gemfiles/rails.4.2.activerecord.will_paginate.gemfile +1 -0
- data/gemfiles/{rails.4.2.mongoid.4.0.0.gemfile → rails.4.2.mongoid.4.0.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.kaminari.gemfile → rails.4.2.mongoid.4.0.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.4.0.0.will_paginate.gemfile → rails.4.2.mongoid.4.0.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.gemfile → rails.4.2.mongoid.5.1.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.kaminari.gemfile → rails.4.2.mongoid.5.1.kaminari.gemfile} +2 -1
- data/gemfiles/{rails.4.2.mongoid.5.1.0.will_paginate.gemfile → rails.4.2.mongoid.5.1.will_paginate.gemfile} +2 -1
- data/gemfiles/{rails.4.0.activerecord.gemfile → rails.5.0.activerecord.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.kaminari.gemfile → rails.5.0.activerecord.kaminari.gemfile} +4 -2
- data/gemfiles/{rails.4.0.mongoid.4.0.0.will_paginate.gemfile → rails.5.0.activerecord.will_paginate.gemfile} +4 -2
- data/gemfiles/{sequel.4.31.gemfile → sequel.4.38.gemfile} +3 -2
- data/lib/chewy.rb +24 -16
- data/lib/chewy/backports/deep_dup.rb +1 -1
- data/lib/chewy/backports/duplicable.rb +1 -0
- data/lib/chewy/config.rb +13 -7
- data/lib/chewy/errors.rb +4 -4
- data/lib/chewy/fields/base.rb +19 -14
- data/lib/chewy/fields/root.rb +11 -9
- data/lib/chewy/index.rb +38 -25
- data/lib/chewy/index/actions.rb +17 -17
- data/lib/chewy/index/settings.rb +3 -4
- data/lib/chewy/journal.rb +107 -0
- data/lib/chewy/journal/apply.rb +31 -0
- data/lib/chewy/journal/clean.rb +24 -0
- data/lib/chewy/journal/entry.rb +83 -0
- data/lib/chewy/journal/query.rb +87 -0
- data/lib/chewy/log_subscriber.rb +8 -8
- data/lib/chewy/minitest.rb +1 -0
- data/lib/chewy/minitest/helpers.rb +77 -0
- data/lib/chewy/minitest/search_index_receiver.rb +80 -0
- data/lib/chewy/query.rb +116 -60
- data/lib/chewy/query/compose.rb +5 -6
- data/lib/chewy/query/criteria.rb +26 -16
- data/lib/chewy/query/filters.rb +9 -9
- data/lib/chewy/query/loading.rb +2 -2
- data/lib/chewy/query/nodes/and.rb +3 -3
- 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 +6 -6
- data/lib/chewy/query/nodes/exists.rb +2 -2
- 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 +11 -13
- data/lib/chewy/query/nodes/match_all.rb +1 -1
- data/lib/chewy/query/nodes/missing.rb +2 -2
- data/lib/chewy/query/nodes/not.rb +3 -3
- data/lib/chewy/query/nodes/or.rb +3 -3
- data/lib/chewy/query/nodes/prefix.rb +4 -3
- data/lib/chewy/query/nodes/query.rb +3 -3
- data/lib/chewy/query/nodes/range.rb +11 -11
- data/lib/chewy/query/nodes/raw.rb +1 -1
- data/lib/chewy/query/nodes/regexp.rb +15 -11
- data/lib/chewy/query/nodes/script.rb +6 -6
- data/lib/chewy/query/pagination/will_paginate.rb +2 -2
- data/lib/chewy/railtie.rb +3 -3
- data/lib/chewy/rake_helper.rb +51 -30
- data/lib/chewy/repository.rb +2 -2
- data/lib/chewy/rspec.rb +1 -1
- data/lib/chewy/rspec/update_index.rb +46 -47
- data/lib/chewy/runtime/version.rb +4 -4
- data/lib/chewy/search.rb +7 -5
- data/lib/chewy/strategy.rb +10 -8
- data/lib/chewy/strategy/atomic.rb +2 -2
- data/lib/chewy/strategy/base.rb +4 -4
- data/lib/chewy/strategy/bypass.rb +1 -2
- data/lib/chewy/strategy/sidekiq.rb +2 -0
- data/lib/chewy/strategy/urgent.rb +1 -1
- data/lib/chewy/type.rb +51 -45
- data/lib/chewy/type/adapter/active_record.rb +23 -12
- data/lib/chewy/type/adapter/base.rb +4 -4
- data/lib/chewy/type/adapter/mongoid.rb +6 -6
- data/lib/chewy/type/adapter/object.rb +15 -12
- data/lib/chewy/type/adapter/orm.rb +24 -15
- data/lib/chewy/type/adapter/sequel.rb +11 -7
- data/lib/chewy/type/crutch.rb +4 -3
- data/lib/chewy/type/import.rb +51 -32
- data/lib/chewy/type/mapping.rb +17 -17
- data/lib/chewy/type/observe.rb +9 -7
- data/lib/chewy/type/witchcraft.rb +62 -23
- data/lib/chewy/type/wrapper.rb +20 -14
- data/lib/chewy/version.rb +1 -1
- data/lib/generators/chewy/install_generator.rb +3 -3
- data/lib/tasks/chewy.rake +28 -23
- data/spec/chewy/config_spec.rb +33 -12
- data/spec/chewy/fields/base_spec.rb +143 -154
- data/spec/chewy/fields/root_spec.rb +22 -20
- data/spec/chewy/fields/time_fields_spec.rb +11 -9
- data/spec/chewy/index/actions_spec.rb +27 -4
- data/spec/chewy/index/aliases_spec.rb +2 -2
- data/spec/chewy/index/settings_spec.rb +72 -50
- data/spec/chewy/index_spec.rb +95 -43
- data/spec/chewy/journal/apply_spec.rb +120 -0
- data/spec/chewy/journal/entry_spec.rb +237 -0
- data/spec/chewy/journal_spec.rb +173 -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 +504 -237
- data/spec/chewy/query/filters_spec.rb +94 -66
- data/spec/chewy/query/loading_spec.rb +76 -40
- 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 +3 -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 +2 -2
- data/spec/chewy/query/pagination/will_paginage_spec.rb +6 -7
- data/spec/chewy/query/pagination_spec.rb +2 -3
- data/spec/chewy/query_spec.rb +208 -145
- data/spec/chewy/repository_spec.rb +8 -8
- data/spec/chewy/rspec/update_index_spec.rb +180 -111
- data/spec/chewy/search_spec.rb +8 -8
- data/spec/chewy/strategy/active_job_spec.rb +2 -2
- data/spec/chewy/strategy/atomic_spec.rb +4 -1
- data/spec/chewy/strategy/resque_spec.rb +2 -2
- data/spec/chewy/strategy/sidekiq_spec.rb +2 -2
- data/spec/chewy/type/actions_spec.rb +1 -1
- data/spec/chewy/type/adapter/active_record_spec.rb +255 -149
- data/spec/chewy/type/adapter/mongoid_spec.rb +169 -108
- data/spec/chewy/type/adapter/object_spec.rb +56 -40
- data/spec/chewy/type/adapter/sequel_spec.rb +248 -163
- data/spec/chewy/type/import_spec.rb +78 -47
- data/spec/chewy/type/mapping_spec.rb +6 -6
- data/spec/chewy/type/observe_spec.rb +20 -14
- data/spec/chewy/type/witchcraft_spec.rb +89 -43
- data/spec/chewy/type_spec.rb +4 -3
- data/spec/chewy_spec.rb +10 -8
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_record.rb +1 -1
- data/spec/support/class_helpers.rb +10 -11
- data/spec/support/mongoid.rb +2 -2
- data/spec/support/sequel.rb +1 -1
- metadata +65 -35
- 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.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.0.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.0.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.gemfile +0 -15
- data/gemfiles/rails.4.1.activerecord.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.activerecord.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.4.0.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.4.0.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.gemfile +0 -15
- data/gemfiles/rails.4.1.mongoid.5.1.0.kaminari.gemfile +0 -14
- data/gemfiles/rails.4.1.mongoid.5.1.0.will_paginate.gemfile +0 -14
- data/gemfiles/rails.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
@@ -11,33 +11,35 @@ describe Chewy::Fields::Root do
|
|
11
11
|
field.dynamic_template 'hello', type: 'string'
|
12
12
|
field.dynamic_template 'hello*', :integer
|
13
13
|
field.dynamic_template 'hello.*'
|
14
|
-
field.dynamic_template
|
15
|
-
field.dynamic_template
|
16
|
-
field.dynamic_template template_42: {mapping: {}, match: ''}
|
17
|
-
field.dynamic_template
|
14
|
+
field.dynamic_template(/hello/)
|
15
|
+
field.dynamic_template(/hello.*/)
|
16
|
+
field.dynamic_template template_42: { mapping: {}, match: '' }
|
17
|
+
field.dynamic_template(/hello\..*/)
|
18
18
|
|
19
|
-
expect(field.mappings_hash).to eq(
|
20
|
-
{template_1: {mapping: {type: 'string'}, match: 'hello'}},
|
21
|
-
{template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}},
|
22
|
-
{template_3: {mapping: {}, path_match: 'hello.*'}},
|
23
|
-
{template_4: {mapping: {}, match: 'hello', match_pattern: 'regexp'}},
|
24
|
-
{template_5: {mapping: {}, match: 'hello.*', match_pattern: 'regexp'}},
|
25
|
-
{template_42: {mapping: {}, match: ''}},
|
26
|
-
{template_7: {mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp'}}
|
27
|
-
]}
|
19
|
+
expect(field.mappings_hash).to eq(product: { dynamic_templates: [
|
20
|
+
{ template_1: { mapping: { type: 'string' }, match: 'hello' } },
|
21
|
+
{ template_2: { mapping: {}, match_mapping_type: 'integer', match: 'hello*' } },
|
22
|
+
{ template_3: { mapping: {}, path_match: 'hello.*' } },
|
23
|
+
{ template_4: { mapping: {}, match: 'hello', match_pattern: 'regexp' } },
|
24
|
+
{ template_5: { mapping: {}, match: 'hello.*', match_pattern: 'regexp' } },
|
25
|
+
{ template_42: { mapping: {}, match: '' } },
|
26
|
+
{ template_7: { mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp' } }
|
27
|
+
] })
|
28
28
|
end
|
29
29
|
|
30
30
|
context do
|
31
|
-
subject(:field)
|
32
|
-
|
33
|
-
|
31
|
+
subject(:field) do
|
32
|
+
described_class.new('product', dynamic_templates: [
|
33
|
+
{ template_42: { mapping: {}, match: '' } }
|
34
|
+
])
|
35
|
+
end
|
34
36
|
|
35
37
|
specify do
|
36
38
|
field.dynamic_template 'hello', type: 'string'
|
37
|
-
expect(field.mappings_hash).to eq(
|
38
|
-
{template_42: {mapping: {}, match: ''}},
|
39
|
-
{template_1: {mapping: {type: 'string'}, match: 'hello'}}
|
40
|
-
]}
|
39
|
+
expect(field.mappings_hash).to eq(product: { dynamic_templates: [
|
40
|
+
{ template_42: { mapping: {}, match: '' } },
|
41
|
+
{ template_1: { mapping: { type: 'string' }, match: 'hello' } }
|
42
|
+
] })
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
@@ -11,17 +11,19 @@ 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 { published_at == o{range} }.count).to eq(1) }
|
25
|
-
specify { expect(PostsIndex.filter { published_at == o{range.min.utc..(range.max + 1.hour).utc} }.count).to eq(2) }
|
26
|
-
specify { expect(PostsIndex.filter { published_at == o{[range.min..range.max]} }.count).to eq(1) }
|
26
|
+
specify { expect(PostsIndex.filter { published_at == o { range } }.count).to eq(1) }
|
27
|
+
specify { expect(PostsIndex.filter { published_at == o { range.min.utc..(range.max + 1.hour).utc } }.count).to eq(2) }
|
28
|
+
specify { expect(PostsIndex.filter { published_at == o { [range.min..range.max] } }.count).to eq(1) }
|
27
29
|
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
|
|
@@ -83,7 +83,7 @@ describe Chewy::Index::Actions do
|
|
83
83
|
|
84
84
|
context do
|
85
85
|
before { DummiesIndex.create! '2014' }
|
86
|
-
specify { expect(DummiesIndex.indexes).to match_array(
|
86
|
+
specify { expect(DummiesIndex.indexes).to match_array(%w(dummies_2013 dummies_2014)) }
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -287,7 +287,7 @@ describe Chewy::Index::Actions do
|
|
287
287
|
define_type City
|
288
288
|
end
|
289
289
|
end
|
290
|
-
let!(:dummy_cities) { 3
|
290
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
291
291
|
|
292
292
|
specify { expect(CitiesIndex.import).to eq(true) }
|
293
293
|
|
@@ -311,7 +311,7 @@ describe Chewy::Index::Actions do
|
|
311
311
|
define_type City
|
312
312
|
end
|
313
313
|
end
|
314
|
-
let!(:dummy_cities) { 3
|
314
|
+
let!(:dummy_cities) { Array.new(3) { |i| City.create(id: i + 1, name: "name#{i}") } }
|
315
315
|
|
316
316
|
specify { expect(CitiesIndex.import!).to eq(true) }
|
317
317
|
|
@@ -390,5 +390,28 @@ describe Chewy::Index::Actions do
|
|
390
390
|
specify { expect(Chewy.client.indices.exists(index: 'cities_2013')).to eq(false) }
|
391
391
|
end
|
392
392
|
end
|
393
|
+
|
394
|
+
context 'journaling' do
|
395
|
+
before do
|
396
|
+
begin
|
397
|
+
Chewy.client.indices.delete(index: Chewy::Journal.index_name)
|
398
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
399
|
+
nil
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
specify do
|
404
|
+
CitiesIndex.reset!
|
405
|
+
|
406
|
+
expect(Chewy.client.indices.exists?(index: Chewy::Journal.index_name)).to eq false
|
407
|
+
end
|
408
|
+
|
409
|
+
specify do
|
410
|
+
CitiesIndex.reset! journal: true
|
411
|
+
|
412
|
+
expect(Chewy.client.indices.exists?(index: Chewy::Journal.index_name)).to eq true
|
413
|
+
expect(Chewy.client.count(index: Chewy::Journal.index_name)['count']).not_to eq 0
|
414
|
+
end
|
415
|
+
end
|
393
416
|
end
|
394
417
|
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
|
@@ -6,77 +6,99 @@ describe Chewy::Index::Settings do
|
|
6
6
|
before { allow(Chewy).to receive_messages(repository: Chewy::Repository.send(:new)) }
|
7
7
|
|
8
8
|
specify { expect(described_class.new.to_hash).to eq({}) }
|
9
|
-
specify { expect(described_class.new(number_of_nodes: 3).to_hash).to eq(
|
10
|
-
specify
|
11
|
-
.
|
12
|
-
|
13
|
-
|
14
|
-
specify
|
15
|
-
.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
.
|
20
|
-
|
21
|
-
|
22
|
-
specify
|
23
|
-
.
|
9
|
+
specify { expect(described_class.new(number_of_nodes: 3).to_hash).to eq(settings: { number_of_nodes: 3 }) }
|
10
|
+
specify do
|
11
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {}).to_hash)
|
12
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {} })
|
13
|
+
end
|
14
|
+
specify do
|
15
|
+
expect(described_class.new(number_of_nodes: 3, analysis: { filter: { filter1: {} } }).to_hash)
|
16
|
+
.to eq(settings: { number_of_nodes: 3, analysis: { filter: { filter1: {} } } })
|
17
|
+
end
|
18
|
+
specify do
|
19
|
+
expect(described_class.new(number_of_nodes: 3, analysis: { analyzer: { analyzer1: {} } }).to_hash)
|
20
|
+
.to eq(settings: { number_of_nodes: 3, analysis: { analyzer: { analyzer1: {} } } })
|
21
|
+
end
|
22
|
+
specify do
|
23
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {
|
24
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } }
|
25
|
+
}).to_hash)
|
26
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {
|
27
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } }
|
28
|
+
} })
|
29
|
+
end
|
30
|
+
specify do
|
31
|
+
expect(described_class.new(number_of_nodes: 3, analysis: { analyser: ['analyzer1'] }).to_hash)
|
32
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {} })
|
33
|
+
end
|
24
34
|
|
25
35
|
context do
|
26
|
-
before { Chewy.tokenizer :tokenizer1,
|
36
|
+
before { Chewy.tokenizer :tokenizer1, options: 42 }
|
27
37
|
|
28
|
-
specify
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
specify do
|
39
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {
|
40
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } }
|
41
|
+
}).to_hash)
|
42
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {
|
43
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } },
|
44
|
+
tokenizer: { tokenizer1: { options: 42 } }
|
45
|
+
} })
|
46
|
+
end
|
35
47
|
end
|
36
48
|
|
37
49
|
context do
|
38
50
|
before do
|
39
|
-
Chewy.filter :filter2,
|
40
|
-
Chewy.filter :filter3,
|
41
|
-
Chewy.filter :filter5,
|
51
|
+
Chewy.filter :filter2, options: 42
|
52
|
+
Chewy.filter :filter3, options: 43
|
53
|
+
Chewy.filter :filter5, options: 44
|
42
54
|
end
|
43
55
|
|
44
|
-
specify
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
specify do
|
57
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {
|
58
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } },
|
59
|
+
filter: ['filter3', { filter4: { options: 45 } }]
|
60
|
+
}).to_hash)
|
61
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {
|
62
|
+
analyzer: { analyzer1: { tokenizer: 'tokenizer1', filter: %w(filter1 filter2) } },
|
63
|
+
filter: { filter2: { options: 42 }, filter3: { options: 43 }, filter4: { options: 45 } }
|
64
|
+
} })
|
65
|
+
end
|
52
66
|
end
|
53
67
|
|
54
68
|
context do
|
55
69
|
before do
|
56
|
-
Chewy.analyzer :analyzer1,
|
57
|
-
Chewy.tokenizer :tokenizer1,
|
70
|
+
Chewy.analyzer :analyzer1, options: 42, tokenizer: 'tokenizer1'
|
71
|
+
Chewy.tokenizer :tokenizer1, options: 43
|
58
72
|
end
|
59
73
|
|
60
|
-
specify
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
74
|
+
specify do
|
75
|
+
expect(described_class.new(number_of_nodes: 3, analysis: {
|
76
|
+
analyzer: ['analyzer1', { analyzer2: { options: 44 } }]
|
77
|
+
}).to_hash)
|
78
|
+
.to eq(settings: { number_of_nodes: 3, analysis: {
|
79
|
+
analyzer: { analyzer1: { options: 42, tokenizer: 'tokenizer1' }, analyzer2: { options: 44 } },
|
80
|
+
tokenizer: { tokenizer1: { options: 43 } }
|
81
|
+
} })
|
82
|
+
end
|
67
83
|
end
|
68
84
|
|
69
85
|
context ':index' do
|
70
|
-
specify
|
71
|
-
.
|
86
|
+
specify do
|
87
|
+
expect(described_class.new(index: { number_of_shards: 3 }).to_hash)
|
88
|
+
.to eq(settings: { index: { number_of_shards: 3 } })
|
89
|
+
end
|
72
90
|
|
73
91
|
context do
|
74
|
-
before { allow(Chewy).to receive_messages(configuration: {index: {number_of_shards: 7, number_of_replicas: 2}}) }
|
92
|
+
before { allow(Chewy).to receive_messages(configuration: { index: { number_of_shards: 7, number_of_replicas: 2 } }) }
|
75
93
|
|
76
|
-
specify
|
77
|
-
.
|
78
|
-
|
79
|
-
|
94
|
+
specify do
|
95
|
+
expect(described_class.new.to_hash)
|
96
|
+
.to eq(settings: { index: { number_of_shards: 7, number_of_replicas: 2 } })
|
97
|
+
end
|
98
|
+
specify do
|
99
|
+
expect(described_class.new(index: { number_of_shards: 3 }).to_hash)
|
100
|
+
.to eq(settings: { index: { number_of_shards: 3, number_of_replicas: 2 } })
|
101
|
+
end
|
80
102
|
end
|
81
103
|
end
|
82
104
|
end
|
data/spec/chewy/index_spec.rb
CHANGED
@@ -18,8 +18,8 @@ describe Chewy::Index do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
let!(:cities) { 2
|
22
|
-
let!(:countries) { 2
|
21
|
+
let!(:cities) { Array.new(2) { |i| City.create! id: i + 1 } }
|
22
|
+
let!(:countries) { Array.new(2) { |i| Country.create! id: i + 1 } }
|
23
23
|
|
24
24
|
specify do
|
25
25
|
expect { PlacesIndex.import }.to update_index(PlacesIndex::City).and_reindex(cities)
|
@@ -62,14 +62,14 @@ describe Chewy::Index do
|
|
62
62
|
specify { expect(stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name).to eq('developers') }
|
63
63
|
|
64
64
|
context do
|
65
|
-
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
|
65
|
+
before { allow(Chewy).to receive_messages(configuration: { prefix: 'testing' }) }
|
66
66
|
specify { expect(DummiesIndex.index_name).to eq('testing_dummies') }
|
67
67
|
specify { expect(stub_index(:dummies) { index_name :users }.index_name).to eq('testing_users') }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe '.default_prefix' do
|
72
|
-
before { allow(Chewy).to receive_messages(configuration: {prefix: 'testing'}) }
|
72
|
+
before { allow(Chewy).to receive_messages(configuration: { prefix: 'testing' }) }
|
73
73
|
specify { expect(Class.new(Chewy::Index).default_prefix).to eq('testing') }
|
74
74
|
end
|
75
75
|
|
@@ -92,29 +92,29 @@ describe Chewy::Index do
|
|
92
92
|
before { stub_class('City::District', City) }
|
93
93
|
|
94
94
|
specify do
|
95
|
-
expect
|
95
|
+
expect do
|
96
96
|
Kernel.eval <<-DUMMY_CITY_INDEX
|
97
97
|
class DummyCityIndex < Chewy::Index
|
98
98
|
define_type City
|
99
99
|
define_type City::District
|
100
100
|
end
|
101
101
|
DUMMY_CITY_INDEX
|
102
|
-
|
102
|
+
end.not_to raise_error
|
103
103
|
end
|
104
104
|
|
105
105
|
specify do
|
106
|
-
expect
|
106
|
+
expect do
|
107
107
|
Kernel.eval <<-DUMMY_CITY_INDEX
|
108
108
|
class DummyCityIndex2 < Chewy::Index
|
109
109
|
define_type City
|
110
110
|
define_type City::Nothing
|
111
111
|
end
|
112
112
|
DUMMY_CITY_INDEX
|
113
|
-
|
113
|
+
end.to raise_error(NameError)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
context 'type methods should be deprecated and can\'t redefine
|
117
|
+
context 'type methods should be deprecated and can\'t redefine existing ones' do
|
118
118
|
before do
|
119
119
|
stub_index(:places) do
|
120
120
|
def self.city
|
@@ -136,6 +136,11 @@ describe Chewy::Index do
|
|
136
136
|
specify { expect(DummiesIndex.type_hash['dummy'].type_name).to eq('dummy') }
|
137
137
|
end
|
138
138
|
|
139
|
+
describe '.type' do
|
140
|
+
specify { expect(DummiesIndex.type('dummy')).to eq(DummiesIndex::Dummy) }
|
141
|
+
specify { expect { DummiesIndex.type('not-the-dummy') }.to raise_error(Chewy::UndefinedType) }
|
142
|
+
end
|
143
|
+
|
139
144
|
specify { expect(DummiesIndex.type_names).to eq(DummiesIndex.type_hash.keys) }
|
140
145
|
|
141
146
|
describe '.types' do
|
@@ -148,24 +153,26 @@ describe Chewy::Index do
|
|
148
153
|
before do
|
149
154
|
allow(Chewy).to receive_messages(config: Chewy::Config.send(:new))
|
150
155
|
|
151
|
-
Chewy.analyzer :name, filter:
|
156
|
+
Chewy.analyzer :name, filter: %w(lowercase icu_folding names_nysiis)
|
152
157
|
Chewy.analyzer :phone, tokenizer: 'ngram', char_filter: ['phone']
|
153
158
|
Chewy.tokenizer :ngram, type: 'nGram', min_gram: 3, max_gram: 3
|
154
159
|
Chewy.char_filter :phone, type: 'pattern_replace', pattern: '[^\d]', replacement: ''
|
155
160
|
Chewy.filter :names_nysiis, type: 'phonetic', encoder: 'nysiis', replace: false
|
156
161
|
end
|
157
162
|
|
158
|
-
let(:documents) { stub_index(:documents) { settings analysis: {analyzer: [:name, :phone, {sorted: {option: :baz}}]} } }
|
163
|
+
let(:documents) { stub_index(:documents) { settings analysis: { analyzer: [:name, :phone, { sorted: { option: :baz } }] } } }
|
159
164
|
|
160
|
-
specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect)
|
161
|
-
specify
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
165
|
+
specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect) }
|
166
|
+
specify do
|
167
|
+
expect(documents.settings_hash).to eq(settings: { analysis: {
|
168
|
+
analyzer: { name: { filter: %w(lowercase icu_folding names_nysiis) },
|
169
|
+
phone: { tokenizer: 'ngram', char_filter: ['phone'] },
|
170
|
+
sorted: { option: :baz } },
|
171
|
+
tokenizer: { ngram: { type: 'nGram', min_gram: 3, max_gram: 3 } },
|
172
|
+
char_filter: { phone: { type: 'pattern_replace', pattern: '[^\d]', replacement: '' } },
|
173
|
+
filter: { names_nysiis: { type: 'phonetic', encoder: 'nysiis', replace: false } }
|
174
|
+
} })
|
175
|
+
end
|
169
176
|
end
|
170
177
|
|
171
178
|
describe '.scopes' do
|
@@ -200,25 +207,29 @@ describe Chewy::Index do
|
|
200
207
|
before { allow(Chewy).to receive_messages(config: Chewy::Config.send(:new)) }
|
201
208
|
|
202
209
|
specify { expect(stub_index(:documents).settings_hash).to eq({}) }
|
203
|
-
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.settings_hash).to eq(
|
210
|
+
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.settings_hash).to eq(settings: { number_of_shards: 1 }) }
|
204
211
|
end
|
205
212
|
|
206
213
|
describe '.mappings_hash' do
|
207
214
|
specify { expect(stub_index(:documents).mappings_hash).to eq({}) }
|
208
215
|
specify { expect(stub_index(:documents) { define_type :document }.mappings_hash).to eq({}) }
|
209
|
-
specify
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
216
|
+
specify do
|
217
|
+
expect(stub_index(:documents) do
|
218
|
+
define_type :document do
|
219
|
+
field :name, type: 'string'
|
220
|
+
end
|
221
|
+
end.mappings_hash).to eq(mappings: { document: { properties: { name: { type: 'string' } } } })
|
222
|
+
end
|
223
|
+
specify do
|
224
|
+
expect(stub_index(:documents) do
|
225
|
+
define_type :document do
|
226
|
+
field :name, type: 'string'
|
227
|
+
end
|
228
|
+
define_type :document2 do
|
229
|
+
field :name, type: 'string'
|
230
|
+
end
|
231
|
+
end.mappings_hash[:mappings].keys).to match_array([:document, :document2])
|
232
|
+
end
|
222
233
|
end
|
223
234
|
|
224
235
|
describe '.index_params' do
|
@@ -226,16 +237,57 @@ describe Chewy::Index do
|
|
226
237
|
|
227
238
|
specify { expect(stub_index(:documents).index_params).to eq({}) }
|
228
239
|
specify { expect(stub_index(:documents) { settings number_of_shards: 1 }.index_params.keys).to eq([:settings]) }
|
229
|
-
specify
|
230
|
-
|
231
|
-
|
240
|
+
specify do
|
241
|
+
expect(stub_index(:documents) do
|
242
|
+
define_type :document do
|
243
|
+
field :name, type: 'string'
|
244
|
+
end
|
245
|
+
end.index_params.keys).to eq([:mappings])
|
246
|
+
end
|
247
|
+
specify do
|
248
|
+
expect(stub_index(:documents) do
|
249
|
+
settings number_of_shards: 1
|
250
|
+
define_type :document do
|
251
|
+
field :name, type: 'string'
|
252
|
+
end
|
253
|
+
end.index_params.keys).to match_array([:mappings, :settings])
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '.journal?' do
|
258
|
+
specify { expect(stub_index(:documents).journal?).to eq false }
|
259
|
+
|
260
|
+
context do
|
261
|
+
before { allow(Chewy).to receive_messages(configuration: { journal: true }) }
|
262
|
+
specify { expect(stub_index(:documents).journal?).to eq false }
|
263
|
+
end
|
264
|
+
|
265
|
+
context do
|
266
|
+
let(:index) do
|
267
|
+
stub_index(:documents) do
|
268
|
+
define_type :document do
|
269
|
+
end
|
270
|
+
end
|
232
271
|
end
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
272
|
+
|
273
|
+
specify { expect(index.journal?).to eq false }
|
274
|
+
|
275
|
+
context do
|
276
|
+
before { allow(Chewy).to receive_messages(configuration: { journal: true }) }
|
277
|
+
specify { expect(index.journal?).to eq true }
|
238
278
|
end
|
239
|
-
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context do
|
282
|
+
let(:index) do
|
283
|
+
stub_index(:documents) do
|
284
|
+
define_type :document do
|
285
|
+
default_import_options journal: true
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
specify { expect(index.journal?).to eq true }
|
291
|
+
end
|
240
292
|
end
|
241
293
|
end
|