简体   繁体   English

使用pg_search搜索特殊字符

[英]Search special characters with pg_search

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.但我想搜索exaclty字,所以结果只有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无法实现你想做的pg_search

pg_search is based on PostgreSQL's Full Text Search. pg_search基于PostgreSQL的全文搜索。 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”和“#GT40”被索引到相同的词汇(这意味着您的搜索无法区分它们):

"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-full-text-search-part-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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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