Class: RediSearch::Aggregate::Clauses::SortBy

Inherits:
RediSearch::ApplicationClause show all
Defined in:
lib/redi_search/aggregate/clauses/sort_by.rb

Defined Under Namespace

Classes: Sortable

Instance Method Summary collapse

Methods inherited from RediSearch::ApplicationClause

#clause_order, clause_order, clause_term

Methods included from Validatable

included, #validate!

Constructor Details

#initialize(fields:) ⇒ SortBy

Returns a new instance of SortBy.



26
27
28
29
30
31
32
33
# File 'lib/redi_search/aggregate/clauses/sort_by.rb', line 26

def initialize(fields:)
  @fields = fields.flat_map do |field|
    if field.is_a?(Hash) then field.map { |k, v| Sortable.new(k, v) }
    else
      Sortable.new(field)
    end
  end
end

Instance Method Details

#clauseObject



35
36
37
38
39
# File 'lib/redi_search/aggregate/clauses/sort_by.rb', line 35

def clause
  validate! && fields.each(&:validate!)

  ["SORTBY", fields.count * 2, *fields.flat_map(&:clause)]
end