gpt4 book ai didi

postgresql - 匹配句子中特定位置的全文搜索

转载 作者:行者123 更新时间:2023-11-29 13:08:15 25 4
gpt4 key购买 nike

SELECT 'Three little birds are sitting on a tree'::tsvector @@ to_tsquery('simple','birds');

我是否可以通过定义搜索词必须满足的句子中特定位置的方式修改查询?

在此示例中,'birds' 位于句子的第三个位置,因此我可以修改约束条件,使其仅在给定位置找到匹配项时才返回 true,例如

to_tsquery2('simple','birds',3) // => true

同时

to_tsquery2('simple','birds',5)  // => false

最佳答案

在 PostgreSQL 全文搜索中没有这方面的规定。

但是您可以在文本前添加一个“标记”并滥用短语搜索:

SELECT to_tsvector('simple',
'quagga '
|| 'Three little birds are sitting on a tree'
)
@@ to_tsquery('simple',
'quagga <3> ' || 'birds'
);

?column?
----------
t
(1 row)

短语a <3> b匹配包含 a 的句子和 b中间有两部作品。

您必须使用 quagga不会出现在您的文本中的任何地方。

关于postgresql - 匹配句子中特定位置的全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58391965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com