Active Search plugin
Plugin details
Documentation
ruby script/plugin install http://julik.textdriven.com/svn/tools/rails_plugins/simple_search
Setup indexing:
class BlogEntry < ActiveRecord::Base indexes_columns :except=>'date', :into=>'index', :including_associations=>false end
This will index all attributes of the entry (except the date and associated objects) into field called "index".
After you defined the column and reindexed the models you can do simple searches on your models. If you supply many terms they are going to be searched for with AND keyword:
entries = BlogEntry.find_using_term("Rails") entries = BlogEntry.find_using_term("Rails Foo Bar Baz")
However, this is not the only way to use ActiveSearch. Under the hood ActiveSearch uses a number of Indexers to perform searches. Every time you call the macro "indexes_columns" an ActiveSearch::Indexer is created on your model. You can get to these indexers via the Model.indexers method
Entry.indexers # => []
When you call find_using_term all of the indexers will be asked to search their indexes. If you want to be more specific and ask a special Indexer, you do it by addressing the indexers array directly and using the +query+ method:
Entry.indexers[0].query("Foo")
== Searching using LIKE (and indexing with ActiveSearch::LikeIndexer)
This is the simplest and default one. Use it when you have little tables (up to 500 records) or the queries will be highly scoped.
It works by pulling the index representation into a separate column of the model table itself and then issuing an inclusive LIKE query on them. Of course in this case you get no search rankings.
The :into option specifies the column that will hold the index text.
class Entry < ActiveRecord::Base indexes_columns :title, :body, :date, :using=>:like, :into=>'column_for_indexes' end
Also, plugin allows using a separate table to store search terms and allow integration with Ferret full-text search engine.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (3 older versions) | Last edited by: scott, 5 months ago

