Skip to content

Instantly share code, notes, and snippets.

@solisoft
Created July 9, 2010 14:56
Show Gist options
  • Save solisoft/469564 to your computer and use it in GitHub Desktop.
Save solisoft/469564 to your computer and use it in GitHub Desktop.
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