Capistrano deploying full text search on Rails using acts_as_xapian
acts_as_xapian is a rails plugin for Xapian, a full text search engine.
acts_as_xapian installs the search engine database inside the plugin directory, under xapiandbs. If you use Capistrano as a deployment tool and since the entire codebase is rewritten (including the plugin directory), you will have to rebuild the entire index every time you do a deployment.
What you need to do is to locate Xapian somewhere capistrano deployments will not overwrite.
Fortunately you can point the Xapian DB to somewhere else more convenient. Simply create a file under config/xapian.yml. Mine looks like this:
development:
base_db_path: xapian/database
staging:
base_db_path: xapian/database
production:
base_db_path: xapian/database
This is telling xapian on the development, staging and production environments to look for the database under the <RAILS_ROOT>/xapian/database.
You will have to create a folder under the deployment shared folder named "xapian/database".
Next you will have to tell Capistrano to relink <RAILS_ROOT>/xapian/database to this shared directory using a Capistrano hook:
after "deploy:symlink", "deploy:symlink_xapian_db"
...
namespace :deploy do
...
task :symlink_xapian_db do
xapian_database_path = 'xapian/database'
run "mkdir -p #{shared_path}/#{xapian_database_path}"
run "ln -sf #{shared_path}/xapian #{release_path}/xapian"
end
end
You will only have to build the index once using
'rake xapian:rebuild_index models="ModelName1 ModelName2"'