Class: ActiveSearch::Result

Inherits:
Hash
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
lib/activesearch/result.rb

Constant Summary collapse

DEFAULT_HIGHLIGHT_RADIUS =
50

Instance Method Summary collapse

Constructor Details

#initialize(result, text, options = {}) ⇒ Result

Returns a new instance of Result.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/activesearch/result.rb', line 12

def initialize(result, text, options = {})
  locale = (options[:locale] || I18n.locale).to_s

  @text = text
  result.to_hash.each do |k,v|
    unless v.nil?
      self[k.to_s] = v.respond_to?(:has_key?) && v.has_key?(locale) ? v[locale] : v
    end
  end

  self.build_highlighted_fields(options[:radius])
end

Instance Method Details

#slice(*keys) ⇒ Object



25
26
27
# File 'lib/activesearch/result.rb', line 25

def slice(*keys)
  ::Hash.new.update(self).slice(*keys)
end