chewy 0.2.0 → 0.2.2
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/CHANGELOG.md +19 -0
- data/Guardfile +1 -1
- data/README.md +1 -1
- data/lib/chewy.rb +1 -12
- data/lib/chewy/config.rb +48 -0
- data/lib/chewy/errors.rb +13 -0
- data/lib/chewy/index.rb +7 -18
- data/lib/chewy/index/actions.rb +20 -2
- data/lib/chewy/index/search.rb +1 -1
- data/lib/chewy/index/settings.rb +77 -0
- data/lib/chewy/query.rb +15 -1
- data/lib/chewy/query/criteria.rb +4 -0
- data/lib/chewy/version.rb +1 -1
- data/spec/chewy/config_spec.rb +44 -0
- data/spec/chewy/index/settings_spec.rb +70 -0
- data/spec/chewy/index_spec.rb +24 -0
- data/spec/chewy/query/criteria_spec.rb +1 -0
- data/spec/chewy/query_spec.rb +14 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618e32a755ee2b5035e4640b4a7969e76492689f
|
4
|
+
data.tar.gz: 420d6db94ffd55a322246a27e3537467c334782d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9db80b8a18cfc60735822fcd5b9c6e761221a8c485e04fb23088c1cdf4f83f43090a7b211949656eb9c989cf0b3832852b87cde3aa8d888558db157a1e38edc6
|
7
|
+
data.tar.gz: be4cb7e42fd04ec7607d9ad9e12dc1cbd664fd004b046b2a756e584760c3a488bf296563ecad006288e45557027db1f2b588d27db45d721e2f70391e9b0ef988
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# Version 0.2.1
|
4
|
+
|
5
|
+
* Auto-resolved analyzers and analyzers repository:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Setting up analyzers repository:
|
9
|
+
Chewy.analyzer :title_analyzer, type: 'custom', filter: %w(lowercase icu_folding title_nysiis)
|
10
|
+
Chewy.filter :title_nysiis, type: 'phonetic', encoder: 'nysiis', replace: false
|
11
|
+
|
12
|
+
# Using analyzers from repository in index classes
|
13
|
+
class ProductsIndex < Chewy::Index
|
14
|
+
settings analysis: {analyzer: ['title_analyzer', {one_more_analyzer: {type: 'custom', tokenizer: 'lowercase'}}]}
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
`title_analyzer` here will be automatically resolved and passed to index mapping
|
19
|
+
|
20
|
+
# Version 0.2.0
|
21
|
+
|
3
22
|
* Reworked import error handling. Now all the import errors from ElasticSearch are handled properly, also import method returns true of false depending on the import process success.
|
4
23
|
|
5
24
|
* `Chewy::Index.import` now takes types hash as argument within options hash:
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -113,7 +113,7 @@ Chewy.logger = Logger.new
|
|
113
113
|
|
114
114
|
Mapping definitions - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping.html
|
115
115
|
|
116
|
-
4. Add some index- and type-related settings
|
116
|
+
4. Add some index- and type-related settings. Analyzers repositories might be used as well. See `Chewy::Index.settings` docs for details:
|
117
117
|
|
118
118
|
```ruby
|
119
119
|
class UsersIndex < Chewy::Index
|
data/lib/chewy.rb
CHANGED
@@ -6,6 +6,7 @@ require 'singleton'
|
|
6
6
|
require 'elasticsearch'
|
7
7
|
|
8
8
|
require 'chewy/version'
|
9
|
+
require 'chewy/errors'
|
9
10
|
require 'chewy/config'
|
10
11
|
require 'chewy/index'
|
11
12
|
require 'chewy/type'
|
@@ -21,18 +22,6 @@ ActiveSupport.on_load(:active_record) do
|
|
21
22
|
end
|
22
23
|
|
23
24
|
module Chewy
|
24
|
-
class Error < StandardError
|
25
|
-
end
|
26
|
-
|
27
|
-
class UndefinedIndex < Error
|
28
|
-
end
|
29
|
-
|
30
|
-
class UndefinedType < Error
|
31
|
-
end
|
32
|
-
|
33
|
-
class UnderivableType < Error
|
34
|
-
end
|
35
|
-
|
36
25
|
def self.derive_type name
|
37
26
|
return name if name.is_a?(Class) && name < Chewy::Type::Base
|
38
27
|
|
data/lib/chewy/config.rb
CHANGED
@@ -2,19 +2,67 @@ module Chewy
|
|
2
2
|
class Config
|
3
3
|
include Singleton
|
4
4
|
|
5
|
+
attr_reader :analyzers, :tokenizers, :filters, :char_filters
|
5
6
|
attr_accessor :client_options, :urgent_update, :query_mode, :filter_mode, :logger
|
6
7
|
|
7
8
|
def self.delegated
|
8
9
|
public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
|
9
10
|
end
|
10
11
|
|
12
|
+
def self.repository name
|
13
|
+
plural_name = name.to_s.pluralize
|
14
|
+
|
15
|
+
class_eval <<-EOS
|
16
|
+
def #{name}(name, options = nil)
|
17
|
+
options ? #{plural_name}[name.to_sym] = options : #{plural_name}[name.to_sym]
|
18
|
+
end
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
|
11
22
|
def initialize
|
12
23
|
@urgent_update = false
|
13
24
|
@client_options = {}
|
14
25
|
@query_mode = :must
|
15
26
|
@filter_mode = :and
|
27
|
+
@analyzers = {}
|
28
|
+
@tokenizers = {}
|
29
|
+
@filters = {}
|
30
|
+
@char_filters = {}
|
16
31
|
end
|
17
32
|
|
33
|
+
# Analysers repository:
|
34
|
+
#
|
35
|
+
# Chewy.analyzer :my_analyzer2, {
|
36
|
+
# type: custom,
|
37
|
+
# tokenizer: 'my_tokenizer1',
|
38
|
+
# filter : ['my_token_filter1', 'my_token_filter2']
|
39
|
+
# char_filter : ['my_html']
|
40
|
+
# }
|
41
|
+
# Chewy.analyzer(:my_analyzer2) # => {type: 'custom', tokenizer: ...}
|
42
|
+
#
|
43
|
+
repository :analyzer
|
44
|
+
|
45
|
+
# Tokenizers repository:
|
46
|
+
#
|
47
|
+
# Chewy.tokenizer :my_tokenizer1, {type: standard, max_token_length: 900}
|
48
|
+
# Chewy.tokenizer(:my_tokenizer1) # => {type: standard, max_token_length: 900}
|
49
|
+
#
|
50
|
+
repository :tokenizer
|
51
|
+
|
52
|
+
# Token filters repository:
|
53
|
+
#
|
54
|
+
# Chewy.filter :my_token_filter1, {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
|
55
|
+
# Chewy.filter(:my_token_filter1) # => {type: stop, stopwords: [stop1, stop2, stop3, stop4]}
|
56
|
+
#
|
57
|
+
repository :filter
|
58
|
+
|
59
|
+
# Char filters repository:
|
60
|
+
#
|
61
|
+
# Chewy.char_filter :my_html, {type: html_strip, escaped_tags: [xxx, yyy], read_ahead: 1024}
|
62
|
+
# Chewy.char_filter(:my_html) # => {type: html_strip, escaped_tags: [xxx, yyy], read_ahead: 1024}
|
63
|
+
#
|
64
|
+
repository :char_filter
|
65
|
+
|
18
66
|
def client_options
|
19
67
|
options = @client_options.merge(yaml_options)
|
20
68
|
options.merge!(logger: logger) if logger
|
data/lib/chewy/errors.rb
ADDED
data/lib/chewy/index.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'chewy/index/actions'
|
2
2
|
require 'chewy/index/aliases'
|
3
3
|
require 'chewy/index/search'
|
4
|
+
require 'chewy/index/settings'
|
4
5
|
|
5
6
|
module Chewy
|
6
7
|
class Index
|
@@ -14,7 +15,7 @@ module Chewy
|
|
14
15
|
self.type_hash = {}
|
15
16
|
|
16
17
|
class_attribute :_settings
|
17
|
-
self._settings =
|
18
|
+
self._settings = Chewy::Index::Settings.new
|
18
19
|
|
19
20
|
# Setups or returns ElasticSearch index name
|
20
21
|
#
|
@@ -129,23 +130,11 @@ module Chewy
|
|
129
130
|
# See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
130
131
|
# for more details
|
131
132
|
#
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
# Perform import operation for every defined type
|
133
|
+
# It is possible to store analyzers settings in Chewy repositories
|
134
|
+
# and link them form index class. See `Chewy::Index::Settings` for details.
|
137
135
|
#
|
138
|
-
|
139
|
-
|
140
|
-
# UsersIndex.import suffix: Time.now.to_i # imports data to index with specified suffix if such is exists
|
141
|
-
# UsersIndex.import batch_size: 300 # import batch size
|
142
|
-
#
|
143
|
-
def self.import options = {}
|
144
|
-
objects = options.extract!(*type_names.map(&:to_sym))
|
145
|
-
types.map do |type|
|
146
|
-
args = [objects[type.type_name.to_sym], options.dup].reject(&:blank?)
|
147
|
-
type.import *args
|
148
|
-
end.all?
|
136
|
+
def self.settings(params)
|
137
|
+
self._settings = Chewy::Index::Settings.new params
|
149
138
|
end
|
150
139
|
|
151
140
|
private
|
@@ -156,7 +145,7 @@ module Chewy
|
|
156
145
|
end
|
157
146
|
|
158
147
|
def self.settings_hash
|
159
|
-
_settings.
|
148
|
+
_settings.to_hash
|
160
149
|
end
|
161
150
|
|
162
151
|
def self.mappings_hash
|
data/lib/chewy/index/actions.rb
CHANGED
@@ -107,11 +107,29 @@ module Chewy
|
|
107
107
|
# UsersIndex.purge! '01-2014' # deletes `users` and `users_01-2014` indexes, creates `users_01-2014`
|
108
108
|
#
|
109
109
|
def purge! suffix = nil
|
110
|
-
|
111
|
-
|
110
|
+
begin
|
111
|
+
delete! if suffix.present? && exists?
|
112
|
+
delete! suffix
|
113
|
+
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
114
|
+
end
|
112
115
|
create! suffix
|
113
116
|
end
|
114
117
|
|
118
|
+
# Perform import operation for every defined type
|
119
|
+
#
|
120
|
+
# UsersIndex.import
|
121
|
+
# UsersIndex.import refresh: false # to disable index refreshing after import
|
122
|
+
# UsersIndex.import suffix: Time.now.to_i # imports data to index with specified suffix if such is exists
|
123
|
+
# UsersIndex.import batch_size: 300 # import batch size
|
124
|
+
#
|
125
|
+
def import options = {}
|
126
|
+
objects = options.extract!(*type_names.map(&:to_sym))
|
127
|
+
types.map do |type|
|
128
|
+
args = [objects[type.type_name.to_sym], options.dup].reject(&:blank?)
|
129
|
+
type.import *args
|
130
|
+
end.all?
|
131
|
+
end
|
132
|
+
|
115
133
|
# Deletes, creates and imports data to the index.
|
116
134
|
# Returns import result
|
117
135
|
#
|
data/lib/chewy/index/search.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Chewy
|
2
|
+
class Index
|
3
|
+
|
4
|
+
# Stores ElasticSearch index settings and resolves `analysis`
|
5
|
+
# hash. At first, you need to store sone analyzers or other
|
6
|
+
# analysis options to the corresponding repository:
|
7
|
+
#
|
8
|
+
# Chewy.analyzer :title_analyzer, type: 'custom', filter: %w(lowercase icu_folding title_nysiis)
|
9
|
+
# Chewy.filter :title_nysiis, type: 'phonetic', encoder: 'nysiis', replace: false
|
10
|
+
#
|
11
|
+
# `title_nysiis` filter here will be expanded automatically when
|
12
|
+
# `title_analyzer` analyser will be used in index settings:
|
13
|
+
#
|
14
|
+
# class ProductsIndex < Chewy::Index
|
15
|
+
# settings analysis: {
|
16
|
+
# analyzer: [
|
17
|
+
# 'title_analyzer',
|
18
|
+
# {one_more_analyzer: {type: 'custom', tokenizer: 'lowercase'}}
|
19
|
+
# ]
|
20
|
+
# }
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# Additional analysing options, which wasn't stored in repositories,
|
24
|
+
# might be used as well.
|
25
|
+
#
|
26
|
+
class Settings
|
27
|
+
def initialize(params = {})
|
28
|
+
@params = params
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_hash
|
32
|
+
return {} unless @params.present?
|
33
|
+
|
34
|
+
params = @params.deep_dup
|
35
|
+
params[:analysis] = resolve_analysis(params[:analysis]) if params[:analysis]
|
36
|
+
|
37
|
+
{settings: params}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def resolve_analysis(analysis)
|
43
|
+
analyzer = resolve(analysis[:analyzer], Chewy.analyzers)
|
44
|
+
|
45
|
+
options = [:tokenizer, :filter, :char_filter].each.with_object({}) do |type, result|
|
46
|
+
dependencies = collect_dependencies(type, analyzer)
|
47
|
+
resolved = resolve(dependencies.push(analysis[type]), Chewy.send(type.to_s.pluralize))
|
48
|
+
result.merge!(type => resolved) if resolved.present?
|
49
|
+
end
|
50
|
+
|
51
|
+
options.merge!(analyzer: analyzer) if analyzer.present?
|
52
|
+
options
|
53
|
+
end
|
54
|
+
|
55
|
+
def collect_dependencies(type, analyzer)
|
56
|
+
analyzer.map { |_, options| options[type] }.compact.flatten.uniq
|
57
|
+
end
|
58
|
+
|
59
|
+
def resolve(params, repository)
|
60
|
+
if params.is_a?(Array)
|
61
|
+
params.flatten.reject(&:blank?).each.with_object({}) do |name_or_hash, result|
|
62
|
+
options = if name_or_hash.is_a?(Hash)
|
63
|
+
name_or_hash
|
64
|
+
else
|
65
|
+
name_or_hash = name_or_hash.to_sym
|
66
|
+
resolved = repository[name_or_hash]
|
67
|
+
resolved ? {name_or_hash => resolved} : {}
|
68
|
+
end
|
69
|
+
result.merge!(options)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
params || {}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/chewy/query.rb
CHANGED
@@ -246,6 +246,20 @@ module Chewy
|
|
246
246
|
chain { criteria.update_facets params }
|
247
247
|
end
|
248
248
|
|
249
|
+
# Marks the criteria as having zero records. This scope always returns empty array
|
250
|
+
# without touching the elasticsearch server.
|
251
|
+
# All the chained calls of methods don't affect the result
|
252
|
+
#
|
253
|
+
# UsersIndex.none.to_a
|
254
|
+
# # => []
|
255
|
+
# UsersIndex.query(text: {name: 'Johny'}).none.to_a
|
256
|
+
# # => []
|
257
|
+
# UsersIndex.none.query(text: {name: 'Johny'}).to_a
|
258
|
+
# # => []
|
259
|
+
def none
|
260
|
+
chain { criteria.update_options none: true }
|
261
|
+
end
|
262
|
+
|
249
263
|
# Adds one or more query to the search request
|
250
264
|
# Internally queries are stored as an array
|
251
265
|
# While the full query compilation this array compiles
|
@@ -448,7 +462,7 @@ module Chewy
|
|
448
462
|
end
|
449
463
|
|
450
464
|
def _results
|
451
|
-
@_results ||= _response['hits']['hits'].map do |hit|
|
465
|
+
@_results ||= (criteria.none? ? [] : _response['hits']['hits']).map do |hit|
|
452
466
|
attributes = hit['_source'] || hit['fields'] || {}
|
453
467
|
attributes.reverse_merge!(id: hit['_id'])
|
454
468
|
.merge!(_score: hit['_score'], _explanation: hit['_explanation'])
|
data/lib/chewy/query/criteria.rb
CHANGED
data/lib/chewy/version.rb
CHANGED
data/spec/chewy/config_spec.rb
CHANGED
@@ -8,6 +8,50 @@ describe Chewy::Config do
|
|
8
8
|
its(:filter_mode) { should == :and }
|
9
9
|
its(:logger) { should be_nil }
|
10
10
|
its(:client_options) { should_not have_key :logger }
|
11
|
+
its(:analyzers) { should == {} }
|
12
|
+
its(:tokenizers) { should == {} }
|
13
|
+
its(:filters) { should == {} }
|
14
|
+
its(:char_filters) { should == {} }
|
15
|
+
|
16
|
+
describe '#analyzer' do
|
17
|
+
specify { subject.analyzer(:name).should be_nil }
|
18
|
+
|
19
|
+
context do
|
20
|
+
before { subject.analyzer(:name, option: :foo) }
|
21
|
+
specify { subject.analyzer(:name).should == {option: :foo} }
|
22
|
+
specify { subject.analyzers.should == {name: {option: :foo}} }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#tokenizer' do
|
27
|
+
specify { subject.tokenizer(:name).should be_nil }
|
28
|
+
|
29
|
+
context do
|
30
|
+
before { subject.tokenizer(:name, option: :foo) }
|
31
|
+
specify { subject.tokenizer(:name).should == {option: :foo} }
|
32
|
+
specify { subject.tokenizers.should == {name: {option: :foo}} }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#filter' do
|
37
|
+
specify { subject.filter(:name).should be_nil }
|
38
|
+
|
39
|
+
context do
|
40
|
+
before { subject.filter(:name, option: :foo) }
|
41
|
+
specify { subject.filter(:name).should == {option: :foo} }
|
42
|
+
specify { subject.filters.should == {name: {option: :foo}} }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#char_filter' do
|
47
|
+
specify { subject.char_filter(:name).should be_nil }
|
48
|
+
|
49
|
+
context do
|
50
|
+
before { subject.char_filter(:name, option: :foo) }
|
51
|
+
specify { subject.char_filter(:name).should == {option: :foo} }
|
52
|
+
specify { subject.char_filters.should == {name: {option: :foo}} }
|
53
|
+
end
|
54
|
+
end
|
11
55
|
|
12
56
|
describe '#logger' do
|
13
57
|
before { subject.logger = double(:logger) }
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chewy::Index::Settings do
|
4
|
+
include ClassHelpers
|
5
|
+
|
6
|
+
describe '#to_hash' do
|
7
|
+
before { Chewy.stub(config: Chewy::Config.send(:new)) }
|
8
|
+
|
9
|
+
specify { described_class.new.to_hash.should == {} }
|
10
|
+
specify { described_class.new(number_of_nodes: 3).to_hash.should == {settings: {number_of_nodes: 3}} }
|
11
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {}).to_hash
|
12
|
+
.should == {settings: {number_of_nodes: 3, analysis: {}}} }
|
13
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {filter: {filter1: {}}}).to_hash
|
14
|
+
.should == {settings: {number_of_nodes: 3, analysis: {filter: {filter1: {}}}}} }
|
15
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}).to_hash
|
16
|
+
.should == {settings: {number_of_nodes: 3, analysis: {analyzer: {analyzer1: {}}}}} }
|
17
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {
|
18
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
|
19
|
+
}).to_hash
|
20
|
+
.should == {settings: {number_of_nodes: 3, analysis: {
|
21
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
|
22
|
+
}}} }
|
23
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {analyser: ['analyzer1']}).to_hash
|
24
|
+
.should == {settings: {number_of_nodes: 3, analysis: {}}} }
|
25
|
+
|
26
|
+
context do
|
27
|
+
before { Chewy.tokenizer :tokenizer1, {options: 42} }
|
28
|
+
|
29
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {
|
30
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}}
|
31
|
+
}).to_hash
|
32
|
+
.should == {settings: {number_of_nodes: 3, analysis: {
|
33
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
|
34
|
+
tokenizer: {tokenizer1: {options: 42}}
|
35
|
+
}}} }
|
36
|
+
end
|
37
|
+
|
38
|
+
context do
|
39
|
+
before do
|
40
|
+
Chewy.filter :filter2, {options: 42}
|
41
|
+
Chewy.filter :filter3, {options: 43}
|
42
|
+
Chewy.filter :filter5, {options: 44}
|
43
|
+
end
|
44
|
+
|
45
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {
|
46
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
|
47
|
+
filter: ['filter3', {filter4: {options: 45}}]
|
48
|
+
}).to_hash
|
49
|
+
.should == {settings: {number_of_nodes: 3, analysis: {
|
50
|
+
analyzer: {analyzer1: {tokenizer: 'tokenizer1', filter: ['filter1', 'filter2']}},
|
51
|
+
filter: {filter2: {options: 42}, filter3: {options: 43}, filter4: {options: 45}}
|
52
|
+
}}} }
|
53
|
+
end
|
54
|
+
|
55
|
+
context do
|
56
|
+
before do
|
57
|
+
Chewy.analyzer :analyzer1, {options: 42, tokenizer: 'tokenizer1'}
|
58
|
+
Chewy.tokenizer :tokenizer1, {options: 43}
|
59
|
+
end
|
60
|
+
|
61
|
+
specify { described_class.new(number_of_nodes: 3, analysis: {
|
62
|
+
analyzer: ['analyzer1', {analyzer2: {options: 44}}]
|
63
|
+
}).to_hash
|
64
|
+
.should == {settings: {number_of_nodes: 3, analysis: {
|
65
|
+
analyzer: {analyzer1: {options: 42, tokenizer: 'tokenizer1'}, analyzer2: {options: 44}},
|
66
|
+
tokenizer: {tokenizer1: {options: 43}}
|
67
|
+
}}} }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/chewy/index_spec.rb
CHANGED
@@ -22,6 +22,30 @@ describe Chewy::Index do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '.settings' do
|
26
|
+
before do
|
27
|
+
Chewy.stub(config: Chewy::Config.send(:new))
|
28
|
+
|
29
|
+
Chewy.analyzer :name, filter: ['lowercase', 'icu_folding', 'names_nysiis']
|
30
|
+
Chewy.analyzer :phone, tokenizer: 'ngram', char_filter: ['phone']
|
31
|
+
Chewy.tokenizer :ngram, type: 'nGram', min_gram: 3, max_gram: 3
|
32
|
+
Chewy.char_filter :phone, type: 'pattern_replace', pattern: '[^\d]', replacement: ''
|
33
|
+
Chewy.filter :names_nysiis, type: 'phonetic', encoder: 'nysiis', replace: false
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:documents) { stub_index(:documents) { settings analysis: {analyzer: [:name, :phone, {sorted: {option: :baz}}]} } }
|
37
|
+
|
38
|
+
specify { expect { documents.settings_hash }.to_not change(documents._settings, :inspect) }
|
39
|
+
specify { documents.settings_hash.should == {settings: {analysis: {
|
40
|
+
analyzer: {name: {filter: ['lowercase', 'icu_folding', 'names_nysiis']},
|
41
|
+
phone: {tokenizer: 'ngram', char_filter: ['phone']},
|
42
|
+
sorted: {option: :baz}},
|
43
|
+
tokenizer: {ngram: {type: 'nGram', min_gram: 3, max_gram: 3}},
|
44
|
+
char_filter: {phone: {type: 'pattern_replace', pattern: '[^\d]', replacement: ''}},
|
45
|
+
filter: {names_nysiis: {type: 'phonetic', encoder: 'nysiis', replace: false}}
|
46
|
+
}}} }
|
47
|
+
end
|
48
|
+
|
25
49
|
describe '.define_type' do
|
26
50
|
specify { DummiesIndex.type_hash['dummy'].should == DummiesIndex::Dummy }
|
27
51
|
|
data/spec/chewy/query_spec.rb
CHANGED
@@ -72,6 +72,20 @@ describe Chewy::Query do
|
|
72
72
|
specify { expect { subject.offset(10) }.not_to change { subject.criteria.options } }
|
73
73
|
end
|
74
74
|
|
75
|
+
describe '#none' do
|
76
|
+
specify { subject.none.should be_a described_class }
|
77
|
+
specify { subject.none.should_not == subject }
|
78
|
+
specify { subject.none.criteria.should be_none }
|
79
|
+
|
80
|
+
context do
|
81
|
+
before { described_class.any_instance.should_not_receive(:_response) }
|
82
|
+
|
83
|
+
specify { subject.none.to_a.should == [] }
|
84
|
+
specify { subject.query(match: 'hello').none.to_a.should == [] }
|
85
|
+
specify { subject.none.query(match: 'hello').to_a.should == [] }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
75
89
|
describe '#query' do
|
76
90
|
specify { subject.query(match: 'hello').should be_a described_class }
|
77
91
|
specify { subject.query(match: 'hello').should_not == subject }
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyromaniac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- filters
|
158
158
|
- lib/chewy.rb
|
159
159
|
- lib/chewy/config.rb
|
160
|
+
- lib/chewy/errors.rb
|
160
161
|
- lib/chewy/fields/base.rb
|
161
162
|
- lib/chewy/fields/default.rb
|
162
163
|
- lib/chewy/fields/root.rb
|
@@ -164,6 +165,7 @@ files:
|
|
164
165
|
- lib/chewy/index/actions.rb
|
165
166
|
- lib/chewy/index/aliases.rb
|
166
167
|
- lib/chewy/index/search.rb
|
168
|
+
- lib/chewy/index/settings.rb
|
167
169
|
- lib/chewy/query.rb
|
168
170
|
- lib/chewy/query/compose.rb
|
169
171
|
- lib/chewy/query/criteria.rb
|
@@ -211,6 +213,7 @@ files:
|
|
211
213
|
- spec/chewy/index/actions_spec.rb
|
212
214
|
- spec/chewy/index/aliases_spec.rb
|
213
215
|
- spec/chewy/index/search_spec.rb
|
216
|
+
- spec/chewy/index/settings_spec.rb
|
214
217
|
- spec/chewy/index_spec.rb
|
215
218
|
- spec/chewy/query/criteria_spec.rb
|
216
219
|
- spec/chewy/query/filters_spec.rb
|
@@ -277,6 +280,7 @@ test_files:
|
|
277
280
|
- spec/chewy/index/actions_spec.rb
|
278
281
|
- spec/chewy/index/aliases_spec.rb
|
279
282
|
- spec/chewy/index/search_spec.rb
|
283
|
+
- spec/chewy/index/settings_spec.rb
|
280
284
|
- spec/chewy/index_spec.rb
|
281
285
|
- spec/chewy/query/criteria_spec.rb
|
282
286
|
- spec/chewy/query/filters_spec.rb
|