我有完整的短语需要搜索文档。该命令plainto_tsquery()或phraseto_tsquery()是限制性的,并且一旦在文档中没有该短语的单词,就给出不匹配项。
我想先搜索所有短语的单词,如果没有匹配项,则其中一些。
我开始解析该短语并手动构建辅助查询,但这有点琐碎。例如,如果我的短语是“我喜欢闪亮的星星”,我会
select *, ts_rank(to_tsvector(description), query) as rank
from skill, to_tsquery('(I & like & shining & stars') query
where query @@ to_tsvector(description)
order by rank desc
select *, ts_rank(to_tsvector(description), query) as rank
from skill, to_tsquery('(like & shining & stars') query
where query @@ to_tsvector(description)
order by rank desc;
select *, ts_rank(to_tsvector(description), query) as rank
from skill, to_tsquery('(I & shining & stars') query
where query @@ to_tsvector(description)
order by rank desc;
select *, ts_rank(to_tsvector(description), query) as rank
from skill, to_tsquery('(I & like & stars') query
where query @@ to_tsvector(description)
order by rank desc;
等...
它有点像Google搜索引擎的“缺少”字词功能
有更好的方法吗?
谢谢