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 Dmytro Shteflyuk and Alexey Kovyrin, distributed under the Ruby 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 (or Postgres, experimental)
* Sphinx 0.97 or greater
* Rails 1.2.3 or greater

== 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:
* <tt>belongs_to</tt> and <tt>has_many</tt> includes
* field merging
* field aliasing

Good Rails integration:
* automatic memcached loads via <tt>cache_fu</tt>
* <tt>will_paginate</tt> compatibility
* query spellcheck
* Google-style query parser
* temporary error recovery
* multiple deployment environments
* comprehensive Rake tasks

And some other things.

= Usage

== Installation
  
First, compile and install Sphinx itself (http://www.sphinxsearch.com). 

You also need the <tt>chronic</tt> gem:
  sudo gem install chronic

Then, install the plugin:
  script/plugin install -x svn://rubyforge.org/var/svn/fauna/ultrasphinx/trunk
 
Next, copy the <tt>example/default.base</tt> file to <tt>RAILS_ROOT/config/ultrasphinx/default.base</tt>. This file sets up the  Sphinx daemon options such as port, host, and index location.
  
If you need per-environment configuration, you can use <tt>RAILS_ROOT/config/ultrasphinx/development.base</tt>, etc. 

Now, in your models, use the <tt>is_indexed</tt> 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 <tt>rake ultrasphinx:index</tt>. 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 => @query)
  @search.run
  @search.results
  
For more query options, including excerpt mode, see Ultrasphinx::Search.
  
= Extras  

== Pagination

Once the <tt>@search</tt> object has been <tt>run</tt>, it is directly compatible with the <tt>will_paginate</tt> view helper.
  
== Spell checking

See Ultrasphinx::Spell.
  
== Available Rake tasks

These Rake tasks are made available to your Rails app:

<tt>ultrasphinx:configure</tt>:: Rebuild the configuration file for this particular environment.
<tt>ultrasphinx:index</tt>:: Reindex the database and send an update signal to the search daemon.
<tt>ultrasphinx:daemon:restart</tt>:: Restart the search daemon.
<tt>ultrasphinx:daemon:start</tt>:: Start the search daemon.
<tt>ultrasphinx:daemon:stop</tt>:: Stop the search daemon.
<tt>ultrasphinx:daemon:status</tt>:: Check if the search daemon is running.
<tt>ultrasphinx:spelling:build</tt>:: Rebuild the custom spelling dictionary. You may need to use <tt>sudo</tt> if your Aspell folder is not writable by the app user.
<tt>ultrasphinx:bootstrap</tt>:: Bootstrap a full Sphinx environment by running configure, index, then daemon:start.

All tasks have shortcuts. Use <tt>us:conf</tt>, <tt>us:in</tt>, <tt>us:restart</tt>, <tt>us:start</tt>, <tt>us:stop</tt>, <tt>us:stat</tt>, <tt>us:spell</tt>, and <tt>us:boot</tt>.

== 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