Further documentation available at:
Texticle exposes full text search capabilities from PostgreSQL, extending ActiveRecord with scopes making search easy and fun!
Only works with PostgreSQL
In the project's Gemfile add
gem 'texticle', '~> 2.0', :require => 'texticle/rails'
ActiveRecord outside of Rails 3
require 'texticle' ActiveRecord::Base.extend(Texticle)
Your models now have access to the search method:
Game.search('Sonic') # will search through the model's :string columns Game.search(:title => 'Mario') Game.search_by_title('Street Fighter').search_by_system('PS3') Game.search_by_title_and_system('Final Fantasy', 'PS2') Game.search_by_title_or_system('Final Fantasy, 'PS3')
To set proper searchig dictionary just override class method on your model:
def self.searchable_language 'russian' end
And all your queries would go right! And don`t forget to change the migration for indexes, like shown below.
Creating Indexes for Super Speed
You can have Postgresql use an index for the full-text search. To declare a full-text index, in a migration add code like the following:
execute " create index on email_logs using gin(to_tsvector('english', subject)); create index on email_logs using gin(to_tsvector('english', email_address));"
In the above example, the table email_logs has two text columns that we search against, subject and email_address. You will need to add an index for every text/string column you query against, or else Postgresql will revert to a full table scan instead of using the indexes.
gem install texticle
(The MIT License)
Copyright © 2011 Aaron Patterson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.