Impressum / Imprint

Faster indexing with acts_as_ferret

Posted on September 02, 2007

Does your application operate on large chunks of records that are indexed by acts_as_ferret? If the answer is yes, then this is for you:

By combining two brand new features of acts_as_ferret you may now speed up batch operations like this: First, disable acts_as_ferret indexing for the model class in question. Then do your updates, but be sure to remember the primary keys of the modified records. After that, re-enable acts_as_ferret and index all modified or created records at once:

Model.disable_ferret
# create or modify records here, collect ids in id_array
Model.enable_ferret
Model.bulk_index(id_array)

You may also use the block syntax to have aaf be re-enabled automatically:

id_array = []
Model.disable_ferret do
  # create or modify records here, collect ids in id_array
end
Model.bulk_index(id_array)
Comments
  1. Bojan MihelacSeptember 05, 2007 @ 11:27 AM
    Hi Jens, does it make sense to call disable_ferret from enironment.rb to stop automatic indexing?
  2. jkSeptember 09, 2007 @ 05:28 PM
    Yes, doing so will stop acts_as_ferret from indexing any new or changed records.