Jens Krämer

Faster indexing with acts_as_ferret

 |  ferret, ruby, rails

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) </code>

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

Bojan Mihelac

Hi Jens,
does it make sense to call disable_ferret from enironment.rb to stop automatic indexing?

jk

Yes, doing so will stop acts_as_ferret from indexing any new or changed records.