Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Fixes #11.
Browse files Browse the repository at this point in the history
  • Loading branch information
mezis committed Aug 30, 2013
1 parent 40ff2b7 commit 2c032f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/fuzzily/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def make_field_fuzzily_searchable(field, options={})

trigram_class.transaction do
batch.each { |record| record.send(trigram_association).delete_all }

return if inserts.empty?

if supports_bulk_inserts
trigram_class.connection.insert(insert_sql + inserts.join(", "))
else
Expand Down
2 changes: 1 addition & 1 deletion lib/fuzzily/trigram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Fuzzily
class String < SimpleDelegator

def trigrams
return [] if __getobj__.nil?
normalized = self.normalize
number_of_trigrams = normalized.length - 3
trigrams = (0..number_of_trigrams).map { |index| normalized[index,3] }.uniq
Expand All @@ -18,7 +19,6 @@ def scored_trigrams
# Remove accents, downcase, replace spaces and word start with '*',
# return list of normalized words
def normalize
# Iconv.iconv('ascii//translit//ignore', 'utf-8', self).first.
ActiveSupport::Multibyte::Chars.new(self).
mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/,'').downcase.to_s.
gsub(/[^a-z]/,' ').
Expand Down

0 comments on commit 2c032f9

Please sign in to comment.