简体   繁体   中英

Search special characters with pg_search

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM