0
+ http://codefluency.rubyforge.org/keyword_search
0
+Generic library to parse GMail-style search strings for keyword/value pairs; supports definition of valid keywords and handling of quoted values.
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
+2.0:: Add negation and grouping (will break API backwards compatibility)
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
+Here's an example of usage from Rails (though the library is generic, and could presumably be used for any Ruby project)
0
+ # Some variables to build up
0
+ # Search a string, defining the supported keywords and building up
0
+ # the variables in the associated closures
0
+ KeywordSearch.search('account has:attachment since:2006-12-03') do |with|
0
+ with.default_keyword :title
0
+ with.keyword :title do |values|
0
+ clauses << "title like ?"
0
+ arguments << "%#{values.join(' ')}%"
0
+ with.keyword :has do |values|
0
+ clauses << 'has_attachment = true' if values.include?('attachment')
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
+ # 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
+sudo gem install keyword_search
0
+Copyright (c) 2007 Bruce Williams
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
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
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
+GMail is copyright Google, Inc.
Comments
No one has commented yet.