Sha256: becd395f57dab6cac741ab601956f852fbd5d84ca66ee73b59009b1c10c942c4

Contents?: true

Size: 816 Bytes

Versions: 7

Compression:

Stored size: 816 Bytes

Contents

module Elastic::Nodes
  class Sort < Base
    include Concerns::Sortable

    attr_accessor :child

    def add_score_sort(order: :desc)
      add_sort('_score', order: order)
    end

    def clone
      prepare_clone(super, child.try(:clone))
    end

    def simplify
      if registered_sorts.empty?
        child.try(:simplify)
      else
        prepare_clone(super, child.try(:simplify))
      end
    end

    def render(_options = {})
      hash = child.render(_options)
      hash['sort'] = render_sorts
      hash
    end

    def handle_result(_raw, _formatter)
      @child.handle_result(_raw, _formatter)
    end

    def traverse(&_block)
      super
      @child.traverse(&_block)
    end

    private

    def prepare_clone(_clone, _child)
      _clone.child = _child
      _clone
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elastic-rails-1.0.4 lib/elastic/nodes/sort.rb
elastic-rails-1.0.3 lib/elastic/nodes/sort.rb
elastic-rails-1.0.2 lib/elastic/nodes/sort.rb
elastic-rails-1.0.1 lib/elastic/nodes/sort.rb
elastic-rails-1.0.0 lib/elastic/nodes/sort.rb
elastic-rails-0.8.7 lib/elastic/nodes/sort.rb
elastic-rails-0.8.6 lib/elastic/nodes/sort.rb