Created
September 26, 2011 23:41
-
-
Save batasrki/1243780 to your computer and use it in GitHub Desktop.
Weirdly named method
This file contains 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
module Util | |
def gen_dyn_search(str, search_list) | |
return "true" if str.blank? | |
terms = str.split(/\s/) | |
sql = "" | |
terms.each do |term| | |
sql += (sql!="")? " AND (" : "(" | |
inner_sql = "" | |
search_list.each do |item| | |
inner_sql += (inner_sql!="")? " OR " : "" | |
inner_sql += "("+item+" LIKE '%"+term+"%')" | |
end | |
sql += inner_sql + ")" | |
end | |
sql | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment