Search special characters with pg_search

704 views Asked by At

Im using

pg_search

And trying to search in the title for a special character.

For example, I have two rows with this information:

id    title
1     GT40
2     #GT40

So when I search "#GT40", the result with pg_search will be 1 and 2. But I want to search exaclty word, so the result will be only 2.

Thanks!

1

There are 1 answers

0
garbo999 On BEST ANSWER

I tried to write a comment but my reputation is not high enough yet. But maybe what you are trying to do is not possible with pg_search?

pg_search is based on PostgreSQL's Full Text Search. Testing in the console shows that "GT40" and "#GT40" are indexed to the same lexeme (which means your searches can't tell them apart):

"GT40":

=# SELECT to_tsvector('english', 'GT40');
 to_tsvector 
-------------
 'gt40':1
(1 row)

"#GT40":

=# SELECT to_tsvector('english', '#GT40');
 to_tsvector 
-------------
 'gt40':1
(1 row)

Here is some reference info that might be helpful:

Tutorial: http://shisaa.jp/postset/postgresql-full-text-search-part-1.html

PostgreSQL's Full Text Search Reference: http://www.postgresql.org/docs/9.1/static/textsearch.html