从Postgres 8.4开始,数据库fts不支持精确的短语匹配,如果给出2个术语,它也不支持邻近匹配.例如,没有办法告诉Postgres匹配单词#1的内容,该单词位于单词#2的指定邻近区域.任何人都知道Postgres的计划,可能支持哪个版本的短语和邻近匹配?
解决方法
Postgresql 9.6文本搜索现在支持短语
select * from (values ('i heart new york'),('i hate york new') ) docs(body) where to_tsvector(body) @@ phraseto_tsquery('new york') (1 row retrieved)
或者单词之间的距离:
-- a distance of exactly 2 "hops" between "quick" and "fox" select * from (values ('the quick brown fox'),('quick brown cute fox') ) docs(body) where to_tsvector(body) @@ to_tsquery('quick <2> fox') (1 row retrieved)