public
Description: Rails plugin to add extra searching functionality to models.
Clone URL: git://github.com/ryanb/searchify.git
filling readme
Ryan Bates (author)
Wed Mar 19 11:21:09 -0700 2008
commit  6e27bb284c8da801b5f022329f389bed627369e4
tree    31d94447dd4dae743cad9791cd6a23ec7c640649
parent  90dfb66a77a8123172ab75fba3e1a39c410bc402
0
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
0
@@ -1,6 +1,74 @@
0
 Searchify
0
 =========
0
 
0
-This is a Rails plugin which will aid in adding searching functionality to models. It is in very early development.
0
+This is a Rails plugin which adds some search functionality to models. It also includes a javascript file and helper methods for building a dynamic search form.
0
+
0
+
0
+Installation
0
+------------
0
+
0
+If you are running edge rails you can install the plugin straight from the repository:
0
+
0
+ script/plugin install git://github.com/ryanb/searchify.git
0
+
0
+Otherwise you can install it with this command:
0
+
0
+ git clone --depth=1 git://github.com/ryanb/searchify.git vendor/plugins/searchify
0
+
0
+To use the dynamic form you need to install a javascript file using this command:
0
+
0
+ script/generate searchify_javascript
0
+
0
+
0
+Requirements
0
+------------
0
+
0
+This plugin uses the "paginate" method to perform a search on the model, so you need to install the will_paginate plugin/gem.
0
+
0
+Currently only MySQL is fully supported. It may work on other database engines, just not as well.
0
+
0
+
0
+Instructions
0
+------------
0
+
0
+You can use the "searchify" method in your model class to enable it for searching. Pass the columns you want to search to this method.
0
+
0
+ class Product < ActiveRecord::Base
0
+ searchify :name, :description, :price, :created_at, :discontinued
0
+ end
0
+
0
+You can then use the "search" method to search all or some of these columns. Here are some examples.
0
+
0
+ Product.search(:name => 'Puzzle', :description => '%forest%') # use percent sign for partial search
0
+ Product.search(:all => 'blue puzzle') # searches for partial word "blue" and "puzzle" in all columns
0
+ Product.search(:created_at_from => '2008-01-01', :created_at_to => '2008-02-01')
0
+ Product.search(:price_operator => '<', :price => '40') # changes the comparison operator
0
+ Product.search(:page => 5, :per_page => 20, :order => 'name') # pass other options besides conditions
0
+
0
+The searchify also allows you to include associations in the search. For example:
0
+
0
+ class Category < ActiveRecord::Base
0
+ has_many :products
0
+ searchify :name, :products => [:name, :description]
0
+ end
0
+
0
+To search the product columns you need to prefix them with "products_" like this:
0
+
0
+ Category.search(:products_name => 'Big Ben') # finds all categories with a product called Big Ben
0
+ Category.search(:all => 'puzzle') # product columns are included
0
+
0
+
0
+
0
+The main benefit of this plugin is how easy it is to add a dynamic search. You can use the searchify_fields_for helper method to generate dynamic fields for searching. Like this:
0
+
0
+ <% form_tag products_path, :method => 'get' do %>
0
+ <%= searchify_fields_for Product %>
0
+ <p><%= submit_tag 'Search', :name => nil, :onclick => 'return searchify_submit()' %></p>
0
+ <% end %>
0
+
0
+Make sure you have the prototype libraries included and it should allow you to dynamically add and remove fields. Pretty cool huh?
0
+
0
+
0
+---
0
 
0
 Copyright (c) 2008 Ryan Bates, released under the MIT license
0
...
2
3
4
 
...
2
3
4
5
0
@@ -2,3 +2,4 @@
0
 - allow override facet class
0
 - some way to add custom fields (for making a category select menu for example)
0
 - add support for other database engines (specifically regarding boolean fields)
0
+- add RDoc documentation into code

Comments

    No one has commented yet.