Class: Chewy::Search::Parameters::Indices

Inherits:
Storage show all
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:

  1. If index is added to the storage, no matter, a class or a string/symbol, it gets appended to the list.
  2. If type is added to the storage, it filters out types assigned via indices.
  3. But when a type class with non-existing index is added, this index got also added to the list if indices.
  4. In cases when of an index identifier added, type indetifiers also got appended instead of filtering.

Instance Attribute Summary

Attributes inherited from Storage

#value

Instance Method Summary collapse

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.

Parameters:

Returns:

  • (true, false)

    the result of comparision

See Also:



27
28
29
# File 'lib/chewy/search/parameters/indices.rb', line 27

def ==(other)
  super || other.class == self.class && other.render == render
end

#indicesArray<Chewy::Index>

Returns index classes used for the request. No strings/symbos included.

Returns:



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.

Returns:

  • ({Symbol => Array<String>})

    rendered value with the parameter name

See Also:



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

#typesArray<Chewy::Type>

Returns type classes used for the request. No strings/symbos included.

Returns:



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.

Parameters:

Returns:

See Also:



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