1

我正在使用 PostgreSQL 通过使用tsvectorand来查找文章中匹配的字符串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>.    

我正在寻找下面提到的唯一字符串:

查询,相似度

4

1 回答 1

0

如果您为 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'
     );
于 2019-11-04T16:51:01.623 回答