gobigdave / simple_model_search
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Wed Feb 18 12:41:52 -0800 2009 | |
| |
README | Sat Aug 22 13:23:49 -0700 2009 | |
| |
Rakefile | Wed Feb 18 12:41:52 -0800 2009 | |
| |
init.rb | Wed Feb 18 12:41:52 -0800 2009 | |
| |
install.rb | Wed Feb 18 12:41:52 -0800 2009 | |
| |
lib/ | Sat Aug 22 13:23:49 -0700 2009 | |
| |
tasks/ | Wed Feb 18 12:41:52 -0800 2009 | |
| |
test/ | Wed Feb 18 12:41:52 -0800 2009 | |
| |
uninstall.rb | Wed Feb 18 12:41:52 -0800 2009 |
README
SimpleModelSearch
=================
Adds search method to ActiveRecord::Base.
The query language supports the operators (), not, and, or.
Precedence in that order.
- is an alias for not.
If no operator is present, and is assumed. Lastly, anything within double quotes is treated as a single search term.
For example,
ruby rails => records where both ruby and rails appear
"ruby on rails" => records where "ruby on rails" appears
ruby or rails => records where ruby or rails (or both) appears
ruby or chunky bacon => records where ruby appears or both chunky and bacon appear
not dead or alive => records where alive appears or dead is absent
-(ruby or rails) => records where neither ruby nor rails appears
(ruby or rails) -"ruby on rails" => records where ruby or rails appears but not the phrase "ruby on rails"
Adds several methods to all model objects.
def self.searches_on(*args)
Allow the user to set the default searchable fields.
By default, search will search all string and text fields. Use this to limit what is searched on.
def self.simple_search(text = nil, options = {})
Search the model's text and string fields
text = a set of words to search for
:only => an array of fields in which to search for the text;
default is 'all text or string columns'
:except => an array of fields to exclude
from the default searchable columns
:include => an array of tables to include in the joins. Fields that
have searchable text will automatically be included in the default
set of :search_columns.
:join_include => an array of tables to include in the joins, but only
for joining. (Searchable fields will not automatically be included.)
:conditions => a string of additional conditions (constraints)
:keywords => true if searches for keyword vs fragment. Default is false.
:order => sort order (order_by SQL snippet)
:page => page desired. use 0 to return everything. Defaults to 1.
returns WillPaginate::Collection
Query feature by Nate McNamara (nate@mcnamara.net)
Original TextSearch library by Duane Johnson.
Example
=======
Copyright (c) 2009 Dave Dupre, released under the MIT license
