class OpenSearch::DSL::Search::Sort
Wraps the ‘sort` part of a search definition
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
OpenSearch::DSL::Search::BaseComponent::new
# File lib/opensearch/dsl/search/sort.rb, line 37 def initialize(*args, &block) @value ||= [] super end
Public Instance Methods
by(name, direction=nil)
click to toggle source
DSL
method to specify sorting item
@example
search do sort do by :category by :clicks, order: 'desc' end end
# File lib/opensearch/dsl/search/sort.rb, line 53 def by(name, direction=nil) @value << ( direction ? { name => direction } : name ) self end
empty?()
click to toggle source
Return whether the definition is empty
@return [Boolean]
# File lib/opensearch/dsl/search/sort.rb, line 78 def empty? to_hash.empty? end
to_hash()
click to toggle source
Convert the definition to a Hash
@return [Hash]
# File lib/opensearch/dsl/search/sort.rb, line 62 def to_hash if @block call unless @block_called @block_called = true else @value << @args if @args && !@args.empty? && ! @value.include?(@args) end @hash = @value.flatten @hash end