I recently needed to re-index certain user records that had been
improperly indexed (see bug
http://projects.jkraemer.net/acts_as_ferret/ticket/220 for all the gory
details). A variation of the following code was used (conditions used to
select which users were removed to keep things simple):
users = User.find(:all, :select => ‘id’)
users.each do |u|
u.reload
u.ferret_update
end
While the sample size was smaller than that for a full re-index, the
indexing process with this approach appeared to run an order of
magnitude faster than User.rebuild_index. Does this seem possible? Not
sure if it’s a Rails thing (no batching, using reload v. find, something
else) or a Ferret thing (other than creating/moving the index file in
and out of place, what does rebuild_index do that I didn’t?) Is there
anything important that indexing in this matter skips? I looked at the
SQL in the Rails log and it appears that associations were retrieved and
indexed properly. Most importantly, our search seems to work fine. I’m
inclined to write a custom rake task to re-index our models in this
manner, am curious if there are compelling reasons not to.