postgresql - 是否有一个 ts(文本搜索)函数会返回找到的字符串而不是布尔值?
问题描述
我正在使用 PostgreSQL 通过使用tsvector
and来查找文章中匹配的字符串tsquery
。
我阅读了 PostgreSQL 手册 12.3 Controlling Text Search,但没有什么能帮助我获得我想要的确切输出。
询问:
SELECT ts_headline('english',
'The most common type of search
is to find all documents containing given query terms
and return them in order of their similarity to the
query.',
to_tsquery('query & similarity'),
'StartSel = <, StopSel = >');
ts_headline 输出
The most common type of search
is to find all documents containing given <query> terms
and return them in order of their <similarity> to the
<query>.
我正在寻找下面提到的唯一字符串:
查询,相似度
解决方案
如果您为 StartSel 和 StopSel 选择了您确定在字符串的其他位置不存在的分隔符,那么使用regexp很容易做到这一点。
SELECT distinct regexp_matches[1] from
regexp_matches(
ts_headline('english',
'The most common type of search
is to find all documents containing given query terms
and return them in order of their similarity to the
query.',
to_tsquery('query & similarity'),
'StartSel = <, StopSel = >'
),
'<(.*?)>','g'
);
推荐阅读
- windows - 在 Jenkinsfile 管道上禁用 cron
- python - AWS Lambda 函数 + Cloudwatch,如何将正确的参数传递给定时执行
- c++ - 没有 lpthread 的 Promise 中出现未知异常的原因
- reactjs - 是否有理由在 React Router 中使用 Link 而不是 NavLink?
- jackson - Spring Batch Oracle TIMESTAMP Jackson 序列化失败
- javascript - 如何让javascript提示问题一定次数
- html - 如何将自定义 css 添加到 github 页面
- azure - 如何将 blob 从 Azure 容器传输到 FTP 服务器/位置?
- android - 我在尝试登录时收到 PayPal 错误
- node.js - 我在客户端使用 next.js 并在服务器端使用 node.js 表达谁