Created
July 9, 2010 14:56
-
-
Save solisoft/469564 to your computer and use it in GitHub Desktop.
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
module MongoMapper | |
module Plugins | |
module Querying | |
module ClassMethods | |
def search(fields, words, conditions = {}, options = {}) | |
filters = [] | |
fields = fields.split(",").map {|l| l.strip } if fields.class.to_s == "String" | |
words.split(" ").each do |word| | |
ftemp = [] | |
fields.each {|field| ftemp << "(String(this.#{field}).replace('null', '').match(/#{word}/i))" } | |
filters << "(#{ftemp * " || "})" | |
end | |
filters = filters * " && " | |
all({:conditions => { "$where" => filters }.merge(conditions) }.merge(options)) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment