PostgreSQL阻止不匹配的tsqueries匹配tsvector

时间:2013-04-22 16:35:26

标签: postgresql full-text-search

给出以下查询:

select to_tsvector('fat cat ate rat') @@ plainto_tsquery('cats ate');

此查询将返回true作为结果。现在,如果我不希望“猫”也匹配“猫”这个词,我有什么方法可以防止这种情况呢?

另外,有什么方法可以确保tsquery以特定顺序匹配整个字符串(例如,“cat ate”被计为单个标记而不是两个)。目前,以下查询也将匹配:

select to_tsvector('fat cat ate rat') @@ plainto_tsquery('ate cats');

1 个答案:

答案 0 :(得分:1)

cat匹配cats是由于英语干扰,英语可能是您的默认文本搜索配置。请查看show default_text_search_config的结果以确定。

使用simple配置可以避免这种情况。尝试使用显式文本配置的函数调用:

select to_tsvector('simple', 'fat cat ate rat') @@ plainto_tsquery('simple', 'cats ate');

或者改为:

set default_text_search_config='simple';