| Path: | README |
| Last Update: | Wed Nov 05 22:02:31 +0400 2008 |
SimplySearchable is a search plugin created by Rida Al Barazi to be used in SpinBits Skeleton App.
The main goal of SimplySearchable is to make it easy to do queries on your model by auto-magically creating some named_scope methods for common conditions, it adds a method to the model named "list" that will find and filter records smartly.
Please submit your bugs, requests and feedback at the project's page on Lighthouse.
If you have the following attributes in you posts table:
Post
id:integer
title:string
body:text
created_at:datetime
updated_at:datetime
In your Model:
class Post < ActiveRecord::Base
has_many :comments
belongs_to :category
simply_searchable
end
This will create the following named scopes:
named_scope where_id, lambda {|value| { :conditions => ["id = ?", value] }}
named_scope where_title, lambda {|value| { :conditions => ["title like ?", "%#{value}%"] }}
named_scope where_body, lambda {|value| { :conditions => ["body like ?", "%#{value}%"] }}
named_scope where_created_at, lambda {|value| { :conditions => ["created_at = ?", value] }}
named_scope where_updated_at, lambda {|value| { :conditions => ["updated_at = ?", value] }}
named_scope where_categories, lambda {|value| { :conditions => ["category_id in (?)", [*value]] }}
named_scope where_comments, lambda {|value| { :conditions => ["comments.ids in (?)", [*value]] }}
It will also create the method ‘list’ which you can use like:
Post.list(:title => 'abc', :created_at => Date.today, :category => [1,3])
Which will return the posts that contain ‘abc’ in their title and created today from categories 1 and 3.
By default SimplySearchable list will_paginate, you can still disable it:
class Post < ActiveRecord::Base
simply_searchable :will_paginate => false
end
Or customize its settings:
class Post < ActiveRecord::Base
simply_searchable :per_page => 20
end
In the new implementation there is no support for associations’ filtering yet, it will come very soon though so stay tuned.