public
Description: Generic support for extracting GMail-style search keywords/values from strings
Homepage: http://codefluency.rubyforge.org/keyword_search
Clone URL: git://github.com/bruce/keyword_search.git
Search Repo:
Move README
bruce (author)
Mon Mar 03 16:13:42 -0800 2008
commit  158a38410d0b281cd8d0e0160019bc0b8d1494fd
tree    994517864823266307bff9f6cefaac9dd03f833b
parent  a33479b476dc1cf96a75e80dd7c0d77bce9763ee
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -1 +1,92 @@
0
+keyword_search
0
+ http://codefluency.rubyforge.org/keyword_search
0
+ by Bruce Williams
0
+
0
+== DESCRIPTION:
0
+
0
+Generic library to parse GMail-style search strings for keyword/value pairs; supports definition of valid keywords and handling of quoted values.
0
+
0
+== FEATURES:
0
+
0
+The library features a very simple, easy-to-use API.
0
+* Define handlers for supported keywords with blocks
0
+* Define the default keyword (values not part of a keyword/value pair)
0
+
0
+Development Roadmap:
0
+2.0:: Add negation and grouping (will break API backwards compatibility)
0
+
0
+Note:: As of 1.3.0, input to KeywordSearch.search is no longer automatically downcased, allowing for case sensitive keyword and value pairs. If you want case insensitivity, downcase the input before you invoke the method.
0
+
0
+== SYNOPSIS:
0
+
0
+Here's an example of usage from Rails (though the library is generic, and could presumably be used for any Ruby project)
0
+
0
+ # Some variables to build up
0
+ clauses = []
0
+ arguments = []
0
+
0
+ # Search a string, defining the supported keywords and building up
0
+ # the variables in the associated closures
0
+
0
+ KeywordSearch.search('account has:attachment since:2006-12-03') do |with|
0
+
0
+ with.default_keyword :title
0
+
0
+ with.keyword :title do |values|
0
+ clauses << "title like ?"
0
+ arguments << "%#{values.join(' ')}%"
0
+ end
0
+
0
+ with.keyword :has do |values|
0
+ clauses << 'has_attachment = true' if values.include?('attachment')
0
+ end
0
+
0
+ with.keyword :since do |values|
0
+ date = Date.parse(values.first) # only support one
0
+ clauses << 'created_on >= ?'
0
+ arguments << date.to_s
0
+ end
0
+
0
+ end
0
+
0
+ # Do our search with <tt>clauses</tt> and <tt>arguments</tt>
0
+ conditions = [clauses.map{|c| "(#{c})"}.join(' AND ')), *arguments] # simplistic example
0
+ results = Message.find(:all, :conditions => conditions)
0
+
0
+== REQUIREMENTS:
0
+
0
+* hoe
0
+
0
+== INSTALL:
0
+
0
+sudo gem install keyword_search
0
+
0
+== LICENSE:
0
+
0
+(The MIT License)
0
+
0
+Copyright (c) 2007 Bruce Williams
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+'Software'), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
+
0
+== LEGAL NOTES
0
+
0
+GMail is copyright Google, Inc.
...
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,92 +1 @@
0
-keyword_search
0
- http://codefluency.rubyforge.org/keyword_search
0
- by Bruce Williams
0
-
0
-== DESCRIPTION:
0
-
0
-Generic library to parse GMail-style search strings for keyword/value pairs; supports definition of valid keywords and handling of quoted values.
0
-
0
-== FEATURES:
0
-
0
-The library features a very simple, easy-to-use API.
0
-* Define handlers for supported keywords with blocks
0
-* Define the default keyword (values not part of a keyword/value pair)
0
-
0
-Development Roadmap:
0
-2.0:: Add negation and grouping (will break API backwards compatibility)
0
-
0
-Note:: As of 1.3.0, input to KeywordSearch.search is no longer automatically downcased, allowing for case sensitive keyword and value pairs. If you want case insensitivity, downcase the input before you invoke the method.
0
-
0
-== SYNOPSIS:
0
-
0
-Here's an example of usage from Rails (though the library is generic, and could presumably be used for any Ruby project)
0
-
0
- # Some variables to build up
0
- clauses = []
0
- arguments = []
0
-
0
- # Search a string, defining the supported keywords and building up
0
- # the variables in the associated closures
0
-
0
- KeywordSearch.search('account has:attachment since:2006-12-03') do |with|
0
-
0
- with.default_keyword :title
0
-
0
- with.keyword :title do |values|
0
- clauses << "title like ?"
0
- arguments << "%#{values.join(' ')}%"
0
- end
0
-
0
- with.keyword :has do |values|
0
- clauses << 'has_attachment = true' if values.include?('attachment')
0
- end
0
-
0
- with.keyword :since do |values|
0
- date = Date.parse(values.first) # only support one
0
- clauses << 'created_on >= ?'
0
- arguments << date.to_s
0
- end
0
-
0
- end
0
-
0
- # Do our search with <tt>clauses</tt> and <tt>arguments</tt>
0
- conditions = [clauses.map{|c| "(#{c})"}.join(' AND ')), *arguments] # simplistic example
0
- results = Message.find(:all, :conditions => conditions)
0
-
0
-== REQUIREMENTS:
0
-
0
-* hoe
0
-
0
-== INSTALL:
0
-
0
-sudo gem install keyword_search
0
-
0
-== LICENSE:
0
-
0
-(The MIT License)
0
-
0
-Copyright (c) 2007 Bruce Williams
0
-
0
-Permission is hereby granted, free of charge, to any person obtaining
0
-a copy of this software and associated documentation files (the
0
-'Software'), to deal in the Software without restriction, including
0
-without limitation the rights to use, copy, modify, merge, publish,
0
-distribute, sublicense, and/or sell copies of the Software, and to
0
-permit persons to whom the Software is furnished to do so, subject to
0
-the following conditions:
0
-
0
-The above copyright notice and this permission notice shall be
0
-included in all copies or substantial portions of the Software.
0
-
0
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
-
0
-== LEGAL NOTES
0
-
0
-GMail is copyright Google, Inc.

Comments

    No one has commented yet.