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>
标签突出显示。
可以提供其他选项来修改片段生成行为。
更改历史记录
- 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)