chewy 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +8 -0
- data/README.md +3 -3
- data/lib/chewy/config.rb +5 -5
- data/lib/chewy/fields/base.rb +1 -1
- data/lib/chewy/index.rb +2 -2
- data/lib/chewy/index/settings.rb +7 -4
- data/lib/chewy/query.rb +1 -1
- data/lib/chewy/query/criteria.rb +1 -1
- data/lib/chewy/version.rb +1 -1
- data/spec/chewy/config_spec.rb +2 -2
- data/spec/chewy/fields/base_spec.rb +12 -0
- data/spec/chewy/index/actions_spec.rb +1 -1
- data/spec/chewy/index/aliases_spec.rb +1 -1
- data/spec/chewy/index/settings_spec.rb +14 -0
- data/spec/chewy/index_spec.rb +5 -1
- data/spec/chewy/query/criteria_spec.rb +1 -1
- data/spec/chewy/query/loading_spec.rb +2 -5
- data/spec/chewy/query/pagination_spec.rb +2 -2
- data/spec/chewy/query_spec.rb +9 -11
- data/spec/chewy/rspec/update_index_spec.rb +1 -1
- data/spec/chewy/type/import_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20296cb15e845cc45aacb4dddaebaa735b5f9d80
|
4
|
+
data.tar.gz: 2872561f5db73ad60dc96ef445de9bdd2da529db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 487d34a9309473ae01af8e2f4f2fe4a4318501c83e6370121e97acaa736630ea2b8bfb129b499dc74a01f7899fd131f296ffa372ddfa6eba324a392cd79d6e34
|
7
|
+
data.tar.gz: 6387d3bcd0e6e1f48187a0bbcc00cfaaffb0069673e149cdf32b531f979843c3b47c3572e5fde6c5717bb21446cd2138deb703ae705969bad6568ff9efaeddea
|
data/.travis.yml
CHANGED
@@ -5,6 +5,6 @@ rvm:
|
|
5
5
|
- 2.1.0
|
6
6
|
# - rbx
|
7
7
|
before_install:
|
8
|
-
- curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.
|
8
|
+
- curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz | tar xz -C /tmp
|
9
9
|
before_script:
|
10
|
-
- TEST_CLUSTER_COMMAND="/tmp/elasticsearch-0.
|
10
|
+
- TEST_CLUSTER_COMMAND="/tmp/elasticsearch-1.0.1/bin/elasticsearch" rake elasticsearch:start
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# Version 0.3.0
|
4
|
+
|
5
|
+
* Added `Chewy.configuration[:index]` config to setup common indexes options.
|
6
|
+
|
7
|
+
* `Chewy.client_options` replaced with `Chewy.configuration`
|
8
|
+
|
9
|
+
* Using source filtering instead of fields filter (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-source-filtering.html).
|
10
|
+
|
3
11
|
# Version 0.2.3
|
4
12
|
|
5
13
|
* `.import!` indexes method, raises import errors.
|
data/README.md
CHANGED
@@ -41,11 +41,11 @@ Or install it yourself as:
|
|
41
41
|
|
42
42
|
### Client configuration
|
43
43
|
|
44
|
-
There are 2 ways to configure Chewy client: `Chewy.
|
44
|
+
There are 2 ways to configure Chewy client: `Chewy.configuration` hash and `chewy.yml`
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
# config/initializers/chewy.rb
|
48
|
-
Chewy.
|
48
|
+
Chewy.configuration = {host: 'localhost:9250'} # do not use environments
|
49
49
|
```
|
50
50
|
|
51
51
|
```yaml
|
@@ -61,7 +61,7 @@ development:
|
|
61
61
|
The result config merges both hashes. Client options are passed as is to Elasticsearch::Transport::Client except the `:prefix` - it is used internally by chewy to create prefixed index names:
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
Chewy.
|
64
|
+
Chewy.configuration = {prefix: 'testing'}
|
65
65
|
UsersIndex.index_name # => 'testing_users'
|
66
66
|
```
|
67
67
|
|
data/lib/chewy/config.rb
CHANGED
@@ -3,7 +3,7 @@ module Chewy
|
|
3
3
|
include Singleton
|
4
4
|
|
5
5
|
attr_reader :analyzers, :tokenizers, :filters, :char_filters
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :configuration, :urgent_update, :query_mode, :filter_mode, :logger
|
7
7
|
|
8
8
|
def self.delegated
|
9
9
|
public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
|
@@ -21,7 +21,7 @@ module Chewy
|
|
21
21
|
|
22
22
|
def initialize
|
23
23
|
@urgent_update = false
|
24
|
-
@
|
24
|
+
@configuration = {}
|
25
25
|
@query_mode = :must
|
26
26
|
@filter_mode = :and
|
27
27
|
@analyzers = {}
|
@@ -63,8 +63,8 @@ module Chewy
|
|
63
63
|
#
|
64
64
|
repository :char_filter
|
65
65
|
|
66
|
-
def
|
67
|
-
options = @
|
66
|
+
def configuration
|
67
|
+
options = @configuration.deep_symbolize_keys.merge(yaml_options)
|
68
68
|
options.merge!(logger: logger) if logger
|
69
69
|
options
|
70
70
|
end
|
@@ -74,7 +74,7 @@ module Chewy
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def client
|
77
|
-
Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new
|
77
|
+
Thread.current[:chewy_client] ||= ::Elasticsearch::Client.new configuration
|
78
78
|
end
|
79
79
|
|
80
80
|
def atomic?
|
data/lib/chewy/fields/base.rb
CHANGED
data/lib/chewy/index.rb
CHANGED
@@ -30,12 +30,12 @@ module Chewy
|
|
30
30
|
#
|
31
31
|
def self.index_name(suggest = nil)
|
32
32
|
if suggest
|
33
|
-
@index_name = build_index_name(suggest, prefix: Chewy.
|
33
|
+
@index_name = build_index_name(suggest, prefix: Chewy.configuration[:prefix])
|
34
34
|
else
|
35
35
|
@index_name ||= begin
|
36
36
|
build_index_name(
|
37
37
|
name.gsub(/Index\Z/, '').demodulize.underscore,
|
38
|
-
prefix: Chewy.
|
38
|
+
prefix: Chewy.configuration[:prefix]
|
39
39
|
) if name
|
40
40
|
end
|
41
41
|
end
|
data/lib/chewy/index/settings.rb
CHANGED
@@ -29,12 +29,15 @@ module Chewy
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def to_hash
|
32
|
-
|
32
|
+
settings = @params.deep_symbolize_keys
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
settings[:analysis] = resolve_analysis(settings[:analysis]) if settings[:analysis]
|
35
|
+
if settings[:index] || Chewy.configuration[:index]
|
36
|
+
settings[:index] = (Chewy.configuration[:index] || {})
|
37
|
+
.deep_merge((settings[:index] || {}).deep_symbolize_keys)
|
38
|
+
end
|
36
39
|
|
37
|
-
{settings:
|
40
|
+
settings.present? ? {settings: settings} : {}
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
data/lib/chewy/query.rb
CHANGED
@@ -463,7 +463,7 @@ module Chewy
|
|
463
463
|
|
464
464
|
def _results
|
465
465
|
@_results ||= (criteria.none? ? [] : _response['hits']['hits']).map do |hit|
|
466
|
-
attributes = hit['_source'] ||
|
466
|
+
attributes = hit['_source'] || {}
|
467
467
|
attributes.reverse_merge!(id: hit['_id'])
|
468
468
|
.merge!(_score: hit['_score'], _explanation: hit['_explanation'])
|
469
469
|
index.type_hash[hit['_type']].new attributes
|
data/lib/chewy/query/criteria.rb
CHANGED
@@ -82,7 +82,7 @@ module Chewy
|
|
82
82
|
body = (_composed_query(_request_query, _request_filter) || {}).tap do |body|
|
83
83
|
body.merge!(facets: facets) if facets?
|
84
84
|
body.merge!(sort: sort) if sort?
|
85
|
-
body.merge!(
|
85
|
+
body.merge!(_source: fields) if fields?
|
86
86
|
end
|
87
87
|
|
88
88
|
{body: body.merge!(_request_options)}
|
data/lib/chewy/version.rb
CHANGED
data/spec/chewy/config_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Chewy::Config do
|
|
7
7
|
its(:query_mode) { should == :must }
|
8
8
|
its(:filter_mode) { should == :and }
|
9
9
|
its(:logger) { should be_nil }
|
10
|
-
its(:
|
10
|
+
its(:configuration) { should_not have_key :logger }
|
11
11
|
its(:analyzers) { should == {} }
|
12
12
|
its(:tokenizers) { should == {} }
|
13
13
|
its(:filters) { should == {} }
|
@@ -57,7 +57,7 @@ describe Chewy::Config do
|
|
57
57
|
before { subject.logger = double(:logger) }
|
58
58
|
|
59
59
|
its(:logger) { should_not be_nil }
|
60
|
-
its(:
|
60
|
+
its(:configuration) { should have_key :logger }
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#atomic?' do
|
@@ -39,6 +39,18 @@ describe Chewy::Fields::Base do
|
|
39
39
|
|
40
40
|
specify { field.compose(double(name: 'Alex')).should == {name: 'Alex'} }
|
41
41
|
end
|
42
|
+
|
43
|
+
context do
|
44
|
+
let(:field) { described_class.new(:name, type: 'object') }
|
45
|
+
let(:object) { double(name: { key1: 'value1', key2: 'value2' }) }
|
46
|
+
|
47
|
+
before do
|
48
|
+
field.nested(described_class.new(:key1, value: ->(h){ h[:key1] }))
|
49
|
+
field.nested(described_class.new(:key2, value: ->(h){ h[:key2] }))
|
50
|
+
end
|
51
|
+
|
52
|
+
specify{ field.compose(object).should == { name: { 'key1' => 'value1', 'key2' => 'value2' } } }
|
53
|
+
end
|
42
54
|
end
|
43
55
|
|
44
56
|
describe '#nested' do
|
@@ -66,5 +66,19 @@ describe Chewy::Index::Settings do
|
|
66
66
|
tokenizer: {tokenizer1: {options: 43}}
|
67
67
|
}}} }
|
68
68
|
end
|
69
|
+
|
70
|
+
context ':index' do
|
71
|
+
specify { described_class.new(index: {number_of_shards: 3}).to_hash
|
72
|
+
.should == {settings: {index: {number_of_shards: 3}}} }
|
73
|
+
|
74
|
+
context do
|
75
|
+
before { Chewy.configuration = {index: {number_of_shards: 7, number_of_replicas: 2}} }
|
76
|
+
|
77
|
+
specify { described_class.new.to_hash
|
78
|
+
.should == {settings: {index: {number_of_shards: 7, number_of_replicas: 2}}} }
|
79
|
+
specify { described_class.new(index: {number_of_shards: 3}).to_hash
|
80
|
+
.should == {settings: {index: {number_of_shards: 3, number_of_replicas: 2}}} }
|
81
|
+
end
|
82
|
+
end
|
69
83
|
end
|
70
84
|
end
|
data/spec/chewy/index_spec.rb
CHANGED
@@ -83,7 +83,7 @@ describe Chewy::Index do
|
|
83
83
|
specify { stub_const('DevelopersIndex', Class.new(Chewy::Index)).index_name.should == 'developers' }
|
84
84
|
|
85
85
|
context do
|
86
|
-
before { Chewy.stub(
|
86
|
+
before { Chewy.stub(configuration: {prefix: 'testing'}) }
|
87
87
|
specify { DummiesIndex.index_name.should == 'testing_dummies' }
|
88
88
|
specify { stub_index(:dummies) { index_name :users }.index_name.should == 'testing_users' }
|
89
89
|
end
|
@@ -98,6 +98,8 @@ describe Chewy::Index do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
describe '.index_params' do
|
101
|
+
before { Chewy.stub(config: Chewy::Config.send(:new)) }
|
102
|
+
|
101
103
|
specify { stub_index(:documents).index_params.should == {} }
|
102
104
|
specify { stub_index(:documents) { settings number_of_shards: 1 }.index_params.keys.should == [:settings] }
|
103
105
|
specify { stub_index(:documents) do
|
@@ -114,6 +116,8 @@ describe Chewy::Index do
|
|
114
116
|
end
|
115
117
|
|
116
118
|
describe '.settings_hash' do
|
119
|
+
before { Chewy.stub(config: Chewy::Config.send(:new)) }
|
120
|
+
|
117
121
|
specify { stub_index(:documents).settings_hash.should == {} }
|
118
122
|
specify { stub_index(:documents) { settings number_of_shards: 1 }.settings_hash.should == {settings: {number_of_shards: 1}} }
|
119
123
|
end
|
@@ -144,7 +144,7 @@ describe Chewy::Query::Criteria do
|
|
144
144
|
specify { request_body { update_queries(:query) }.should == {body: {query: :query}} }
|
145
145
|
specify { request_body {
|
146
146
|
update_options(from: 10); update_sort(:field); update_fields(:field); update_queries(:query)
|
147
|
-
}.should == {body: {query: :query, from: 10, sort: [:field],
|
147
|
+
}.should == {body: {query: :query, from: 10, sort: [:field], _source: ['field']}} }
|
148
148
|
end
|
149
149
|
|
150
150
|
describe '#_composed_query' do
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Query::Loading do
|
4
4
|
include ClassHelpers
|
5
|
-
before { Chewy
|
5
|
+
before { Chewy.client.indices.delete index: '*' }
|
6
6
|
|
7
7
|
before do
|
8
8
|
stub_model(:city)
|
@@ -24,10 +24,7 @@ describe Chewy::Query::Loading do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
before
|
28
|
-
PlacesIndex::City.import(cities)
|
29
|
-
PlacesIndex::Country.import(countries)
|
30
|
-
end
|
27
|
+
before { PlacesIndex.import!(cities: cities, countries: countries) }
|
31
28
|
|
32
29
|
specify { PlacesIndex.order(:rating).limit(6).load.total_count.should == 12 }
|
33
30
|
specify { PlacesIndex.order(:rating).limit(6).load.should =~ cities.first(3) + countries.first(3) }
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Query::Pagination do
|
4
4
|
include ClassHelpers
|
5
|
-
before { Chewy
|
5
|
+
before { Chewy.client.indices.delete index: '*' }
|
6
6
|
|
7
7
|
before do
|
8
8
|
stub_index(:products) do
|
@@ -13,7 +13,7 @@ describe Chewy::Query::Pagination do
|
|
13
13
|
end
|
14
14
|
let(:data) { 10.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
15
15
|
|
16
|
-
before { ProductsIndex::Product.import(data.map { |h| double(h) }) }
|
16
|
+
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }
|
17
17
|
before { Kaminari.config.stub(default_per_page: 3) }
|
18
18
|
|
19
19
|
let(:search) { ProductsIndex.order(:age) }
|
data/spec/chewy/query_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Chewy::Query do
|
4
4
|
include ClassHelpers
|
5
|
+
before { Chewy.client.indices.delete index: '*' }
|
5
6
|
|
6
|
-
before { Chewy::Index.client.indices.delete }
|
7
7
|
before do
|
8
8
|
stub_index(:products) do
|
9
9
|
define_type :product do
|
@@ -20,9 +20,11 @@ describe Chewy::Query do
|
|
20
20
|
let(:products) { 3.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
21
21
|
let(:cities) { 3.times.map { |i| {id: i.next.to_s}.stringify_keys! } }
|
22
22
|
let(:countries) { 3.times.map { |i| {id: i.next.to_s}.stringify_keys! } }
|
23
|
-
before
|
24
|
-
|
25
|
-
|
23
|
+
before do
|
24
|
+
ProductsIndex::Product.import!(products.map { |h| double(h) })
|
25
|
+
ProductsIndex::City.import!(cities.map { |h| double(h) })
|
26
|
+
ProductsIndex::Country.import!(countries.map { |h| double(h) })
|
27
|
+
end
|
26
28
|
|
27
29
|
specify { subject.count.should == 9 }
|
28
30
|
specify { subject.limit(6).count.should == 6 }
|
@@ -35,7 +37,7 @@ describe Chewy::Query do
|
|
35
37
|
|
36
38
|
describe '#==' do
|
37
39
|
let(:data) { 3.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
|
38
|
-
before { ProductsIndex::Product.import(data.map { |h| double(h) }) }
|
40
|
+
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }
|
39
41
|
|
40
42
|
specify { subject.query(match: 'hello').should == subject.query(match: 'hello') }
|
41
43
|
specify { subject.query(match: 'hello').should_not == subject.query(match: 'world') }
|
@@ -194,7 +196,7 @@ describe Chewy::Query do
|
|
194
196
|
end.tap(&:create!)
|
195
197
|
end
|
196
198
|
|
197
|
-
before { CitiesIndex::City.import cities }
|
199
|
+
before { CitiesIndex::City.import! cities }
|
198
200
|
|
199
201
|
specify { CitiesIndex.order(:rating).first.should be_a CitiesIndex::City }
|
200
202
|
specify { CitiesIndex.order(:rating).first.name.should == 'name0' }
|
@@ -226,16 +228,12 @@ describe Chewy::Query do
|
|
226
228
|
end
|
227
229
|
end.tap(&:create!)
|
228
230
|
end
|
229
|
-
before { CitiesIndex::City.import cities }
|
231
|
+
before { CitiesIndex::City.import! cities }
|
230
232
|
|
231
233
|
specify { CitiesIndex.order(:rating).first.should be_a CitiesIndex::City }
|
232
234
|
specify { CitiesIndex.order(:rating).first.name.should be_nil }
|
233
235
|
specify { CitiesIndex.order(:rating).first.rating.should be_nil }
|
234
236
|
specify { CitiesIndex.order(:rating).first.nested.should be_nil }
|
235
|
-
|
236
|
-
specify { CitiesIndex.order(:rating).only(:name).first.name.should be_nil }
|
237
|
-
specify { CitiesIndex.order(:rating).only(:name).first.rating.should be_nil }
|
238
|
-
specify { CitiesIndex.order(:rating).only(:nested).first.nested.should be_nil }
|
239
237
|
end
|
240
238
|
end
|
241
239
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -27,7 +27,7 @@ ActiveRecord::Schema.define do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
Chewy.
|
30
|
+
Chewy.configuration = {host: 'localhost:9250', index: {number_of_shards: 1, number_of_replicas: 0}}
|
31
31
|
|
32
32
|
RSpec.configure do |config|
|
33
33
|
config.mock_with :rspec
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chewy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|