sql - ActiveRecord regular-expression search by whole word -


i want search activerecord model product keyword, want match whole words in description instead of arbitrary substrings.

say have string

'the packaging may vary' 

as product's description, search using keyword 'aging' should not match, search 'packaging' should match. match words, beginning or end of string. want this:

product.where("description ~* ?", "regexp") 

what should replace regexp with, "%[^|| ]#{string}[$|| ]%"?

product.where("description ~* ?", "\m#{string}\m") 

\m matches @ beginning of word , \m matches @ end of word. more info here: http://www.postgresql.org/docs/9.0/static/functions-matching.html


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -