class Chewy::Search::Parameters::Order

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.

@see Chewy::Search::Request#order @see Chewy::Search::Request#reorder @see www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html

Public Instance Methods

render() click to toggle source

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

@see Chewy::Search::Parameters::Storage#render @return [{Symbol => Array<Hash, String, Symbol>}]

# File lib/chewy/search/parameters/order.rb, line 28
def render
  return if value.blank?

  {sort: value}
end
update!(other_value) click to toggle source

Merges two hashes.

@see Chewy::Search::Parameters::Storage#update! @param other_value [Object] any acceptable storage value @return [Object] updated value

# File lib/chewy/search/parameters/order.rb, line 19
def update!(other_value)
  value.concat(normalize(other_value))
end

Private Instance Methods

normalize(value) click to toggle source
# File lib/chewy/search/parameters/order.rb, line 36
def normalize(value)
  case value
  when Array
    value.each_with_object([]) do |sv, res|
      res.concat(normalize(sv))
    end
  when Hash
    [value.stringify_keys]
  else
    value.present? ? [value.to_s] : []
  end
end