ts_headline()

显示全文搜索查询匹配结果的函数

ts_headline() 是一个系统函数,以缩写形式显示全文搜索查询的匹配结果。

ts_headline()PostgreSQL 8.3 中添加。

用法

ts_headline ( [ config regconfig, ] document text, query tsquery [, options text ] ) → text
ts_headline ( [ config regconfig, ] document json, query tsquery [, options text ] ) → text
ts_headline ( [ config regconfig, ] document jsonb, query tsquery [, options text ] ) → text

结果文本是源文本中的一个片段,其中来自提供的 tsquery 的匹配词用 HTML <b> 标签突出显示。

可以提供其他选项来修改片段生成行为。

更改历史记录

示例

ts_headline() 的基本用法示例

postgres=# WITH document AS (
  SELECT $$
The quick brown fox jumps over the lazy dog

The earliest known appearance of the phrase was in The Boston Journal. In an
article titled "Current Notes" in the February 9, 1885, edition, the phrase is
mentioned as a good practice sentence for writing students: "A favorite copy set
by writing teachers for their pupils is the following, because it contains every
letter of the alphabet: 'A quick brown fox jumps over the lazy dog.'"
$$ AS text)
SELECT ts_headline(d.text, plainto_tsquery('quick brown fox'))
  FROM document d;
                         ts_headline                          
--------------------------------------------------------------
 <b>quick</b> <b>brown</b> <b>fox</b>jumps over the lazy dog+
                                                             +
 The earliest known appearance of the phrase
(1 row)

分类

全文搜索系统函数

另请参阅

ts_rank()ts_rank_cd()

反馈

提交任何关于 "ts_headline()" 的评论、建议或更正 在此