Module: Fuzzily::Model::ClassMethods::Rails3
- Included in:
- Fuzzily::Model::ClassMethods
- Defined in:
- lib/fuzzily/model.rb
Instance Method Summary collapse
Instance Method Details
#_add_fuzzy_scopes ⇒ Object
64 65 66 67 68 69 70 |
# 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) ⇒ Object
56 57 58 59 60 61 62 |
# 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 |