module Fuzzily::Model::ClassMethods::Rails3

Public Instance Methods

_add_fuzzy_scopes() click to toggle source
# File lib/fuzzily/model.rb, line 64
def _add_fuzzy_scopes
  scope :for_model,  lambda { |model|
    where(:owner_type => model.kind_of?(Class) ? model.name : model)
  }
  scope :for_field,  lambda { |field_name| where(:fuzzy_field => field_name) }
  scope :with_trigram, lambda { |trigrams| where(:trigram => trigrams) }
end
_matches_for_trigrams(trigrams) click to toggle source
# File lib/fuzzily/model.rb, line 56
def _matches_for_trigrams(trigrams)
  self.
    select('owner_id, owner_type, count(*) AS matches, MAX(score) AS score').
    group('owner_id, owner_type').
    order('matches DESC, score ASC').
    with_trigram(trigrams)
end