Skip to content

Instantly share code, notes, and snippets.

@prestonp
Created August 25, 2014 15:11
Show Gist options
  • Save prestonp/d28ef73a8ebbc79bea55 to your computer and use it in GitHub Desktop.
Save prestonp/d28ef73a8ebbc79bea55 to your computer and use it in GitHub Desktop.
mosql.registerConditionalHelper( '$matches', function( column, set, values, collection ) {
return column + ' @@ plainto_tsquery(' + set + ')';
});
mosql.registerConditionalHelper( '$partialMatches', function( column, set, values, collection ) {
// This breaks down a query for prefix matching.
// The limitation is it does not support spaces
// but rather & (AND) and | (OR) and ! (NOT).
// Ex to_tsquery('cat & hat & !ham') -- works
// to_tsquery('cat in the hat') -- error!
return column + ' @@ to_tsquery(' + set + '||\':*\')';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment