Created
November 4, 2009 09:40
-
-
Save madx/225917 to your computer and use it in GitHub Desktop.
Transform a text query to a Sequel filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_filter(query) | |
query.split(/ +/).map { |chunk| | |
case chunk | |
when /^by:(.+)/ | |
{:author => $~[1]} | |
when /^is:(.+)/ | |
{:status => $~[1]} | |
else | |
:title.like("%#{chunk}%") | |
end | |
}.inject(:ctime) {|f,e| e & f } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment