PostgreSQL 的 to_tsvector
函数非常有用,但就我的数据集而言,它的作用比我想要的要多一些。
例如:
select *
from to_tsvector('english', 'This is my favourite game. I enjoy everything about it.');
产生:'enjoy':7 'everyth':8 'favourit':4 'game':5
我不担心停用词被过滤掉,这很好。但是有些词会被完全毁掉,比如 everything
和 favourite
。
是否有修改此行为的方法或是否有其他函数可以执行此操作?
PS:是的,我可以编写自己的查询来执行此操作(而且我已经这样做了),但我想要一种更快的方法。
最佳答案
您看到的和不希望看到的行为是“词干提取”。如果你不想这样,你必须使用不同的字典和 to_tsvector。 “简单”字典不进行词干提取,因此它应该适合您的用例。
select *
from to_tsvector('simple', 'This is my favourite game. I enjoy everything about it.');
结果如下输出
'about':9 'enjoy':7 'everything':8 'favourite':4 'game':5 'i':6 'is':2 'it':10 'my':3 'this':1
如果你仍然想删除停用词,据我所知,你必须定义自己的字典。请参阅下面的示例,尽管您可能想阅读 documentation以确保这完全符合您的要求。
CREATE TEXT SEARCH DICTIONARY only_stop_words (
Template = pg_catalog.simple,
Stopwords = english
);
CREATE TEXT SEARCH CONFIGURATION public.only_stop_words ( COPY = pg_catalog.simple );
ALTER TEXT SEARCH CONFIGURATION public.only_stop_words ALTER MAPPING FOR asciiword WITH only_stop_words;
select *
from to_tsvector('only_stop_words', 'The This is my favourite game. I enjoy everything about it.');
'enjoy':8 'everything':9 'favourite':5 'game':6
关于postgresql - PostgreSQL 的 to_tsvector 函数可以返回标记/单词而不是词素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46687065/