Ultrasphinx
Ruby on Rails configurator and client to the Sphinx full text search engine.
== License
Copyright 2007 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. Some portions copyright Pat Allan, distributed under the MIT license, and used with permission. Some portions copyright PJ Hyett and Mislav Marohnić, distributed under the MIT license, and used with permission.
The public certificate for the gem is at http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem.
== Requirements
* MySQL 5.0, or PostgreSQL 8.2
* Sphinx 0.9.8-dev r871
* Rails 1.2.3
More recent versions than listed are ok.
== Features
Advanced Sphinx usage:
* searching and ranking across orthogonal models
* excerpt highlighting
* field weighting
* faceting on text, date, and numeric fields
ActiveRecord-style SQL generation:
* belongs_to and has_many includes
* field merging
* field aliasing
Good Rails integration:
* automatic memcached loads via cache_fu
* will_paginate compatibility
* query spellcheck
* Google-style query parser
* error recovery
* multiple deployment environments
* comprehensive Rake tasks
And some other things.
= Usage
== Installation
First, install Sphinx itself. Get the 0.9.8 development snapshot (http://www.sphinxsearch.com), then run ./configure, make, and sudo make install. Make sure to set your ./configure flags : --prefix if necessary, and also --with-pgsql if you need Postgres support.
You also need the chronic gem:
sudo gem install chronic
Then, install the plugin:
script/plugin install -x svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk
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
Now 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 live. Otherwise the new index will be installed but the daemon will remain stopped.
== Running queries
Query the daemon as so:
@search = Ultrasphinx::Search.new(:query => @query)
@search.run
@search.results
For more query options, including excerpt mode, see Ultrasphinx::Search.
= Extras
== 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
See RAKE_TASKS[link:files/RAKE_TASKS.html].
== Deployment notes
See DEPLOYMENT_NOTES[link:files/DEPLOYMENT_NOTES.html].
== A note about PostgreSQL
PostgreSQL 8.2 and higher are well supported. However, make sure you have executed CREATE LANGUAGE plpgsql; at least once. This step does not need to be repeated, so depending on your DB permissions, you might be able to put it in a migration.
== Reporting problems
* http://rubyforge.org/forum/forum.php?forum_id=14244
Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.
== Further resources
* http://blog.evanweaver.com/articles/2007/07/09/ultrasphinx-searching-the-world-in-231-seconds