ts_headline() 是一个系统函数,用于以缩写形式显示全文搜索查询的匹配项。
ts_headline() 已在 PostgreSQL 8.3 中添加。
用法
ts_headline ( [configregconfig, ]documenttext,querytsquery[,optionstext] ) →text
ts_headline ( [configregconfig, ]documentjson,querytsquery[,optionstext] ) →text
ts_headline ( [configregconfig, ]documentjsonb,querytsquery[,optionstext] ) →text
生成文本是源文本的片段,其中提供的 tsquery 的匹配词会用 HTML <b> 标签高亮显示。
可以提供额外的选项来修改片段生成行为。
变更历史
- PostgreSQL 10
- 添加了 json/jsonb 支持(提交 e306df7f)
- PostgreSQL 8.3
- 添加(提交 140d4ebc)
示例
用于 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)
