Sha256: 26c454b9f0c0fedd08047968d57bc6190ad61edfd241728f4c3d29dcb200823c

Contents?: true

Size: 813 Bytes

Versions: 8

Compression:

Stored size: 813 Bytes

Contents

module Searchkick
  class Results < Tire::Results::Collection

    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

    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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
searchkick-0.5.3 lib/searchkick/results.rb
searchkick-0.5.2 lib/searchkick/results.rb
searchkick-0.5.1 lib/searchkick/results.rb
searchkick-0.5.0 lib/searchkick/results.rb
searchkick-0.4.2 lib/searchkick/results.rb
searchkick-0.4.1 lib/searchkick/results.rb
searchkick-0.3.5 lib/searchkick/results.rb
searchkick-0.3.4 lib/searchkick/results.rb