Reputation: 1216
Does gem pg_serch supports search by regex, if yes could someone give an example of using regular expressions with pg_search. I could not find it in the documentation. I am looking for something like this
Model.regex_search(/.*find_string$/)
is it possible with pg_search?
Upvotes: 2
Views: 351
Reputation: 1599
No it doesn't, nor should it.
pg_search
utilizes Postgres' full text search extension, so it is already, in a way, doing regex searches on indexed data.
If you want to do a pure regex search against text data in your table, you should use PG's pattern matching. You can use the operators ~
(case sensitive) and ~*
(case insensitive) within WHERE
clauses to match against a POSIX regular expression.
Model.where("column ~* ?", "regex")
If you intend on doing this, I highly recommend that you create indexes on those columns.
Upvotes: 2