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()”的任何评论、建议或更正,请在此处 提交