SearchableBy ============ Adds a search method to query your ActiveRecord models: searchable_by :field_a, :field_b, :field_etc YourModel.search 'some search words' Examples ======== # declare with searchable_by class User < ActiveRecord::Base enables the "search" method and by default searches 'login' and 'email' columns searchable_by :login, :email end # search into associations class User < ActiveRecord::Base has_many :addresses searchable_by :login, :email, :addresses => [:street, :city] end # simple search - based on default fields in searchable_by line User.search 'fred' => [#, #] # specify which fields to search on with :narrow_fields User.search 'fred', :narrow_fields => [:email, :login, :name] => [#, #, #] # use default search fields but pass other options User.search 'fred', :conditions => { :is_admin => true }, :limit => 2 => [#, #] # use :page option and we'll assume that you want to paginate using will_paginate User.search 'j', :page => 2 => [#, #, #, #, #] # by default, all search words must be found User.search 'fred john jack susan' => [] # set :require_all to false if you want to do an "OR" search User.search 'fred john jack susan', :require_all => false => [#, #, #, #, #] # use double quotes to identify phrases User.search '"fred flintstone"', :narrow_fields => [:login, :full_name] => [#] Copyright (c) 2008-2009 Jason LaPier, released under the MIT license