Class: Chewy::Search::Parameters::IndicesBoost

Inherits:
Storage
  • Object
show all
Defined in:
lib/chewy/search/parameters/indices_boost.rb

Overview

Stores provided values as a string-float hash, but also takes keys order into account.

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

Comparison also reqires additional logic. Since indexes boost is sensitive to the order index templates are provided, we have to compare stored hashes keys as well.

Returns:

  • (true, false)

See Also:



38
39
40
# File 'lib/chewy/search/parameters/indices_boost.rb', line 38

def ==(other)
  super && value.keys == other.value.keys
end

#renderArray<{String => Float}>

Renders the value hash as an array of hashes for each key-value pair.

Returns:

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

    updated value

See Also:



28
29
30
# File 'lib/chewy/search/parameters/indices_boost.rb', line 28

def render
  {self.class.param_name => value.map { |k, v| {k => v} }} if value.present?
end

#update!(other_value) ⇒ {String => Float}

Merges two hashes, but puts keys from the second hash at the end of the result hash.

Parameters:

  • other_value ({String, Symbol => String, Integer, Float})

    any acceptable storage value

Returns:

  • ({String => Float})

    updated value

See Also:



18
19
20
21
# File 'lib/chewy/search/parameters/indices_boost.rb', line 18

def update!(other_value)
  new_value = normalize(other_value)
  value.except!(*new_value.keys).merge!(new_value)
end