Class: Chewy::Search::Parameters::Indices
- Defined in:
- lib/chewy/search/parameters/indices.rb
Overview
Stores indices and/or types to query. Renders it to lists of string accepted by ElasticSearch API.
The semantics behind it can be described in the following statements:
- If index is added to the storage, no matter, a class or a string/symbol, it gets appended to the list.
- If type is added to the storage, it filters out types assigned via indices.
- But when a type class with non-existing index is added, this index got also added to the list if indices.
- In cases when of an index identifier added, type indetifiers also got appended instead of filtering.
Instance Attribute Summary
Attributes inherited from Storage
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Two index storages are equal if they produce the same output on render.
-
#indices ⇒ Array<Chewy::Index>
Returns index classes used for the request.
-
#render ⇒ {Symbol => Array<String>}
Returns desired index and type names.
-
#types ⇒ Array<Chewy::Type>
Returns type classes used for the request.
-
#update!(other_value) ⇒ {Symbol => Array<Chewy::Index, Chewy::Type, String, Symbol>}
Just adds types to types and indices to indices.
Methods inherited from Storage
#initialize, #merge!, #replace!
Constructor Details
This class inherits a constructor from Chewy::Search::Parameters::Storage
Instance Method Details
#==(other) ⇒ true, false
Two index storages are equal if they produce the same output on render.
27 28 29 |
# File 'lib/chewy/search/parameters/indices.rb', line 27 def ==(other) super || other.class == self.class && other.render == render end |
#indices ⇒ Array<Chewy::Index>
Returns index classes used for the request. No strings/symbos included.
60 61 62 |
# File 'lib/chewy/search/parameters/indices.rb', line 60 def indices index_classes | type_classes.map(&:index) end |
#render ⇒ {Symbol => Array<String>}
Returns desired index and type names.
49 50 51 52 53 54 |
# File 'lib/chewy/search/parameters/indices.rb', line 49 def render { index: index_names.uniq.sort, type: type_names.uniq.sort }.reject { |_, v| v.blank? } end |
#types ⇒ Array<Chewy::Type>
Returns type classes used for the request. No strings/symbos included.
68 69 70 |
# File 'lib/chewy/search/parameters/indices.rb', line 68 def types type_classes | (index_classes - type_classes.map(&:index)).flat_map(&:types) end |
#update!(other_value) ⇒ {Symbol => Array<Chewy::Index, Chewy::Type, String, Symbol>}
Just adds types to types and indices to indices.
36 37 38 39 40 41 42 43 |
# File 'lib/chewy/search/parameters/indices.rb', line 36 def update!(other_value) new_value = normalize(other_value) @value = { indices: value[:indices] | new_value[:indices], types: value[:types] | new_value[:types] } end |