使用pg_search搜索特殊字符

时间:2022-09-13 09:27:12

Im using

我使用

pg_search

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.

所以当我搜索“#GT40”时,pg_search的结果将是1和2。但是我想要搜索准确的单词,所以结果只有2。

Thanks!

谢谢!

1 个解决方案

#1


3  

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是不可能实现的呢?

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):

pg_search基于PostgreSQL的全文搜索。在控制台中的测试显示“GT40”和“#GT40”被索引到相同的lexeme(这意味着您的搜索无法区分它们):

"GT40":

“GT40”:

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

"#GT40":

“# 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

教程:http://shisaa.jp/postset/postgresql -满-文字-搜索- - 1. - html的一部分

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

PostgreSQL的全文搜索参考:http://www.postgresql.org/docs/9.1/static/textsearch.html。

#1


3  

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是不可能实现的呢?

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):

pg_search基于PostgreSQL的全文搜索。在控制台中的测试显示“GT40”和“#GT40”被索引到相同的lexeme(这意味着您的搜索无法区分它们):

"GT40":

“GT40”:

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

"#GT40":

“# 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

教程:http://shisaa.jp/postset/postgresql -满-文字-搜索- - 1. - html的一部分

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

PostgreSQL的全文搜索参考:http://www.postgresql.org/docs/9.1/static/textsearch.html。