-
Notifications
You must be signed in to change notification settings - Fork 381
Open
Description
I'm trying to search for users based on either name or email address. As far as I can tell postgresql interprets the '@' symbol as a special character and breaks my search.
Here is my setup on the search:
pg_search_scope :search_by_name_and_email,
against: { name: "A", email: "B" },
using: { tsearch: { prefix: true }}
When I pass through a query of 'user@ex' I get the following sql:
SELECT "users".*, ((ts_rank((setweight(to_tsvector('simple', coalesce("users"."name"::text, '')), 'A') || setweight(to_tsvector('simple', coalesce("users"."email"::text, '')), 'B')), (to_tsquery('simple', ''' ' || 'user@ex' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "users" WHERE (((setweight(to_tsvector('simple', coalesce("users"."name"::text, '')), 'A') || setweight(to_tsvector('simple', coalesce("users"."email"::text, '')), 'B')) @@ (to_tsquery('simple', ''' ' || 'user@ex' || ' ''' || ':*')))) ORDER BY pg_search_rank DESC, "users"."id" ASC
It seems like postgresql is breaking up my query at the '@' token, based on the following:
select * from ts_parse('default', 'user@ex');
tokid | token
-------+-------
1 | user
12 | @
1 | ex
(3 rows)
select * from ts_debug('simple', 'user@ex');
alias | description | token | dictionaries | dictionary | lexemes
-----------+-----------------+-------+--------------+------------+---------
asciiword | Word, all ASCII | user | {simple} | simple | {user}
blank | Space symbols | @ | {} | |
asciiword | Word, all ASCII | ex | {simple} | simple | {ex}
(3 rows)
Should I be escaping my query in some way, or does pg_search simply not support searching by fields which contain an '@' symbol? (I'm guessing we would have the same problem with other 'special' characters in posgresql, such as '&', '|' or '_'.
Metadata
Metadata
Assignees
Labels
No labels