Class: Chewy::Search::Parameters::Order

Inherits:
Storage show all
Defined in:
lib/chewy/search/parameters/order.rb

Overview

Sort parameter storage. Stores a hash of fields with the nil key if no options for the field were specified. Normalizer accepts an array of any hash-string-symbols combinations, or a hash.

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. Hashes are compared orderlessly, but for sort parameter oder is important, so we compare hash key collections additionally.

Returns:

  • (true, false)

See Also:



43
44
45
# File 'lib/chewy/search/parameters/order.rb', line 43

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

#render{Symbol => Array<Hash, String, Symbol>}

Size requires specialized rendering logic, it should return an array to satisfy ES.

Returns:

See Also:



28
29
30
31
32
33
34
35
# File 'lib/chewy/search/parameters/order.rb', line 28

def render
  return if value.blank?

  sort = value.map do |(field, options)|
    options ? {field => options} : field
  end
  {sort: sort}
end

#update!(other_value) ⇒ Object

Merges two hashes.

Parameters:

  • other_value (Object)

    any acceptable storage value

Returns:

See Also:



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

def update!(other_value)
  value.merge!(normalize(other_value))
end