Class: OpenSearch::DSL::Search::Sort
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Sort
- Includes:
- BaseComponent
- Defined in:
- lib/opensearch/dsl/search/sort.rb
Overview
Wraps the ‘sort` part of a search definition
Instance Method Summary collapse
-
#by(name, direction = nil) ⇒ Object
DSL method to specify sorting item.
-
#empty? ⇒ Boolean
Return whether the definition is empty.
-
#initialize(*args, &block) ⇒ Sort
constructor
A new instance of Sort.
-
#to_hash ⇒ Hash
Convert the definition to a Hash.
Methods included from BaseComponent
Constructor Details
#initialize(*args, &block) ⇒ Sort
Returns a new instance of Sort.
37 38 39 40 |
# File 'lib/opensearch/dsl/search/sort.rb', line 37 def initialize(*args, &block) @value ||= [] super end |
Instance Method Details
#by(name, direction = nil) ⇒ Object
DSL method to specify sorting item
53 54 55 56 |
# File 'lib/opensearch/dsl/search/sort.rb', line 53 def by(name, direction=nil) @value << ( direction ? { name => direction } : name ) self end |
#empty? ⇒ Boolean
Return whether the definition is empty
78 79 80 |
# File 'lib/opensearch/dsl/search/sort.rb', line 78 def empty? to_hash.empty? end |
#to_hash ⇒ Hash
Convert the definition to a Hash
62 63 64 65 66 67 68 69 70 71 72 |
# 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 |