4

I am using Postgresql with full test search with english dict. When I want to receive records with some english words I get verid results.

And so:

SELECT id FROM table1 WHERE ts_vector1 @@ to_tsquery('it')

returns 0 results.

SELECT id FROM table1 WHERE ts_vector1 @@ to_tsquery('specialist & it')

returns more than 0 results (word 'it' exists in table and index). ts_vector1 is created as follow:

ts_vector1 = to_tsvector('english', some_text_column)

Is 'it' a reserved word? If so, what is the best way to 'escape' reserved words?

4

2 回答 2

4

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

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

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

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

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

于 2013-10-02T12:13:14.130 回答
0

好的,所以 2013 年已经过去了,但问题仍然存在。您想删除“它”,因为它是噪音,但保留“它”这个词。通常信息技术的“它”写成“IT”。

在通过以下方式提供全文搜索之前to_tsvector

  1. 标记您的文本

  2. 将“IT”一词替换为“信息技术”

在使用 to_tsquery 进行搜索之前:

  1. 标记搜索查询文本

  2. 将“IT”一词替换为“信息技术”

您不再有英语“it”和“IT”之间的冲突,这在大多数情况下应该有效。也许您也可以在执行此操作之前尝试使用其他关键字来检测上下文。

完全在数据库中执行此操作可能是可能的,但在大多数应用程序中,这可以通过您的主服务器/程序通用语言来完成。

于 2018-11-19T11:53:55.093 回答