class Elastics::ActiveRecord::SearchResult
Public Class Methods
new(response, options = {})
click to toggle source
It expects `:model` option with a model-class. Optionally pass `scope` option with a lambda which takes and modifies relation.
Calls superclass method
# File lib/elastics/active_record/search_result.rb, line 7 def initialize(response, options = {}) @model = options[:model] @scope = options[:scope] super response, options end
Public Instance Methods
collection()
click to toggle source
# File lib/elastics/active_record/search_result.rb, line 18 def collection @collection ||= relation.find_all_ordered(ids_to_find, true) end
ids()
click to toggle source
super.map(&:to_i)
# File lib/elastics/active_record/search_result.rb, line 14 def ids @ids ||= hits['hits'.freeze].map { |x| x['_id'.freeze].to_i } end
relation()
click to toggle source
# File lib/elastics/active_record/search_result.rb, line 22 def relation @relation ||= begin result = @model.where(id: ids_to_find) @scope ? @scope.call(result) : result end end