chewy 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/CHANGELOG.md +43 -1
  4. data/Gemfile +3 -0
  5. data/README.md +49 -11
  6. data/chewy.gemspec +1 -2
  7. data/gemfiles/Gemfile.rails-3.2 +1 -0
  8. data/gemfiles/Gemfile.rails-4.0 +1 -0
  9. data/lib/chewy.rb +8 -2
  10. data/lib/chewy/backports/deep_dup.rb +46 -0
  11. data/lib/chewy/backports/duplicable.rb +90 -0
  12. data/lib/chewy/config.rb +33 -6
  13. data/lib/chewy/errors.rb +1 -1
  14. data/lib/chewy/fields/base.rb +19 -7
  15. data/lib/chewy/fields/root.rb +13 -0
  16. data/lib/chewy/index/actions.rb +14 -6
  17. data/lib/chewy/index/search.rb +3 -2
  18. data/lib/chewy/query.rb +131 -17
  19. data/lib/chewy/query/compose.rb +27 -17
  20. data/lib/chewy/query/criteria.rb +34 -22
  21. data/lib/chewy/query/loading.rb +94 -10
  22. data/lib/chewy/query/nodes/exists.rb +1 -1
  23. data/lib/chewy/query/nodes/has_relation.rb +1 -1
  24. data/lib/chewy/query/nodes/missing.rb +1 -1
  25. data/lib/chewy/query/pagination.rb +8 -38
  26. data/lib/chewy/query/pagination/kaminari.rb +37 -0
  27. data/lib/chewy/runtime.rb +9 -0
  28. data/lib/chewy/runtime/version.rb +25 -0
  29. data/lib/chewy/type/adapter/active_record.rb +21 -7
  30. data/lib/chewy/type/adapter/base.rb +1 -1
  31. data/lib/chewy/type/adapter/object.rb +9 -6
  32. data/lib/chewy/type/import.rb +7 -4
  33. data/lib/chewy/type/mapping.rb +9 -9
  34. data/lib/chewy/type/wrapper.rb +1 -1
  35. data/lib/chewy/version.rb +1 -1
  36. data/lib/tasks/chewy.rake +40 -21
  37. data/spec/chewy/config_spec.rb +1 -1
  38. data/spec/chewy/fields/base_spec.rb +273 -8
  39. data/spec/chewy/index/actions_spec.rb +1 -2
  40. data/spec/chewy/index/aliases_spec.rb +0 -1
  41. data/spec/chewy/index/search_spec.rb +0 -8
  42. data/spec/chewy/index/settings_spec.rb +0 -2
  43. data/spec/chewy/index_spec.rb +0 -2
  44. data/spec/chewy/query/criteria_spec.rb +85 -18
  45. data/spec/chewy/query/loading_spec.rb +26 -9
  46. data/spec/chewy/query/nodes/and_spec.rb +2 -2
  47. data/spec/chewy/query/nodes/exists_spec.rb +6 -6
  48. data/spec/chewy/query/nodes/missing_spec.rb +4 -4
  49. data/spec/chewy/query/nodes/or_spec.rb +2 -2
  50. data/spec/chewy/query/pagination/kaminari_spec.rb +55 -0
  51. data/spec/chewy/query/pagination_spec.rb +15 -22
  52. data/spec/chewy/query_spec.rb +121 -52
  53. data/spec/chewy/rspec/update_index_spec.rb +0 -1
  54. data/spec/chewy/runtime/version_spec.rb +48 -0
  55. data/spec/chewy/runtime_spec.rb +9 -0
  56. data/spec/chewy/type/adapter/active_record_spec.rb +52 -0
  57. data/spec/chewy/type/adapter/object_spec.rb +33 -0
  58. data/spec/chewy/type/import_spec.rb +1 -3
  59. data/spec/chewy/type/mapping_spec.rb +4 -6
  60. data/spec/chewy/type/observe_spec.rb +0 -2
  61. data/spec/chewy/type/wrapper_spec.rb +0 -2
  62. data/spec/chewy/type_spec.rb +26 -5
  63. data/spec/chewy_spec.rb +0 -2
  64. data/spec/spec_helper.rb +2 -2
  65. metadata +15 -21
  66. data/lib/chewy/fields/default.rb +0 -10
  67. data/spec/chewy/fields/default_spec.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f677d05031da075087c0fb9942f31741766ce341
4
- data.tar.gz: 5759eead057c0e533a988ce96e5dd1c77ab9ccd2
3
+ metadata.gz: b9ce5f8bf5d9ad285ee36e1196ebd0516e7ded43
4
+ data.tar.gz: 9f4bc4e97c744d020cd33529a6aeb9d8ee8a4e7a
5
5
  SHA512:
6
- metadata.gz: 76d493cea3e5fd380fc455e53fe886a16e48a1d1050f619668617f719d7721dd3cd93ae1b815bec5785142a5bf7f3d327e3dbc2e4db3a8a8cee521ed61ee93fc
7
- data.tar.gz: 3091372369882b60d33b5b2ca8928a81ff1b9e7f5c7d8ff38fb0518bbb4a8d4e431746594e78d34a193c58c4aebff0bc245bc6be2ee27f046ca863e2988027a8
6
+ metadata.gz: 647b9df1cc80287dc95525ac8f55a94130eb1f94e91c5d1d72c370d47047a2055d9c751be3277fe93791fdbd36f083aa4af873a31a88a758c702c603806b4dbc
7
+ data.tar.gz: eddd0288baab2431ee08cb61d47e2a2bdbfc7453d4b3891f4b12d8af7c897f63415e01c56fedbc9fbb7f5eeceb48a7f79799b73cca797c6f8d876be6cee5ee2d
data/.travis.yml CHANGED
@@ -2,13 +2,13 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
5
+ - 2.1.1
6
6
  # - rbx
7
7
  gemfile:
8
8
  - Gemfile
9
9
  - gemfiles/Gemfile.rails-3.2
10
10
  - gemfiles/Gemfile.rails-4.0
11
11
  before_install:
12
- - curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz | tar xz -C /tmp
12
+ - curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.tar.gz | tar xz -C /tmp
13
13
  before_script:
14
- - TEST_CLUSTER_COMMAND="/tmp/elasticsearch-1.0.1/bin/elasticsearch" rake elasticsearch:start
14
+ - TEST_CLUSTER_COMMAND="/tmp/elasticsearch-1.2.1/bin/elasticsearch" rake elasticsearch:start
data/CHANGELOG.md CHANGED
@@ -1,9 +1,51 @@
1
1
  # master
2
2
 
3
- # Version 0.4.1
3
+ # Version 0.5.0
4
+
5
+ ## Incompatible changes:
6
+
7
+ * 404 exception (IndexMissingException) while query is swallowed and treated like an empty result set.
8
+
9
+ * `load` and `preload` for queries became lazy. Might be partially incompatible.
10
+
11
+ * Changed mapping behavior: multi-fields are defined in conformity with ElasticSearch documentation (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_multi_fields.html#_multi_fields)
12
+
13
+ ## Changes:
14
+
15
+ * `suggest` query options support (@rschellhorn).
16
+
17
+ * Added hash data support. How it is possible to pass hashes to import.
18
+
19
+ * `rake chewy:reset` and `rake chewy:update` paramless acts as `rake chewy:reset:all` and `rake chewy:update:all` respectively
20
+
21
+ * Added `delete_from_index?` API method for custom deleted objects marking.
22
+
23
+ * Added `post_filter` API, working the same way as filters.
24
+
25
+ * Added chainable `strategy` query method.
26
+
27
+ * Aliasing is performed in index create request for ElasticSearch >= 1.1.
28
+
29
+ * `preload` scope method loads ORM/ODM objects in background.
30
+
31
+ * `load` method `:only` and `:except` options to specify load types.
32
+
33
+ * `highlight` and `rescore` query options support.
4
34
 
5
35
  * config/chewy.yml ERB support.
6
36
 
37
+ ## Bugfixes:
38
+
39
+ * Fixed `missing` and `exists` filters DSL constructors.
40
+
41
+ * Reworked index data composing.
42
+
43
+ * Support for Kaminari new PaginatableArray behavior (@leemhenson)
44
+
45
+ * Correct waiting for status. After index creation, bulk import, and deletion.
46
+
47
+ * Fix #23 "wrong constant name" with namespace models
48
+
7
49
  # Version 0.4.0
8
50
 
9
51
  * Changed `update_index` matcher behavior. Now it compare array attributes position-independantly.
data/Gemfile CHANGED
@@ -3,7 +3,10 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in chewy.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'kaminari', require: false
7
+
6
8
  group :test do
9
+
7
10
  gem 'guard'
8
11
  gem 'guard-rspec'
9
12
  gem 'rb-inotify', require: false
data/README.md CHANGED
@@ -9,11 +9,11 @@ Chewy is ODM and wrapper for official elasticsearch client (https://github.com/e
9
9
 
10
10
  * Multi-model indexes.
11
11
 
12
- Index classes are independant from ORM/ODM models. Now implementing, e.g. cross-model autocomplete is much easier. You can just define index and work with it in object-oriented style. You can define several types for index - one per indexed model.
12
+ Index classes are independent from ORM/ODM models. Now implementing, e.g. cross-model autocomplete is much easier. You can just define index and work with it in object-oriented style. You can define several types for index - one per indexed model.
13
13
 
14
14
  * Every index is observable by all the related models.
15
15
 
16
- Most of the indexed models a related to other and somtimes it is nessesary to denormalize this related data and put at the same object. Like you need to index array of tags with article together. Chewy allows you to specify updatable index for every model separately. So, corresponding articles will be reindexed on the any tag update.
16
+ Most of the indexed models are related to other and sometimes it is nessesary to denormalize this related data and put at the same object. For example, you need to index array of tags with article together. Chewy allows you to specify updatable index for every model separately. So, corresponding articles will be reindexed on any tag update.
17
17
 
18
18
  * Bulk import everywhere.
19
19
 
@@ -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.configuration = {prefix: 'testing'}
64
+ Chewy.configuration = {prefix: 'test'}
65
65
  UsersIndex.index_name # => 'test_users'
66
66
  ```
67
67
 
@@ -102,7 +102,7 @@ See [config.rb](lib/chewy/config.rb) for more details.
102
102
  field :email, analyzer: 'email' # elasticsearch-related options
103
103
  field :country, value: ->(user) { user.country.name } # custom value proc
104
104
  field :badges, value: ->(user) { user.badges.map(&:name) } # passing array values to index
105
- field :projects, type: 'object' do # the same syntax for `multi_field`
105
+ field :projects do # the same block syntax for multi_field, if `:type` is specified
106
106
  field :title
107
107
  field :description # default data type is `string`
108
108
  end
@@ -130,17 +130,17 @@ See [config.rb](lib/chewy/config.rb) for more details.
130
130
 
131
131
  define_type User.active.includes(:country, :badges, :projects) do
132
132
  root date_detection: false do
133
- template 'about_translations.*', type: 'string', analyzer: 'stantard'
133
+ template 'about_translations.*', type: 'string', analyzer: 'standard'
134
134
 
135
135
  field :first_name, :last_name
136
136
  field :email, analyzer: 'email'
137
137
  field :country, value: ->(user) { user.country.name }
138
138
  field :badges, value: ->(user) { user.badges.map(&:name) }
139
- field :projects, type: 'object' do
139
+ field :projects do
140
140
  field :title
141
141
  field :description
142
142
  end
143
- field :about_translations, type: 'object'
143
+ field :about_translations, type: 'object' # pass object type explicitely if necessary
144
144
  field :rating, type: 'integer'
145
145
  field :created, type: 'date', include_in_all: false,
146
146
  value: ->{ created_at }
@@ -172,7 +172,7 @@ See [config.rb](lib/chewy/config.rb) for more details.
172
172
  update_index('users#user') { user if user.active? } # you can return even `nil` from the backreference
173
173
  end
174
174
 
175
- class Bage < ActiveRecord::Base
175
+ class Badge < ActiveRecord::Base
176
176
  has_and_belongs_to_many :users
177
177
 
178
178
  update_index('users') { users } # if index has only one type
@@ -223,7 +223,7 @@ UsersIndex.import user: User.where('rating > 100') # import only active users to
223
223
  UsersIndex.reset! # purges index and imports default data for all types
224
224
  ```
225
225
 
226
- Also if passed user is #destroyed? or specified id is not existing in the database, import will perform `delete` index for this it
226
+ Also if passed user is `#destroyed?` or `#delete_from_index?` or specified id does not exists in the database, import will perform delete from index action for this object.
227
227
 
228
228
  See [actions.rb](lib/chewy/index/actions.rb) for more details.
229
229
 
@@ -296,7 +296,7 @@ Also, queries can be performed on a type individually
296
296
  UsersIndex::User.filter(term: {name: 'foo'}) # will return UserIndex::User collection only
297
297
  ```
298
298
 
299
- If you are performing more then one `filter` or `query` in the chain,
299
+ If you are performing more than one `filter` or `query` in the chain,
300
300
  all the filters and queries will be concatenated in the way specified by
301
301
  `filter_mode` and `query_mode` respectively.
302
302
 
@@ -598,6 +598,24 @@ Compliance cheatsheet for filters and DSL expressions:
598
598
 
599
599
  See [filters.rb](lib/chewy/query/filters.rb) for more details.
600
600
 
601
+ ### Faceting
602
+
603
+ Facets are an optional sidechannel you can request from elasticsearch describing certain fields of the resulting collection. The most common use for facets is to allow the user continue filtering specifically within the subset, as opposed to the global index.
604
+
605
+ For instance, let's request the ```country``` field as a facet along with our users collection. We can do this with the #facets method like so:
606
+
607
+ ```ruby
608
+ UsersIndex.filter{ [...] }.facets({countries: {terms: {field: 'country'}}})
609
+ ```
610
+
611
+ Let's look at what we asked from elasticsearch. The facets setter method accepts a hash. You can choose custom/semantic key names for this hash for your own convinience (in this case I used the plural version of the actual field), in our case: ```countries```. The following nested hash tells ES to grab and aggregate values (terms) from the ```country``` field on our indexed records.
612
+
613
+ When the response comes back, it will have the ```:facets``` sidechannel included:
614
+
615
+ ```
616
+ < { ... ,"facets":{"countries":{"_type":"terms","missing":?,"total":?,"other":?,"terms":[{"term":"USA","count":?},{"term":"Brazil","count":?}, ...}}
617
+ ```
618
+
601
619
  ### Objects loading
602
620
 
603
621
  It is possible to load source objects from database for every search result:
@@ -605,7 +623,8 @@ It is possible to load source objects from database for every search result:
605
623
  ```ruby
606
624
  scope = UsersIndex.filter(range: {rating: {gte: 100}})
607
625
 
608
- scope.load # => will return User instances array (not a scope because )
626
+ scope.load # => scope is marked to return User instances array
627
+ scope.load.query(...) # => since objects are loaded lazily you can complete scope
609
628
  scope.load(user: { scope: ->{ includes(:country) }}) # you can also pass loading scopes for each
610
629
  # possibly returned type
611
630
  scope.load(user: { scope: User.includes(:country) }) # the second scope passing way.
@@ -614,6 +633,14 @@ scope.load(scope: ->{ includes(:country) }) # and more common scope applied to e
614
633
  scope.only(:id).load # it is optimal to request ids only if you are not planning to use type objects
615
634
  ```
616
635
 
636
+ The `preload` method takes the same options as `load` and ORM/ODM objects will be loaded, but scope will still return array of Chewy wrappers. To access real objects use `_object` wrapper method:
637
+
638
+ ```ruby
639
+ UsersIndex.filter(range: {rating: {gte: 100}}).preload(...).query(...).map(&:_object)
640
+ ```
641
+
642
+ See [loading.rb](lib/chewy/query/loading.rb) for more details.
643
+
617
644
  ### `ActiveSupport::Notifications` support
618
645
 
619
646
  Chewy has notifing the following events:
@@ -679,7 +706,11 @@ Inside Rails application some index mantaining rake tasks are defined.
679
706
 
680
707
  ```bash
681
708
  rake chewy:reset:all # resets all the existing indexes, declared in app/chewy
709
+ rake chewy:reset # alias for chewy:reset:all
682
710
  rake chewy:reset[users] # resets UsersIndex
711
+
712
+ rake chewy:update:all # updates all the existing indexes, declared in app/chewy
713
+ rake chewy:update # alias for chewy:update:all
683
714
  rake chewy:update[users] # updates UsersIndex
684
715
  ```
685
716
 
@@ -704,3 +735,10 @@ See [update_index.rb](lib/chewy/rspec/update_index.rb) for more details.
704
735
  4. Commit your changes (`git commit -am 'Add some feature'`)
705
736
  5. Push to the branch (`git push origin my-new-feature`)
706
737
  6. Create new Pull Request
738
+
739
+ Use the following Rake tasks to control ElasticSearch cluster while developing.
740
+
741
+ ```bash
742
+ rake elasticsearch:start # start Elasticsearch cluster on 9250 port for tests
743
+ rake elasticsearch:stop # stop Elasticsearch
744
+ ```
data/chewy.gemspec CHANGED
@@ -19,9 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec', '~> 2.14'
22
+ spec.add_development_dependency 'rspec', '~> 2.14.0'
23
23
  spec.add_development_dependency 'sqlite3'
24
- spec.add_development_dependency 'kaminari'
25
24
  spec.add_development_dependency 'activerecord', '>= 3.2'
26
25
  spec.add_development_dependency 'database_cleaner'
27
26
  spec.add_development_dependency 'elasticsearch-extensions'
@@ -4,6 +4,7 @@ gemspec path: '../'
4
4
 
5
5
  gem 'activerecord', '~> 3.2.0'
6
6
  gem 'activesupport', '~> 3.2.0'
7
+ gem 'kaminari', require: false
7
8
 
8
9
  group :test do
9
10
  gem 'guard'
@@ -4,6 +4,7 @@ gemspec path: '../'
4
4
 
5
5
  gem 'activerecord', '~> 4.0.0'
6
6
  gem 'activesupport', '~> 4.0.0'
7
+ gem 'kaminari', require: false
7
8
 
8
9
  group :test do
9
10
  gem 'guard'
data/lib/chewy.rb CHANGED
@@ -1,19 +1,25 @@
1
- require 'active_support/concern'
1
+ require 'active_support'
2
2
  require 'active_support/core_ext'
3
+ require 'active_support/concern'
3
4
  require 'active_support/json'
4
5
  require 'i18n/core_ext/hash'
6
+ require 'chewy/backports/deep_dup' unless Object.respond_to?(:deep_dup)
5
7
  require 'singleton'
6
8
 
9
+ begin
10
+ require 'kaminari'
11
+ rescue LoadError
12
+ end
7
13
  require 'elasticsearch'
8
14
 
9
15
  require 'chewy/version'
10
16
  require 'chewy/errors'
11
17
  require 'chewy/config'
18
+ require 'chewy/runtime'
12
19
  require 'chewy/index'
13
20
  require 'chewy/type'
14
21
  require 'chewy/query'
15
22
  require 'chewy/fields/base'
16
- require 'chewy/fields/default'
17
23
  require 'chewy/fields/root'
18
24
 
19
25
  require 'chewy/railtie' if defined?(::Rails)
@@ -0,0 +1,46 @@
1
+ require 'chewy/backports/duplicable'
2
+
3
+ class Object
4
+ # Returns a deep copy of object if it's duplicable. If it's
5
+ # not duplicable, returns +self+.
6
+ #
7
+ # object = Object.new
8
+ # dup = object.deep_dup
9
+ # dup.instance_variable_set(:@a, 1)
10
+ #
11
+ # object.instance_variable_defined?(:@a) # => false
12
+ # dup.instance_variable_defined?(:@a) # => true
13
+ def deep_dup
14
+ duplicable? ? dup : self
15
+ end
16
+ end
17
+
18
+ class Array
19
+ # Returns a deep copy of array.
20
+ #
21
+ # array = [1, [2, 3]]
22
+ # dup = array.deep_dup
23
+ # dup[1][2] = 4
24
+ #
25
+ # array[1][2] # => nil
26
+ # dup[1][2] # => 4
27
+ def deep_dup
28
+ map { |it| it.deep_dup }
29
+ end
30
+ end
31
+
32
+ class Hash
33
+ # Returns a deep copy of hash.
34
+ #
35
+ # hash = { a: { b: 'b' } }
36
+ # dup = hash.deep_dup
37
+ # dup[:a][:c] = 'c'
38
+ #
39
+ # hash[:a][:c] # => nil
40
+ # dup[:a][:c] # => "c"
41
+ def deep_dup
42
+ each_with_object(dup) do |(key, value), hash|
43
+ hash[key.deep_dup] = value.deep_dup
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,90 @@
1
+ #--
2
+ # Most objects are cloneable, but not all. For example you can't dup +nil+:
3
+ #
4
+ # nil.dup # => TypeError: can't dup NilClass
5
+ #
6
+ # Classes may signal their instances are not duplicable removing +dup+/+clone+
7
+ # or raising exceptions from them. So, to dup an arbitrary object you normally
8
+ # use an optimistic approach and are ready to catch an exception, say:
9
+ #
10
+ # arbitrary_object.dup rescue object
11
+ #
12
+ # Rails dups objects in a few critical spots where they are not that arbitrary.
13
+ # That rescue is very expensive (like 40 times slower than a predicate), and it
14
+ # is often triggered.
15
+ #
16
+ # That's why we hardcode the following cases and check duplicable? instead of
17
+ # using that rescue idiom.
18
+ #++
19
+ class Object
20
+ # Can you safely dup this object?
21
+ #
22
+ # False for +nil+, +false+, +true+, symbol, and number objects;
23
+ # true otherwise.
24
+ def duplicable?
25
+ true
26
+ end
27
+ end
28
+
29
+ class NilClass
30
+ # +nil+ is not duplicable:
31
+ #
32
+ # nil.duplicable? # => false
33
+ # nil.dup # => TypeError: can't dup NilClass
34
+ def duplicable?
35
+ false
36
+ end
37
+ end
38
+
39
+ class FalseClass
40
+ # +false+ is not duplicable:
41
+ #
42
+ # false.duplicable? # => false
43
+ # false.dup # => TypeError: can't dup FalseClass
44
+ def duplicable?
45
+ false
46
+ end
47
+ end
48
+
49
+ class TrueClass
50
+ # +true+ is not duplicable:
51
+ #
52
+ # true.duplicable? # => false
53
+ # true.dup # => TypeError: can't dup TrueClass
54
+ def duplicable?
55
+ false
56
+ end
57
+ end
58
+
59
+ class Symbol
60
+ # Symbols are not duplicable:
61
+ #
62
+ # :my_symbol.duplicable? # => false
63
+ # :my_symbol.dup # => TypeError: can't dup Symbol
64
+ def duplicable?
65
+ false
66
+ end
67
+ end
68
+
69
+ class Numeric
70
+ # Numbers are not duplicable:
71
+ #
72
+ # 3.duplicable? # => false
73
+ # 3.dup # => TypeError: can't dup Fixnum
74
+ def duplicable?
75
+ false
76
+ end
77
+ end
78
+
79
+ require 'bigdecimal'
80
+ class BigDecimal
81
+ begin
82
+ BigDecimal.new('4.56').dup
83
+
84
+ def duplicable?
85
+ true
86
+ end
87
+ rescue TypeError
88
+ # can't dup, so use superclass implementation
89
+ end
90
+ end
data/lib/chewy/config.rb CHANGED
@@ -3,7 +3,34 @@ module Chewy
3
3
  include Singleton
4
4
 
5
5
  attr_reader :analyzers, :tokenizers, :filters, :char_filters
6
- attr_accessor :configuration, :urgent_update, :query_mode, :filter_mode, :logger
6
+ attr_accessor :configuration,
7
+ # Just sets up logger to current configuration
8
+ #
9
+ # Chewy.logger = Rails.logger
10
+ #
11
+ :logger,
12
+
13
+ # Urgent update default value. False by default. Urgent
14
+ # updates are useful for testing, so don't use it in the
15
+ # application code. Prefer `Chewy.atomic` block for cumulative
16
+ # index updates.
17
+ #
18
+ :urgent_update,
19
+
20
+ # Default query compilation mode. `:must` by default.
21
+ # See Chewy::Query#query_mode for details
22
+ #
23
+ :query_mode,
24
+
25
+ # Default filters compilation mode. `:and` by default.
26
+ # See Chewy::Query#filter_mode for details
27
+ #
28
+ :filter_mode,
29
+
30
+ # Default post_filters compilation mode. `nil` by default.
31
+ # See Chewy::Query#post_filter_mode for details
32
+ #
33
+ :post_filter_mode
7
34
 
8
35
  def self.delegated
9
36
  public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods
@@ -20,8 +47,8 @@ module Chewy
20
47
  end
21
48
 
22
49
  def initialize
23
- @urgent_update = false
24
50
  @configuration = {}
51
+ @urgent_update = false
25
52
  @query_mode = :must
26
53
  @filter_mode = :and
27
54
  @analyzers = {}
@@ -101,10 +128,10 @@ module Chewy
101
128
  # creation.
102
129
  #
103
130
  # test: &test
104
- # host: 'localhost:9250'
105
- # index:
106
- # number_of_shards: 1
107
- # number_of_replicas: 0
131
+ # host: 'localhost:9250'
132
+ # index:
133
+ # number_of_shards: 1
134
+ # number_of_replicas: 0
108
135
  #
109
136
  def configuration
110
137
  options = @configuration.deep_symbolize_keys.merge(yaml_options)