Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Hempel brianhempel

View GitHub Profile
View gist:745318
criteria.merge!( :_keywords => { :$in => words } )
search_result = collection.map_reduce(search_map(words), search_reduce, :query => criteria)
def search_reduce
"function( key , values ){return values[0];}"
end
def search_map(words)
#convert words into Regex OR
View gist:745312
criteria.merge!( :_keywords => { :$in => words } )
search_result = collection.map_reduce(search_map(words), search_reduce, {:query => criteria, :finalize => search_finalize})
def search_reduce
"function( key , values ){return { model: values[0]};}"
end
def search_finalize
"function( key , values ){return values.model;}"