Module: Fuzzily::Model::ClassMethods

Defined in:
lib/fuzzily/model.rb

Instance Method Summary collapse

Instance Method Details

#matches_for(text) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/fuzzily/model.rb', line 38

def matches_for(text)
  trigrams = Fuzzily::String.new(text).trigrams
  self.
    scoped(:select => 'owner_id, owner_type, count(*) AS matches, MAX(score) AS score').
    scoped(:group => 'owner_id, owner_type').
    scoped(:order => 'matches DESC, score ASC').
    with_trigram(trigrams).
    map(&:owner)
end