Ultrasphinx plugin
Plugin details
Documentation
ruby script/plugin install svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk
You also need the chronic gem:
sudo gem install chronic
Next, copy the example/default.base file to RAILS_ROOT/config/ultrasphinx/default.base. This file sets up the Sphinx daemon options such as port, host, and index location.
If you need per-environment configuration, you can use RAILS_ROOT/config/ultrasphinx/development.base, etc.
Now, in your models, use the is_indexed method to configure a model as searchable. For example:
class Post is_indexed :fields => ["created_at", "title", "body"] end
For more index options, see ActiveRecord::Base .is_indexed.
== Building the index
Run:
rake ultrasphinx:configure rake ultrasphinx:index rake ultrasphinx:daemon:start
To rotate the index, just rerun rake ultrasphinx:index. If the search daemon is running, it will have its index rotated. Otherwise the new index will be installed but the daemon will remain stopped.
Make sure to manually stop and restart the daemon if you change the field configuration or model set. It will not reload the configuration file automatically.
== Running queries
Query the daemon as so:
@search = Ultrasphinx::Search.new(@query) @search.run @search.results
For more query options, including excerpt mode, see Ultrasphinx::Search.
== Pagination
Once the @search object has been run, it is directly compatible with the will_paginate view helper.
== Spell checking
See Ultrasphinx::Spell.
== Available Rake tasks
These rake tasks are made available to your Rails app:
ultrasphinx:configure - Rebuild the configuration file for this particular environment. ultrasphinx:index - Reindex the database and send an update signal to the search daemon. ultrasphinx:daemon:restart - Restart the search daemon. ultrasphinx:daemon:start - Start the search daemon. ultrasphinx:daemon:stop - Stop the search daemon. ultrasphinx:daemon:status - Check if the search daemon is running. ultrasphinx:spelling:build - Rebuild the custom spelling dictionary. You may need to use sudo if your Aspell folder is not writable by the app user. ultrasphinx:bootstrap - Bootstrap a full Sphinx environment by running configure, index, then daemon:start.
All tasks have shortcuts. Use us:conf, us:in, us:restart, us:start, us:stop, us:stat, us:spell, and us:boot.
== Further resources
* http://rubyforge.org/forum/forum.php?forum_id=14244
* http://blog.evanweaver.com/articles/2007/07/09/ultrasphinx-searching-the-world-in-231-seconds
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, over 3 years ago


