Postgresql 在Postgres全文搜索中仅匹配一些单词

Postgresql 在Postgres全文搜索中仅匹配一些单词,postgresql,full-text-search,postgresql-9.1,Postgresql,Full Text Search,Postgresql 9.1,我对使用postgres作为我正在开发的网站的搜索引擎很感兴趣,但似乎postgres在匹配ts_查询和ts_向量类型时非常严格。如果ts_向量不包含查询中的所有项,则会拒绝匹配 例如,我希望查询“Stack Overflow code”与Stack Overflow站点摘要匹配,但事实并非如此,因为单词“code”不存在,即使“Stack”和“Overflow”不存在 SELECT to_tsvector('Stack Overflow is a question and answer si

我对使用postgres作为我正在开发的网站的搜索引擎很感兴趣,但似乎postgres在匹配ts_查询和ts_向量类型时非常严格。如果ts_向量不包含查询中的所有项,则会拒绝匹配

例如,我希望查询“Stack Overflow code”与Stack Overflow站点摘要匹配,但事实并非如此,因为单词“code”不存在,即使“Stack”和“Overflow”不存在

SELECT 
to_tsvector('Stack Overflow is a question and answer site for professional and enthusiast programmers. It''s built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we''re working together to build a library of detailed answers to every question about programming.')
@@ 
plainto_tsquery('english', 'Stack Overflow code')
返回:

false
在我的用例中,我对精确匹配不感兴趣,因为这将被用户用来搜索网站


当文档中只有部分查询时,是否有方法将某个内容计算为匹配项?

这是因为
plainto\u tsquery
将字符串切分为单独的词素,并在它们之间放置&(and)运算符。这意味着它匹配所有单词

如果需要|(OR)运算符,则需要编写自己的“解析器”。例如,您可以将所有出现的
'
替换为
'|'

SELECT 
to_tsvector('Stack Overflow is a question and answer site for professional and enthusiast programmers. It''s built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we''re working together to build a library of detailed answers to every question about programming.')
@@ 
to_tsquery('english', replace('Stack Overflow Code', ' ' , '|'));

另请参见smlar扩展,由与文本搜索相同的作者编写