Module: Searchkick::Similar

Defined in:
lib/searchkick/similar.rb

Instance Method Summary collapse

Instance Method Details

#similar(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/searchkick/similar.rb', line 4

def similar(options = {})
  like_text = self.class.searchkick_index.retrieve(document_type, id).to_hash
    .keep_if{|k,v| k[0] != "_" and (!options[:fields] or options[:fields].map(&:to_sym).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.search(like_text, options)
end