Sha256: f0737ac6c1947e7408832f8b6f2ad3ac3da3faaf5cb6b1e79f439e838e0bc5a2
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 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 Pollyanna is a gem, which you can install with sudo gem install pollyanna In Rails 2, add the following to your <tt>environment.rb</tt>: config.gem 'pollyanna' In Rails 3, add the following to your <tt>Gemfile</tt>: gem 'pollyanna' == Rails 3 compatibility We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released. == Credits Henning Koch {makandra.com}[http://makandra.com/] {gem-session.com}[http://gem-session.com/]
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pollyanna-1.0.4 | README.rdoc |