class Elasticsearch::DSL::Search::Sort

Wraps the `sort` part of a search definition

@see www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html

Public Class Methods

new(*args, &block) click to toggle source
# File lib/elasticsearch/dsl/search/sort.rb, line 29
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/elasticsearch/dsl/search/sort.rb, line 45
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/elasticsearch/dsl/search/sort.rb, line 70
def empty?
  to_hash.empty?
end
to_hash() click to toggle source

Convert the definition to a Hash

@return [Hash]

# File lib/elasticsearch/dsl/search/sort.rb, line 54
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