如何让 Postgres 10.x 不从文本搜索中删除冠词和代词

How to get Postgres 10.x to not drop articles and pronouns from text searches

我正在为我们的应用程序开发搜索界面,并注意到 Postgres 正在从搜索词中删除冠词和代词:

> select to_tsvector('english', 'welcome to your house')
< 'hous':4 'welcom':1

如果标题为“你的和她的”,这会产生问题:

> select to_tsvector('english', 'yours and hers')
< (blank)

如何配置文本搜索以停止删除冠词和代词?我仍然希望获得搜索“jumped”并使其匹配“jumping”的好处。

所以你想保留词干,但去掉停用词。您可以就地更改英语词典,但这通常不是一个好主意,因为它会带来升级风险。 (您的更改将在转储和恢复后丢失,或者 运行 of pg_upgrade)并且这会让不知道更改的人感到困惑。因此,您可以制作不含停用词的副本。

create text search dictionary english_stem_nostop ( template = snowball, language = english );
create text search configuration english_nostop ( copy = english);
alter text search configuration english_nostop alter mapping replace english_stem with english_stem_nostop;

select to_tsvector('english_nostop', 'welcome to your house');
            to_tsvector             
-------------------------------------
'hous':4 'to':2 'welcom':1 'your':3