metaduck
28Set/090

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"'

About Pedro Teixeira

Pedro Teixeira is a former Enterprise Java Beans technical project manager for Clarity Europe (BES Tech Ventures). On 2004 he founded a services company ( http://berro.pt ), focused on the tourism industry throughout 2005-2008, briefly worked for http://www.expedita.com, shifted to product development on 2007, rebuilt http://netmadeira.com on 2009 for ZON Madeira. On early 2010 he started freelance work for Avallain, an e-Learning company strongly focused on delivering multi-media learning content and learning community expericences.
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.