PostgreSQL 的 to_tsvector 函数可以 return tokens/words 而不是 lexemes 吗?

Can PostgreSQL's to_tsvector function return tokens/words and not lexemes?

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

我不担心停用词被过滤掉,这很好。但是有些词会完全毁掉,比如 everythingfavourite.

是否有修改此行为的方法或是否有其他函数可以执行此操作?

PS:是的,我可以编写自己的查询来执行此操作(而且我有),但我想要一种更快的方法。

您看到但不希望出现的行为是 "stemming"。如果你不想这样,你必须使用不同的字典 to_tsvector。 "simple" 词典不进行词干提取,因此它应该适合您的用例。

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