# Capistrano and ferret

**URL:** <https://www.ruby-forum.com/t/capistrano-and-ferret/122465>\
**Category:** Deployment\
**Created:** [December 7, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/capistrano-and-ferret/122465 "2007-12-07T20:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 7, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/capistrano-and-ferret/122465/1 "2007-12-07T20:39:49Z")

</div>

Problem:

In my project, the /index directory, used by ferret, is not in the svn  
repository, for obvious reasons.

Every time I deploy, /index is gone, and the first user to run a search  
on the new deployment has a very… long… wait… ahead of them while  
the app re-indexes every searchable object in the db.

Solutions?

1. migrate the index directory over from the previous deployment.
2. somehow, get ferret to reindex during deployment:

- either by some magic method I don’t know about, calling  
“/browse/all” on my app, or some such.

What I want to know is… How can I solve this problem with Capistrano.  
(Surely it’s been dealt with dozens or hundreds of times before.)

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 7, 2007, 11:57pm UTC](https://www.ruby-forum.com/t/capistrano-and-ferret/122465/2 "2007-12-07T23:57:59Z")

</div>

Hello Robert,

> In my project, the /index directory, used by ferret, is not in the svn  
> repository, for obvious reasons.

I have this very same setup.

> Solutions?
> 
> 1. migrate the index directory over from the previous deployment.

This is the cleanest solution IMHO. Your second approach isn’t  
realistic when you’ll have millions of records to index! 😉 First, you  
should create an ‘index’ directory in the shared path. Then, add this  
to your deploy.rb:

namespace :deploy do  
task :before\_symlink do  
run “ln -fs #{shared\_path}/index #{release\_path}/index”  
end  
end

(I know, this the old callbacks syntax with Cap 2, I was experencing  
problems with the new syntax and haven’t retried since then. I’ll have  
to.)

Hope this helps,

Philippe

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 11, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/capistrano-and-ferret/122465/3 "2007-12-11T15:31:44Z")

</div>

Thanks so much for your guidance.

Philippe J. wrote:

> Your second approach isn’t  
> realistic when you’ll have millions of records to index!

I’ll need to re-index anytime a model changes in a ferret-relevant way,  
won’t I?

If so, should that be part of the migration process? (add\_column and  
then reindex every object of that type?)

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [December 20, 2007, 12:16am UTC](https://www.ruby-forum.com/t/capistrano-and-ferret/122465/4 "2007-12-20T00:16:44Z")

</div>

> namespace :deploy do  
> task :before\_symlink do  
> run “ln -fs #{shared\_path}/index #{release\_path}/index”  
> end  
> end
> 
> (I know, this the old callbacks syntax with Cap 2, I was experencing  
> problems with the new syntax and haven’t retried since then. I’ll have  
> to.)

Here is how to do that with the new style of callbacks in Cap 2

task :symlink\_index do  
run “ln -fs #{shared\_path}/index #{release\_path}/index”  
end

before ‘deploy:symlink’, :symlink\_index
