# Simple, fast indexing script v. rebuild\_index

**URL:** <https://www.ruby-forum.com/t/simple-fast-indexing-script-v-rebuild-index/139509>\
**Category:** Ferret\
**Created:** [June 4, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/simple-fast-indexing-script-v-rebuild-index/139509 "2008-06-04T16:38:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thornett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@thornett](https://www.ruby-forum.com/u/thornett)\
**Post date:** [June 4, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/simple-fast-indexing-script-v-rebuild-index/139509/1 "2008-06-04T16:38:33Z")

</div>

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](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.
