Skip to content

gnugeek/distilled_gin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distilled Gin

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.

What’s New

  • 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

Install

  • ./script/plugin install git://github.com/gnugeek/distilled_gin.git

Usage

Adding a gin full text index to a model

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

What this does:

(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>.

Searching for a model using the gin full text index

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

License

Copyright by Brian Knox, 2009. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

About

Activerecord extension for deploying and using full text indexes on PostgreSQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages