Skip to content

Instantly share code, notes, and snippets.

@neumino
Last active December 31, 2015 04:59
Show Gist options
  • Save neumino/7938008 to your computer and use it in GitHub Desktop.
Save neumino/7938008 to your computer and use it in GitHub Desktop.
blazedd - IRC - 2013.12.12
r.table("users").filter( function(user) {
// map over all the keys of search
return r.expr(search).keys().map( function(key) {
// for each key, we return a boolean weather user(key) match search(key) (case insensitive)
return user(key).match( r.expr("(?i)").add(r.expr(search)(key)) ).ne(null)
}).reduce( function(left, right) { // Then for each boolean, we return left and right // so we perform a "and" operation here.
return left.and(right)
})
})
// To avoid manually the and, you can just look for false, and negate everything
var search={name: "michel"};r.table("users").filter( function(user) {
return r.expr(search).keys().map( function(key) {
return user(key).match( r.expr("(?i)").add(r.expr(search)(key)) ).ne(null)
}).contains(false).not()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment