-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
40 lines (27 loc) · 1.44 KB
/
README
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
SearchScope
===========
A simple extension to ActiveRecord to allow scoped search. You can define a number search types that will use different selection of fields.
I wouldn't want to use this to build my google killer search engine on but might be useful for either:
* small apps / infrequently searched models
* placeholder search funtionality until you move up to proper fulltext search like hyperestraier, ferret, solr, sphinx etc...
Example
=======
class Hangup < ActiveRecord::Base
search_scope :default => :everything,
:types => {
:everything => [:inherited_from,:most_annoys,:name,:description],
:related_people => [:inherited_from,:most_annoys],
:name => [:name]
}
end
# Any hangups containing the text cleanliness
Hangup.search 'cleanliness'
# Search multiple terms - careful as you'll generate (number of terms) * (number of fields) SQL LIKE clauses
Hangup.search %w[stickers feathers]
# Any hangups that were either inherited from or annoy someone called mike
Hangup.search 'mike', :type => :related_people
# The above query will result in the following SQL being generated
SELECT * FROM `hangups` WHERE ((lower(`hangups`.`inherited_from`) like '%mike%' OR lower(`hangups`.`most_annoys`) like '%mike%'))
# Internally this uses named_scope so you can do all the cool stuff that allows
Hangup.search('teeth').find(:first, :order => :severity)
Copyright (c) 2009 Nick Sellen, released under the MIT license