Distilled Gin is a rails plugin that is an extension of ActiveRecord::Base and ActiveRecord::Migration for working with PostgreSQL’s full text search engine.
-
Initial release - adds “add_gin_index” support to ActiveRecord::Migration (explained below)
-
2009-05-2 - adds “is_distillable” extension to ActiveRecord::Base to provide tsquery search support
-
./script/plugin install git://github.com/gnugeek/distilled_gin.git
class AddGin < ActiveRecord::Migration def self.up add_gin_index :table => :table_name, :columns => [:col1, :col2, :col3] end def self.down remove_gin_index :table => :table_name end end
(Please see the PostgreSQL Full Text Search documentation at www.postgresql.org/docs/8.3/static/textsearch.html)
This migration command will perform the following against <table_name>:
-
Add a column named <table_name>_tsv_idx of type tsvector to <table_name>.
-
Update the column to hold the output of a concatenation of to_tsvector run against all columns in the column list.
-
Create a gin index against the tsvector column.
-
Add an update trigger to the table to keep the tsvector column up to date
This migration is fully reversable with remove_gin_index <table_name>.
class MyModel < ActiveRecord::Base is_distillable end MyModel.with_tsquery('foo').find_all MyModel.with_tsquery('foo & bar').find_all MyModel.with_tsquery('(foo | bar) & baz').find_all
Copyright by Brian Knox, 2009. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.