Sha256: 85d3dcf0933cc6eba27ca881ca0137d57c42deaca8231802a6935035ee091fce

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

= Pollyanna - very simple search for your ActiveRecord models

Pollyanna adds a very simple full text search to your ActiveRecord models.
Before saving, searchable models copy strings relevant to the search into a text column.
Pollyanna finds results for a query using LIKE patterns in SQL.

We found Pollyanna very useful for search-as-you-type boxes.

== Example 

    class Movie < ActiveRecord::Base
      include Pollyanna::Searchable

      def search_text
        "#{title} #{year} #{director}"
      end

    end

    class MoviesController

      def index
        @movies = Movie.search(params[:query])
      end

    end

== Making a model searchable

1. Add a text column "search_text" to a model
2. Have the model include <tt>Pollyanna::Searchable</tt>
3. Overwrite <tt>search_text</tt> to define which text is indexed upon saving
4. <tt>Model.search("query goes here")</tt> now gives you a scope for the results of your query. Blank queries return everything.

== Searching other columns

If you want to search a column other than <tt>search_text</tt>, you may say <tt>Movie.search(query, :by => "other_column")</tt>.

== How queries are matched

- Pollyanna matches partial words, so "oo" matches "foo".
- Multiple words in a query are AND-ed automatically.

== Installation

Add the following to your <tt>Initializer.run</tt> block in your <tt>environment.rb</tt>:
    config.gem 'pollyanna', :source => 'http://gemcutter.org'
Then do a 
    sudo rake gems:install

Alternatively, use
    sudo gem sources -a http://gemcutter.org
    sudo gem install pollyanna

== Credits

Henning Koch

{www.makandra.de}[http://www.makandra.de/]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pollyanna-1.0.3 README.rdoc