chewy 7.0.1 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -26
  3. data/CHANGELOG.md +7 -3
  4. data/README.md +27 -38
  5. data/lib/chewy/fields/root.rb +1 -2
  6. data/lib/chewy/index.rb +4 -15
  7. data/lib/chewy/index/actions.rb +1 -3
  8. data/lib/chewy/index/aliases.rb +1 -3
  9. data/lib/chewy/railtie.rb +2 -18
  10. data/lib/chewy/search/loader.rb +2 -12
  11. data/lib/chewy/search/parameters/indices.rb +12 -57
  12. data/lib/chewy/search/request.rb +20 -40
  13. data/lib/chewy/search/response.rb +1 -1
  14. data/lib/chewy/search/scrolling.rb +1 -1
  15. data/lib/chewy/stash.rb +2 -5
  16. data/lib/chewy/type/import/bulk_request.rb +1 -2
  17. data/lib/chewy/type/import/journal_builder.rb +1 -2
  18. data/lib/chewy/type/import/routine.rb +2 -2
  19. data/lib/chewy/type/mapping.rb +1 -1
  20. data/lib/chewy/type/syncer.rb +1 -4
  21. data/lib/chewy/version.rb +1 -1
  22. data/lib/tasks/chewy.rake +10 -10
  23. data/migration_guide.md +0 -19
  24. data/spec/chewy/fields/base_spec.rb +4 -4
  25. data/spec/chewy/fields/root_spec.rb +4 -4
  26. data/spec/chewy/index/specification_spec.rb +13 -13
  27. data/spec/chewy/index_spec.rb +1 -3
  28. data/spec/chewy/journal_spec.rb +4 -4
  29. data/spec/chewy/runtime_spec.rb +1 -1
  30. data/spec/chewy/search/loader_spec.rb +0 -16
  31. data/spec/chewy/search/parameters/indices_spec.rb +25 -110
  32. data/spec/chewy/search/request_spec.rb +11 -28
  33. data/spec/chewy/search/scrolling_spec.rb +2 -8
  34. data/spec/chewy/search_spec.rb +2 -2
  35. data/spec/chewy/type/import/bulk_request_spec.rb +0 -6
  36. data/spec/chewy/type/import/journal_builder_spec.rb +0 -4
  37. data/spec/chewy/type/import_spec.rb +2 -2
  38. data/spec/chewy/type/mapping_spec.rb +5 -37
  39. metadata +2 -6
  40. data/.github/workflows/ruby.yml +0 -94
  41. data/lib/chewy/search/parameters/types.rb +0 -20
  42. data/spec/chewy/search/parameters/types_spec.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1dd4e22b7f5c013837c2799973a115efec21cac6555a8ec9f30c85b63525f155
4
- data.tar.gz: d938f5225426da6b649179bcacced5f24974a80995cf4dd62ac77f8e9484df8b
3
+ metadata.gz: 58a5011ecef1ca511a28d4d3299d61f852c4c11ffe6fd124db3e0a5b370a0f9e
4
+ data.tar.gz: fa0ce61841d579210c2de4a84624b265cca533f887e6125d8e07cee59315c4a6
5
5
  SHA512:
6
- metadata.gz: f54a6ae762f36af260a07f7da838d802e5152431b14b8120c1be2fa083510ecaf1ae650e115294a2bac3ad4ae17bac399b0873d4259e63f4ad9a655c05bfa224
7
- data.tar.gz: d2c4cf7030995844d04841ad0739497dacffd3fb57d52ca6d7aed871d30e112fe6eb88f084a678c7090d359f91f944b21fc4f45b65f1f9fffa6da2775f9845b0
6
+ metadata.gz: '0925c5bb8f3adfc79b5914d975c71f2677d6232ccbac074d65ee63d99d23cfbc16c85adf88c953e003fbebfcff2fc9b0bb5a11d735ce6432cdcd57d76e7f81e4'
7
+ data.tar.gz: fefd812c6daea408e90b6f235efd169b195b5d1003fe4d3042c2e502b375d0b7cdf6d4d41133d012bf05a0f0e417ce95e43fbd1eb8e99b9ba3d72f6a4b50e548
data/.circleci/config.yml CHANGED
@@ -23,8 +23,6 @@ workflows:
23
23
  - rspec-ruby-27-activerecord52
24
24
  - rspec-ruby-27-mongoid
25
25
  - rspec-ruby-30-activerecord61
26
- - rspec-ruby-27-activerecord61-es6
27
- - rspec-ruby-30-activerecord61-es6
28
26
 
29
27
  commands:
30
28
  rspec-test:
@@ -214,27 +212,3 @@ jobs:
214
212
  GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
215
213
  steps:
216
214
  - rspec-test
217
-
218
- rspec-ruby-27-activerecord61-es6:
219
- docker:
220
- - image: circleci/ruby:2.7
221
- - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
222
- environment:
223
- <<: *es-env
224
- working_directory: ~/repo
225
- environment:
226
- GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
227
- steps:
228
- - rspec-test
229
-
230
- rspec-ruby-30-activerecord61-es6:
231
- docker:
232
- - image: circleci/ruby:3.0
233
- - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13
234
- environment:
235
- <<: *es-env
236
- working_directory: ~/repo
237
- environment:
238
- GEMFILE: gemfiles/rails.6.1.activerecord.gemfile
239
- steps:
240
- - rspec-test
data/CHANGELOG.md CHANGED
@@ -8,12 +8,16 @@
8
8
 
9
9
  ### Bugs Fixed
10
10
 
11
- ## 7.0.1 (2021-05-03)
11
+ ## 7.1.0 (2021-03-03)
12
12
 
13
13
  ### Changes
14
14
 
15
- * [#792](https://github.com/toptal/chewy/pull/792): Skip ES version memoization for search requests ([@rabotyaga][])
16
- * See the Migration Guide for details
15
+ * [#766](https://github.com/toptal/chewy/pull/766): **(Breaking)** Drop support for Elasticsearch 6.x ([@rabotyaga][])
16
+ * [#765](https://github.com/toptal/chewy/pull/765): Fix ruby 2.7 warnings in rake tasks ([@aglushkov][])
17
+
18
+ ### Bugs Fixed
19
+
20
+ * [#722](https://github.com/toptal/chewy/issues/722): Remove alias_method_chain, use Module#prepend instead ([@dalthon][])
17
21
 
18
22
  ## 7.0.0 (2021-02-22)
19
23
 
data/README.md CHANGED
@@ -17,7 +17,6 @@ Chewy is an ODM (Object Document Mapper), built on top of the [the official Elas
17
17
  * [Index definition](#index-definition)
18
18
  * [Type default import options](#type-default-import-options)
19
19
  * [Multi (nested) and object field types](#multi-nested-and-object-field-types)
20
- * [Parent and children types](#parent-and-children-types)
21
20
  * [Geo Point fields](#geo-point-fields)
22
21
  * [Crutches™ technology](#crutches-technology)
23
22
  * [Witchcraft™ technology](#witchcraft-technology)
@@ -55,10 +54,6 @@ Chewy is an ODM (Object Document Mapper), built on top of the [the official Elas
55
54
 
56
55
  In this section we'll cover why you might want to use Chewy instead of the official `elasticsearch-ruby` client gem.
57
56
 
58
- * Multi-model indices.
59
-
60
- Index classes are independent from ORM/ODM models. Now, implementing e.g. cross-model autocomplete is much easier. You can just define the index and work with it in an object-oriented style. You can define several types for index - one per indexed model.
61
-
62
57
  * Every index is observable by all the related models.
63
58
 
64
59
  Most of the indexed models are related to other and sometimes it is necessary to denormalize this related data and put at the same object. For example, you need to index an array of tags together with an article. Chewy allows you to specify an updateable index for every model separately - so corresponding articles will be reindexed on any tag update.
@@ -99,6 +94,7 @@ Chewy is compatible with MRI 2.5-3.0¹.
99
94
 
100
95
  | Chewy version | Elasticsearch version |
101
96
  | ------------- | ---------------------------------- |
97
+ | 7.1.x | 7.x |
102
98
  | 7.0.0 | 6.8, 7.x |
103
99
  | 6.0.0 | 5.x, 6.x |
104
100
  | 5.x | 5.x, limited support for 1.x & 2.x |
@@ -365,18 +361,6 @@ end
365
361
 
366
362
  The `value:` option for internal fields will no longer be effective.
367
363
 
368
- ### Parent and children types
369
-
370
- To define [parent](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child-mapping.html) type for a given index_type, you can include root options for the type where you can specify parent_type and parent_id
371
-
372
- ```ruby
373
- define_type User.includes(:account) do
374
- root parent: 'account', parent_id: ->{ account_id } do
375
- field :created_at, type: 'date'
376
- field :task_id, type: 'integer'
377
- end
378
- end
379
- ```
380
364
  ### Geo Point fields
381
365
 
382
366
  You can use [Elasticsearch's geo mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html) with the `geo_point` field type, allowing you to query, filter and order by latitude and longitude. You can use the following hash format:
@@ -602,7 +586,7 @@ Imagine that you reset your index in a zero-downtime manner (to separate index),
602
586
 
603
587
  ### Types access
604
588
 
605
- You can access index-defined types with the following API:
589
+ You can access index-defined type with the following API:
606
590
 
607
591
  ```ruby
608
592
  UsersIndex::User # => UsersIndex::User
@@ -630,11 +614,10 @@ UsersIndex::User.import # import with 0 arguments process all the data specified
630
614
  UsersIndex::User.import User.where('rating > 100') # or import specified users scope
631
615
  UsersIndex::User.import User.where('rating > 100').to_a # or import specified users array
632
616
  UsersIndex::User.import [1, 2, 42] # pass even ids for import, it will be handled in the most effective way
633
- UsersIndex::User.import User.where('rating > 100'), update_fields: [:email] # if update fields are specified - it will update their values only with the `update` bulk action.
617
+ UsersIndex::User.import User.where('rating > 100'), update_fields: [:email] # if update fields are specified - it will update their values only with the `update` bulk action
634
618
 
635
- UsersIndex.import # import every defined type
636
- UsersIndex.import user: User.where('rating > 100') # import only active users to `user` type.
637
- # Other index types, if exists, will be imported with default scope from the type definition.
619
+ UsersIndex.import # same as UsersIndex::User.import
620
+ UsersIndex.import user: User.where('rating > 100') # import only specified users
638
621
  UsersIndex.reset! # purges index and imports default data for all types
639
622
  ```
640
623
 
@@ -923,19 +906,25 @@ Quick introduction.
923
906
  The request DSL have the same chainable nature as AR or Mongoid ones. The main class is `Chewy::Search::Request`. It is possible to perform requests on behalf of indices or types:
924
907
 
925
908
  ```ruby
926
- PlaceIndex.query(match: {name: 'London'}) # returns documents of any type
927
- PlaceIndex::City.query(match: {name: 'London'}) # returns cities only.
909
+ CitiesIndex.query(match: {name: 'London'}) # or
910
+ CitiesIndex::City.query(match: {name: 'London'})
928
911
  ```
929
912
 
930
913
  Main methods of the request DSL are: `query`, `filter` and `post_filter`, it is possible to pass pure query hashes or use `elasticsearch-dsl`. Also, there is an additional
931
914
 
932
915
  ```ruby
933
- PlaceIndex
916
+ CitiesIndex
934
917
  .filter(term: {name: 'Bangkok'})
935
918
  .query { match name: 'London' }
936
919
  .query.not(range: {population: {gt: 1_000_000}})
937
920
  ```
938
921
 
922
+ You can query a set of indexes at once:
923
+
924
+ ```ruby
925
+ CitiesIndex.indices(CountriesIndex).query(match: {name: 'Some'})
926
+ ```
927
+
939
928
  See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html and https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl for more details.
940
929
 
941
930
  An important part of requests manipulation is merging. There are 4 methods to perform it: `merge`, `and`, `or`, `not`. See [Chewy::Search::QueryProxy](lib/chewy/search/query_proxy.rb) for details. Also, `only` and `except` methods help to remove unneeded parts of the request.
@@ -943,7 +932,7 @@ An important part of requests manipulation is merging. There are 4 methods to pe
943
932
  Every other request part is covered by a bunch of additional methods, see [Chewy::Search::Request](lib/chewy/search/request.rb) for details:
944
933
 
945
934
  ```ruby
946
- PlaceIndex.limit(10).offset(30).order(:name, {population: {order: :desc}})
935
+ CitiesIndex.limit(10).offset(30).order(:name, {population: {order: :desc}})
947
936
  ```
948
937
 
949
938
  Request DSL also provides additional scope actions, like `delete_all`, `exists?`, `count`, `pluck`, etc.
@@ -969,8 +958,8 @@ See [Chewy::Search::Scrolling](lib/chewy/search/scrolling.rb) for details.
969
958
  It is possible to load ORM/ODM source objects with the `objects` method. To provide additional loading options use `load` method:
970
959
 
971
960
  ```ruby
972
- PlacesIndex.load(scope: -> { active }).to_a # to_a returns `Chewy::Type` wrappers.
973
- PlacesIndex.load(scope: -> { active }).objects # An array of AR source objects.
961
+ CitiesIndex.load(scope: -> { active }).to_a # to_a returns `Chewy::Type` wrappers.
962
+ CitiesIndex.load(scope: -> { active }).objects # An array of AR source objects.
974
963
  ```
975
964
 
976
965
  See [Chewy::Search::Loader](lib/chewy/search/loader.rb) for more details.
@@ -978,7 +967,7 @@ See [Chewy::Search::Loader](lib/chewy/search/loader.rb) for more details.
978
967
  In case when it is necessary to iterate through both of the wrappers and objects simultaneously, `object_hash` method helps a lot:
979
968
 
980
969
  ```ruby
981
- scope = PlacesIndex.load(scope: -> { active })
970
+ scope = CitiesIndex.load(scope: -> { active })
982
971
  scope.each do |wrapper|
983
972
  scope.object_hash[wrapper]
984
973
  end
@@ -995,8 +984,8 @@ Performs zero-downtime reindexing as described [here](https://www.elastic.co/blo
995
984
  ```bash
996
985
  rake chewy:reset # resets all the existing indices
997
986
  rake chewy:reset[users] # resets UsersIndex only
998
- rake chewy:reset[users,places] # resets UsersIndex and PlacesIndex
999
- rake chewy:reset[-users,places] # resets every index in the application except specified ones
987
+ rake chewy:reset[users,cities] # resets UsersIndex and CitiesIndex
988
+ rake chewy:reset[-users,cities] # resets every index in the application except specified ones
1000
989
  ```
1001
990
 
1002
991
  #### `chewy:upgrade`
@@ -1011,8 +1000,8 @@ See [Chewy::Stash::Specification](lib/chewy/stash.rb) and [Chewy::Index::Specifi
1011
1000
  ```bash
1012
1001
  rake chewy:upgrade # upgrades all the existing indices
1013
1002
  rake chewy:upgrade[users] # upgrades UsersIndex only
1014
- rake chewy:upgrade[users,places] # upgrades UsersIndex and PlacesIndex
1015
- rake chewy:upgrade[-users,places] # upgrades every index in the application except specified ones
1003
+ rake chewy:upgrade[users,cities] # upgrades UsersIndex and CitiesIndex
1004
+ rake chewy:upgrade[-users,cities] # upgrades every index in the application except specified ones
1016
1005
  ```
1017
1006
 
1018
1007
  #### `chewy:update`
@@ -1024,8 +1013,8 @@ Unlike `reset` or `upgrade` tasks, it is possible to pass type references to upd
1024
1013
  ```bash
1025
1014
  rake chewy:update # updates all the existing indices
1026
1015
  rake chewy:update[users] # updates UsersIndex only
1027
- rake chewy:update[users,places#city] # updates the whole UsersIndex and PlacesIndex::City type
1028
- rake chewy:update[-users,places#city] # updates every index in the application except every type defined in UsersIndex and the rest of the types defined in PlacesIndex
1016
+ rake chewy:update[users,cities#city] # updates UsersIndex and CitiesIndex (if City type is defined on CitiesIndex)
1017
+ rake chewy:update[-users,cities#city] # updates every index in the application except UsersIndex and CitiesIndex::City
1029
1018
  ```
1030
1019
 
1031
1020
  #### `chewy:sync`
@@ -1039,8 +1028,8 @@ See [Chewy::Type::Syncer](lib/chewy/type/syncer.rb) for more details.
1039
1028
  ```bash
1040
1029
  rake chewy:sync # synchronizes all the existing indices
1041
1030
  rake chewy:sync[users] # synchronizes UsersIndex only
1042
- rake chewy:sync[users,places#city] # synchronizes the whole UsersIndex and PlacesIndex::City type
1043
- rake chewy:sync[-users,places#city] # synchronizes every index in the application except every type defined in UsersIndex and the rest of the types defined in PlacesIndex
1031
+ rake chewy:sync[users,cities#city] # synchronizes UsersIndex and CitiesIndex (if City type is defined on CitiesIndex)
1032
+ rake chewy:sync[-users,cities#city] # synchronizes every index in the application except except UsersIndex and CitiesIndex::City
1044
1033
  ```
1045
1034
 
1046
1035
  #### `chewy:deploy`
@@ -1064,7 +1053,7 @@ If the number of processes is not specified explicitly - `parallel` gem tries to
1064
1053
  ```bash
1065
1054
  rake chewy:parallel:reset
1066
1055
  rake chewy:parallel:upgrade[4]
1067
- rake chewy:parallel:update[4,places#city]
1056
+ rake chewy:parallel:update[4,cities#city]
1068
1057
  rake chewy:parallel:sync[4,-users]
1069
1058
  rake chewy:parallel:deploy[4] # performs parallel upgrade and parallel sync afterwards
1070
1059
  ```
@@ -29,8 +29,7 @@ module Chewy
29
29
  mappings[name][:dynamic_templates].concat dynamic_templates
30
30
  end
31
31
 
32
- mappings[name][:_parent] = parent.is_a?(Hash) ? parent : {type: parent} if parent
33
- mappings
32
+ mappings[name]
34
33
  end
35
34
 
36
35
  def dynamic_template(*args)
data/lib/chewy/index.rb CHANGED
@@ -152,23 +152,12 @@ module Chewy
152
152
  self.type_hash = type_hash.merge(type_class.type_name => type_class)
153
153
  end
154
154
 
155
- # Types method has double usage.
156
- # If no arguments are passed - it returns array of defined types:
155
+ # Returns defined type:
157
156
  #
158
- # UsersIndex.types # => [UsersIndex::Admin, UsersIndex::Manager, UsersIndex::User]
157
+ # UsersIndex.types # => [UsersIndex::User]
159
158
  #
160
- # If arguments are passed it treats like a part of chainable query DSL and
161
- # adds types array for index to select.
162
- #
163
- # UsersIndex.filters { name =~ 'ro' }.types(:admin, :manager)
164
- # UsersIndex.types(:admin, :manager).filters { name =~ 'ro' } # the same as the first example
165
- #
166
- def types(*args)
167
- if args.present?
168
- all.types(*args)
169
- else
170
- type_hash.values
171
- end
159
+ def types
160
+ type_hash.values
172
161
  end
173
162
 
174
163
  # Returns defined types names:
@@ -59,9 +59,7 @@ module Chewy
59
59
 
60
60
  body = specification_hash
61
61
  body[:aliases] = {general_name => {}} if options[:alias] && suffixed_name != general_name
62
- args = {index: suffixed_name, body: body}
63
- args[:include_type_name] = true if Runtime.version >= '6.7.0'
64
- result = client.indices.create(**args)
62
+ result = client.indices.create(index: suffixed_name, body: body)
65
63
 
66
64
  Chewy.wait_for_status if result
67
65
  result
@@ -5,9 +5,7 @@ module Chewy
5
5
 
6
6
  module ClassMethods
7
7
  def indexes
8
- get_args = {index: index_name}
9
- get_args[:include_type_name] = true if Runtime.version >= '6.7.0'
10
- indexes = empty_if_not_found { client.indices.get(**get_args).keys }
8
+ indexes = empty_if_not_found { client.indices.get(index: index_name).keys }
11
9
  indexes += empty_if_not_found { client.indices.get_alias(name: index_name).keys }
12
10
  indexes.compact.uniq
13
11
  end
data/lib/chewy/railtie.rb CHANGED
@@ -22,17 +22,6 @@ module Chewy
22
22
  end
23
23
 
24
24
  module MigrationStrategy
25
- extend ActiveSupport::Concern
26
- included do
27
- alias_method_chain :migrate, :chewy
28
- end
29
-
30
- def migrate_with_chewy(*args)
31
- Chewy.strategy(:bypass) { migrate_without_chewy(*args) }
32
- end
33
- end
34
-
35
- module Rails5MigrationStrategy
36
25
  def migrate(*args)
37
26
  Chewy.strategy(:bypass) { super }
38
27
  end
@@ -57,13 +46,8 @@ module Chewy
57
46
 
58
47
  initializer 'chewy.migration_strategy' do
59
48
  ActiveSupport.on_load(:active_record) do
60
- if Rails::VERSION::MAJOR >= 5
61
- ActiveRecord::Migration.prepend(Rails5MigrationStrategy)
62
- ActiveRecord::Migrator.prepend(Rails5MigrationStrategy) if defined? ActiveRecord::Migrator
63
- else
64
- ActiveRecord::Migration.send(:include, MigrationStrategy)
65
- ActiveRecord::Migrator.send(:include, MigrationStrategy) if defined? ActiveRecord::Migrator
66
- end
49
+ ActiveRecord::Migration.prepend(MigrationStrategy)
50
+ ActiveRecord::Migrator.prepend(MigrationStrategy) if defined? ActiveRecord::Migrator
67
51
  end
68
52
  end
69
53
 
@@ -9,14 +9,10 @@ module Chewy
9
9
  # @see Chewy::Search::Scrolling#scroll_objects
10
10
  class Loader
11
11
  # @param indexes [Array<Chewy::Index>] list of indexes to lookup types
12
- # @param only [Array<String, Symbol>] list of selected type names to load
13
- # @param except [Array<String, Symbol>] list of type names which will not be loaded
14
12
  # @param options [Hash] adapter-specific load options
15
13
  # @see Chewy::Type::Adapter::Base#load
16
- def initialize(indexes: [], only: [], except: [], **options)
14
+ def initialize(indexes: [], **options)
17
15
  @indexes = indexes
18
- @only = Array.wrap(only).map(&:to_s)
19
- @except = Array.wrap(except).map(&:to_s)
20
16
  @options = options
21
17
  end
22
18
 
@@ -31,7 +27,7 @@ module Chewy
31
27
  (@derive_type ||= {})[[index, type]] ||= begin
32
28
  index_class = derive_index(index)
33
29
  raise Chewy::UnderivableType, "Can not find index named `#{index}`" unless index_class
34
- index_class.type_hash[type] or raise Chewy::UnderivableType, "Index `#{index}` doesn`t have type named `#{type}`"
30
+ index_class.type_hash.values.first
35
31
  end
36
32
  end
37
33
 
@@ -48,8 +44,6 @@ module Chewy
48
44
  def load(hits)
49
45
  hit_groups = hits.group_by { |hit| [hit['_index'], hit['_type']] }
50
46
  loaded_objects = hit_groups.each_with_object({}) do |((index_name, type_name), hit_group), result|
51
- next if skip_type?(type_name)
52
-
53
47
  type = derive_type(index_name, type_name)
54
48
  ids = hit_group.map { |hit| hit['_id'] }
55
49
  loaded = type.adapter.load(ids, **@options.merge(_type: type))
@@ -74,10 +68,6 @@ module Chewy
74
68
  def indexes_hash
75
69
  @indexes_hash ||= @indexes.index_by(&:index_name)
76
70
  end
77
-
78
- def skip_type?(type_name)
79
- @except.include?(type_name) || @only.present? && !@only.include?(type_name)
80
- end
81
71
  end
82
72
  end
83
73
  end
@@ -3,70 +3,48 @@ require 'chewy/search/parameters/storage'
3
3
  module Chewy
4
4
  module Search
5
5
  class Parameters
6
- # Stores indices and/or types to query.
6
+ # Stores indices to query.
7
7
  # Renders it to lists of string accepted by ElasticSearch
8
8
  # API.
9
9
  #
10
- # The semantics behind it can be described in the
11
- # following statements:
12
- # 1. If index is added to the storage, no matter, a class
10
+ # If index is added to the storage, no matter, a class
13
11
  # or a string/symbol, it gets appended to the list.
14
- # 2. If type is added to the storage, it filters out types
15
- # assigned via indices.
16
- # 3. But when a type class with non-existing index is added,
17
- # this index got also added to the list if indices.
18
- # 4. In cases when of an index identifier added, type
19
- # indetifiers also got appended instead of filtering.
20
12
  class Indices < Storage
21
13
  # Two index storages are equal if they produce the
22
14
  # same output on render.
23
15
  #
24
16
  # @see Chewy::Search::Parameters::Storage#==
25
17
  # @param other [Chewy::Search::Parameters::Storage] any storage instance
26
- # @return [true, false] the result of comparision
18
+ # @return [true, false] the result of comparison
27
19
  def ==(other)
28
20
  super || other.class == self.class && other.render == render
29
21
  end
30
22
 
31
- # Just adds types to types and indices to indices.
23
+ # Just adds indices to indices.
32
24
  #
33
25
  # @see Chewy::Search::Parameters::Storage#update!
34
- # @param other_value [{Symbol => Array<Chewy::Index, Chewy::Type, String, Symbol>}] any acceptable storage value
35
- # @return [{Symbol => Array<Chewy::Index, Chewy::Type, String, Symbol>}] updated value
26
+ # @param other_value [{Symbol => Array<Chewy::Index, String, Symbol>}] any acceptable storage value
27
+ # @return [{Symbol => Array<Chewy::Index, String, Symbol>}] updated value
36
28
  def update!(other_value)
37
29
  new_value = normalize(other_value)
38
30
 
39
- @value = {
40
- indices: value[:indices] | new_value[:indices],
41
- types: value[:types] | new_value[:types]
42
- }
31
+ @value = {indices: value[:indices] | new_value[:indices]}
43
32
  end
44
33
 
45
- # Returns desired index and type names.
34
+ # Returns desired index names.
46
35
  #
47
36
  # @see Chewy::Search::Parameters::Storage#render
48
37
  # @return [{Symbol => Array<String>}] rendered value with the parameter name
49
38
  def render
50
- {
51
- index: index_names.uniq.sort,
52
- type: type_names.uniq.sort
53
- }.reject { |_, v| v.blank? }
39
+ {index: index_names.uniq.sort}.reject { |_, v| v.blank? }
54
40
  end
55
41
 
56
42
  # Returns index classes used for the request.
57
- # No strings/symbos included.
43
+ # No strings/symbols included.
58
44
  #
59
45
  # @return [Array<Chewy::Index>] a list of index classes
60
46
  def indices
61
- index_classes | type_classes.map(&:index)
62
- end
63
-
64
- # Returns type classes used for the request.
65
- # No strings/symbos included.
66
- #
67
- # @return [Array<Chewy::Type>] a list of types classes
68
- def types
69
- type_classes | (index_classes - type_classes.map(&:index)).flat_map(&:types)
47
+ index_classes
70
48
  end
71
49
 
72
50
  private
@@ -78,10 +56,7 @@ module Chewy
78
56
  def normalize(value)
79
57
  value ||= {}
80
58
 
81
- {
82
- indices: Array.wrap(value[:indices]).flatten.compact,
83
- types: Array.wrap(value[:types]).flatten.compact
84
- }
59
+ {indices: Array.wrap(value[:indices]).flatten.compact}
85
60
  end
86
61
 
87
62
  def index_classes
@@ -97,26 +72,6 @@ module Chewy
97
72
  def index_names
98
73
  indices.map(&:index_name) | index_identifiers.map(&:to_s)
99
74
  end
100
-
101
- def type_classes
102
- value[:types].select do |klass|
103
- klass.is_a?(Class) && klass < Chewy::Type
104
- end
105
- end
106
-
107
- def type_identifiers
108
- value[:types] - type_classes
109
- end
110
-
111
- def type_names
112
- type_names = types.map(&:type_name)
113
-
114
- if index_identifiers.blank? && type_identifiers.present?
115
- (type_names & type_identifiers.map(&:to_s)).presence || type_names
116
- else
117
- type_names | type_identifiers.map(&:to_s)
118
- end
119
- end
120
75
  end
121
76
  end
122
77
  end