PostgreSQL:to_tsquery 以搜索开始并以搜索结束

PostgreSQL: to_tsquery starts with and ends with search

最近,我在一个巨大的 table 系统上实现了 PostgreSQL 11 全文搜索,以解决其中命中 LIKE 查询的问题。 table 有超过 2 亿行,使用 to_tsquery 查询对于 tsvector.

类型的列非常有效

现在我需要点击以下查询,但阅读文档我找不到如何去做(或者它在那里但我不明白,因为全文搜索对我来说还是新事物)

如何才能使下面的查询 return 只有当查询是“The cat”(开头为)和“the book”(结尾为)时才为真,如果可以进行全文搜索。

select to_tsvector('The cat is on the book') @@ to_tsquery('Cat')

I implemented a PostgreSQL 11 full-text search on a huge table I have in a system to solve the problem of hitting LIKE queries in it.

你是怎么做到的? FTS 不适用于 LIKE 查询。它适用于 FTS 查询,例如 @@.

您不能直接查找以特定单词开头和结尾的字符串。您可以使用索引来筛选 cat 和 book,然后重新筛选那些在正确位置的行。

select * from whatever where tsv_col @@ to_tsquery('cat & book') and text_col LIKE 'The cat % the book';

除非你想匹配 'The cathe book' 之类的东西,否则你将不得不做其他事情,使用两个不同的 LIKE。