Class: Searchkick::Results

Inherits:
Tire::Results::Collection
  • Object
show all
Defined in:
lib/searchkick/results.rb

Instance Method Summary collapse

Instance Method Details

#__find_records_by_ids(klass, ids) ⇒ Object

fixes deprecation warning



23
24
25
# File 'lib/searchkick/results.rb', line 23

def __find_records_by_ids(klass, ids)
  @options[:load] === true ? klass.find(ids) : klass.includes(@options[:load][:include]).find(ids)
end

#suggestionsObject



4
5
6
7
8
9
10
# File 'lib/searchkick/results.rb', line 4

def suggestions
  if @response["suggest"]
    @response["suggest"].values.flat_map{|v| v.first["options"] }.sort_by{|o| -o["score"] }.map{|o| o["text"] }.uniq
  else
    raise "Pass `suggest: true` to the search method for suggestions"
  end
end

#with_detailsObject



12
13
14
15
16
17
18
19
20
# File 'lib/searchkick/results.rb', line 12

def with_details
  each_with_hit.map do |model, hit|
    details = {}
    if hit["highlight"]
      details[:highlight] = Hash[ hit["highlight"].map{|k, v| [k.sub(/\.analyzed\z/, "").to_sym, v.first] } ]
    end
    [model, details]
  end
end