module Fuzzily::Model::ClassMethods::Rails2
Public Instance Methods
_add_fuzzy_scopes()
click to toggle source
# File lib/fuzzily/model.rb, line 41 def _add_fuzzy_scopes named_scope :for_model, lambda { |model| { :conditions => { :owner_type => model.kind_of?(Class) ? model.name : model } }} named_scope :for_field, lambda { |field_name| { :conditions => { :fuzzy_field => field_name } }} named_scope :with_trigram, lambda { |trigrams| { :conditions => { :trigram => trigrams } }} named_scope :limit, lambda { |count| { :limit => count }} end
_matches_for_trigrams(trigrams)
click to toggle source
# File lib/fuzzily/model.rb, line 33 def _matches_for_trigrams(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) end