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

Commit

Permalink
Adds compatibility with SQLite < 3.7.11
Browse files Browse the repository at this point in the history
  • Loading branch information
mezis committed Jul 13, 2013
1 parent eee3f2a commit 10b71e0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/fuzzily/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def fuzzily_searchable(*fields)
def make_field_fuzzily_searchable(field, options={})
class_variable_defined?(:"@@fuzzily_searchable_#{field}") and return

trigram_class_name = options.fetch(:class_name, 'Trigram')
trigram_association = "trigrams_for_#{field}".to_sym
trigram_class_name = options.fetch(:class_name, 'Trigram')
trigram_association = "trigrams_for_#{field}".to_sym
update_trigrams_method = "update_fuzzy_#{field}!".to_sym
batch_size = fuzzily_batch_size

has_many trigram_association,
:class_name => trigram_class_name,
Expand Down Expand Up @@ -46,7 +47,7 @@ def make_field_fuzzily_searchable(field, options={})
singleton_class.send(:define_method,"bulk_update_fuzzy_#{field}".to_sym) do
trigram_class = trigram_class_name.constantize

self.scoped(:include => trigram_association).find_in_batches(:batch_size => 100) do |batch|
self.scoped(:include => trigram_association).find_in_batches(:batch_size => batch_size) do |batch|
inserts = []
batch.each do |record|
data = Fuzzily::String.new(record.send(field))
Expand Down Expand Up @@ -92,5 +93,14 @@ def make_field_fuzzily_searchable(field, options={})
self
end

def fuzzily_batch_size
if connection.kind_of?(ActiveRecord::ConnectionAdapters::SQLiteAdapter) &&
connection.send(:sqlite_version) < '3.7.11'
1
else
100
end
end

end
end

0 comments on commit 10b71e0

Please sign in to comment.