Sha256: ac73af39e6ee208210d06cfb5f12d55fa50f468ba5989312093db262b2b3d594

Contents?: true

Size: 548 Bytes

Versions: 5

Compression:

Stored size: 548 Bytes

Contents

module Searchkick
  module Similar

    def similar(options = {})
      like_text = self.class.searchkick_index.retrieve(self).to_hash
        .keep_if{|k,v| !options[:fields] || options[:fields].map(&:to_s).include?(k) }
        .values.compact.join(" ")

      # TODO deep merge method
      options[:where] ||= {}
      options[:where][:_id] ||= {}
      options[:where][:_id][:not] = id.to_s
      options[:limit] ||= 10
      options[:similar] = true
      self.class.send(Searchkick.search_method_name, like_text, options)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
searchkick-0.8.5 lib/searchkick/similar.rb
searchkick-0.8.4 lib/searchkick/similar.rb
searchkick-0.8.3 lib/searchkick/similar.rb
searchkick-0.8.2 lib/searchkick/similar.rb
searchkick-0.8.1 lib/searchkick/similar.rb