Index your DataMapper Models with Xapian

Still pretty preliminary, but the basics seem to work. dm-xapian is a Merb plugin to index your DataMapper models with Xapian

At this point the details are still sketchy, and you first need to install xapian, then the xapian ruby bindings: Install Xapian and ruby bindings

Then it gets easier:

* build the gem with
rake install
* add the dependency
dependencies "dm-xapian"
* create the dm-xapian resource
rake dm:autoupgrade
* tell dm-xapian to index your models (Er, Resources) with something like:

is_indexed :texts => [ :name, :region, :country, :varietal ],
:values => [[:price, 0, "price", :float], [:ean, 1, "ean", :string]],
:terms => [ [ :winery, 'W', "winery" ] ]

* build the index with
rake xapian:rebuild_index models="Wine Winery"
* build the index with
rake xapian:update_index models="Wine Winery"
This will remove from the index any model destroyed or update any model since the last call to xapian:rebuild_index or xapian:update_index
* Run a query
rake xapian:query query="edited 6" models="Wine Winery" verbose=true limit=25

Of course, running a query via rake is not so useful, but that’s all I tried so far. But at least this proved that the index was built correctly, and integrated search to an app is next.

As you may have noticed already, a big thing lacking at this point are specs.

This is in collaboration with Joshaven and based on the awesome work by Francis Irving on act_as_xapian who created the Rails+ActiveRecord version.