PostgreSQL全文搜索和保留字,保留一些单词

Ada*_*iak 5 postgresql full-text-search tsvector

我正在使用 Postgresql 和英语字典进行完整的测试搜索。当我想接收带有一些英语单词的记录时,我得到了真实的结果。

所以:

SELECT id FROM table1 WHERE ts_vector1 @@ to_tsquery('it')
Run Code Online (Sandbox Code Playgroud)

返回 0 个结果。

SELECT id FROM table1 WHERE ts_vector1 @@ to_tsquery('specialist & it')
Run Code Online (Sandbox Code Playgroud)

返回超过 0 个结果(表和索引中存在单词“it”)。ts_vector1 创建如下:

ts_vector1 = to_tsvector('english', some_text_column)
Run Code Online (Sandbox Code Playgroud)

“it”是保留词吗?如果是这样,“转义”保留字的最佳方法是什么?

Den*_*rdy 5

根据相关文档,“it”作为停用词被忽略:

http://www.postgresql.org/docs/current/static/textsearch-controls.html

在上面的示例中,我们看到生成的 tsvector 不包含单词 a、on 或 it,单词rats 变成rat,并且标点符号 - 被忽略。

您可以通过配置所需的词典来更改停用词列表:

http://www.postgresql.org/docs/current/static/textsearch-dictionaries.html