public
Fork of bruce/keyword_search
Description: Generic support for extracting GMail-style search keywords/values from strings
Homepage: http://codefluency.rubyforge.org/keyword_search
Clone URL: git://github.com/technoweenie/keyword_search.git
Updated tests and README on case sensitivity

git-svn-id: 
svn+ssh://rubyforge.org/var/svn/codefluency/keyword_search/trunk@35 
a36c4c08-a44a-49c9-8a5d-6074d9d18ea7
wbruce (author)
Tue Oct 09 01:10:05 -0700 2007
commit  a33479b476dc1cf96a75e80dd7c0d77bce9763ee
tree    44254d1504740248694757a57295034d72fb0769
parent  f0cad1153e1f62e7b031b34140f1249fd2e8a55d
...
 
 
 
 
1
2
3
4
5
 
6
7
 
8
9
10
...
1
2
3
4
5
6
7
 
 
8
9
 
10
11
12
13
0
@@ -1,10 +1,13 @@
0
+= 1.3.1 / 2007-10-09
0
+
0
+* Tests/README update for case sensitivity change
0
+
0
 = 1.3.0 / 2007-10-09
0
 
0
 * Conversion to Ragel-based parser (faster, less resource-intensive)
0
-* Better support for other character sets, allow apostrophes in
0
- unquoted words
0
+* Better support for other character sets, allow apostrophes in unquoted words
0
 * Test suite now uses test/spec
0
-* API Should be backwards compatible
0
+* API is almost backwards compatible (though keywords/values are now case sensitive; downcase the input manually if you want the old behavior)
0
 
0
 = 1.2.0 / 2007-05-09
0
 
...
6
7
8
9
 
10
11
12
13
14
15
16
17
18
19
20
21
 
 
22
23
24
...
6
7
8
 
9
10
11
12
13
14
 
 
 
 
15
16
17
18
19
20
21
22
0
@@ -6,19 +6,17 @@ keyword_search
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/PROBLEMS:
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
-Various notes:
0
-* Quoted values are supported.
0
-* Input is automatically downcased (both keywords and values should be assumed to be in lowercase)
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)
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@
0
 require 'rubygems'
0
 require 'hoe'
0
 
0
-Hoe.new('keyword_search', '1.3.0') do |p|
0
+Hoe.new('keyword_search', '1.3.1') do |p|
0
   p.rubyforge_name = 'codefluency'
0
   p.summary = 'Generic support for extracting GMail-style search keywords/values from strings'
0
   p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
...
7
8
9
10
 
 
11
12
13
...
31
32
33
34
35
 
 
 
36
37
38
...
97
98
99
100
101
102
 
 
 
103
104
105
...
121
122
123
124
 
125
126
127
128
129
 
130
131
 
132
133
134
135
136
137
 
138
139
 
140
141
142
...
235
236
237
238
 
 
 
 
 
 
 
 
 
 
 
239
240
241
242
 
 
243
244
245
...
251
252
253
254
 
255
256
257
 
 
 
 
 
258
259
260
...
7
8
9
 
10
11
12
13
14
...
32
33
34
 
 
35
36
37
38
39
40
...
99
100
101
 
 
 
102
103
104
105
106
107
...
123
124
125
 
126
127
128
129
130
131
132
133
 
134
135
136
137
138
139
 
140
141
 
142
143
144
145
...
238
239
240
 
241
242
243
244
245
246
247
248
249
250
251
252
253
 
 
254
255
256
257
258
...
264
265
266
 
267
268
 
 
269
270
271
272
273
274
275
276
0
@@ -7,7 +7,8 @@ module KeywordSearch
0
       
0
   class << self
0
   
0
- # line 44 "lib/keyword_search.rl"
0
+ # line 48 "lib/keyword_search.rl"
0
+
0
     
0
     def search(input_string, definition=nil, &block)
0
       definition ||= Definition.new(&block)
0
@@ -31,8 +32,9 @@ class << self
0
   private :_parser_actions, :_parser_actions=
0
 end
0
 self._parser_actions = [
0
- 0, 1, 3, 1, 4, 2, 0, 2,
0
- 2, 1, 0
0
+ 0, 1, 3, 1, 5, 1, 6, 2,
0
+ 0, 2, 2, 1, 0, 3, 0, 2,
0
+ 4, 3, 1, 0, 4
0
 ]
0
 
0
 class << self
0
@@ -97,9 +99,9 @@ class << self
0
   private :_parser_trans_actions_wi, :_parser_trans_actions_wi=
0
 end
0
 self._parser_trans_actions_wi = [
0
- 5, 3, 5, 5, 3, 5, 1, 0,
0
- 0, 0, 0, 8, 8, 0, 8, 1,
0
- 0, 0, 0, 0, 0, 1, 0, 0,
0
+ 7, 5, 13, 13, 5, 7, 1, 0,
0
+ 0, 0, 0, 17, 17, 0, 10, 1,
0
+ 0, 0, 0, 3, 0, 1, 0, 3,
0
   0, 1, 0, 0, 0, 0
0
 ]
0
 
0
@@ -121,22 +123,23 @@ class << self
0
 end
0
 self.parser_en_main = 1;
0
 
0
-# line 62 "lib/keyword_search.rl"
0
+# line 66 "lib/keyword_search.rl"
0
       p = 0
0
       pe = data.length
0
       key = nil
0
       tokstart = nil
0
       results = {}
0
+ quotes = 0
0
       
0
-# line 133 "lib/keyword_search.rb"
0
+# line 135 "lib/keyword_search.rb"
0
 begin
0
   p ||= 0
0
   pe ||= data.length
0
   cs = parser_start
0
 end
0
-# line 68 "lib/keyword_search.rl"
0
+# line 73 "lib/keyword_search.rl"
0
       
0
-# line 141 "lib/keyword_search.rb"
0
+# line 143 "lib/keyword_search.rb"
0
 begin
0
   _klen, _trans, _keys, _acts, _nacts = nil
0
   if p != pe
0
@@ -235,11 +238,21 @@ when 3:
0
           end
0
 # line 26 "lib/keyword_search.rl"
0
 when 4:
0
-# line 42 "lib/keyword_search.rl"
0
+# line 32 "lib/keyword_search.rl"
0
+ begin
0
+ quotes += 1 end
0
+# line 32 "lib/keyword_search.rl"
0
+when 5:
0
+# line 34 "lib/keyword_search.rl"
0
+ begin
0
+ quotes -= 1 end
0
+# line 34 "lib/keyword_search.rl"
0
+when 6:
0
+# line 46 "lib/keyword_search.rl"
0
     begin
0
  raise ParseError, "At offset #{p}, near: '#{data[p,10]}'"     end
0
-# line 42 "lib/keyword_search.rl"
0
-# line 244 "lib/keyword_search.rb"
0
+# line 46 "lib/keyword_search.rl"
0
+# line 256 "lib/keyword_search.rb"
0
     end # action switch
0
   end
0
   end while false
0
@@ -251,10 +264,13 @@ when 4:
0
   end
0
   end
0
   end
0
-# line 69 "lib/keyword_search.rl"
0
+# line 74 "lib/keyword_search.rl"
0
       
0
-# line 258 "lib/keyword_search.rb"
0
-# line 70 "lib/keyword_search.rl"
0
+# line 270 "lib/keyword_search.rb"
0
+# line 75 "lib/keyword_search.rl"
0
+ unless quotes.zero?
0
+ raise ParseError, "Unclosed quotes"
0
+ end
0
       results
0
     end
0
     
...
176
177
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180
181
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
0
@@ -176,6 +176,30 @@ context "KeywordSearch" do
0
       end
0
     end
0
   end
0
+
0
+ specify "keywords are case sensitive" do
0
+ result = nil
0
+ KeywordSearch.search(%<Text:justtesting>) do |with|
0
+ with.keyword :text do |values|
0
+ result = :small
0
+ end
0
+ with.keyword :Text do |values|
0
+ result = :big
0
+ end
0
+ end
0
+ assert_equal :big, result
0
+ end
0
+
0
+ specify "values are case sensitive" do
0
+ result = nil
0
+ KeywordSearch.search(%<text:Big>) do |with|
0
+ with.keyword :text do |values|
0
+ result = values.first
0
+ end
0
+ end
0
+ assert_equal 'Big', result
0
+ end
0
+
0
 end
0
 
0
 

Comments

    No one has commented yet.