# 高亮搜索结果
搜索结果的理想显示是：列出每篇文档中与搜索相关的部分，并标识为什么与查询相关。通常，搜索引擎显示文档片段时会对其中的搜索术语进行标记。GaussDB提供了函数ts_headline支持这部分功能。
```
ts_headline([ config regconfig, ] document text, query tsquery [, options text ]) returns text
```
ts_headline接受一个文档和一个查询，并且从该文档返回一个引用，其中来自查询的术语会被加亮。被用来解析该文档的配置可以用config指定；如果config被忽略，将会使用default_text_search_config配置。
options表示可选配置，由一个或多个option=value对组成，且必须用逗号分隔。options可以是下面的选项：
- StartSel，StopSel：分隔文档中出现的查询词，以区别于其他摘录词。当包含有空格或逗号时，必须用双引号将字符串引起来。内容最大长度为32767字节。
- MaxWords，MinWords：定义摘录的最长和最短值。

- ShortWord：在摘录的开始和结束会丢弃此长度或更短的词。默认值3会消除常见的英语冠词。

- HighlightAll：布尔标志。如果为真，整个文档将作为摘录。忽略前面三个参数的值。

- MaxFragments：要显示的文本摘录或片段的最大数量。默认值0表示选择非片段的摘录生成方法。 大于0的值表示选择基于片段的摘录生成。此方法查找带有尽可能多查询词的文本片段，并显示查询词周围的上下文片段。因此，查询词临近每个片段的中间，且查询词两边都有词。每个片段至多有MaxWords，并且长度为ShortWord或更短的词在每一个片段开始和结束被丢弃。如果在文档中没有找到所有的查询词，则文档中开头将显示MinWords单片段。

- FragmentDelimiter：当有一个以上的片段时，通过该字符串分隔这些片段。内容最大长度为32767字节。
不声明选项时，采用下面的缺省值：
```
StartSel=<b>, StopSel=</b>,
MaxWords=35, MinWords=15, ShortWord=3, HighlightAll=FALSE,
MaxFragments=0, FragmentDelimiter=" ... "
```
例如：
```
gaussdb=# 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('english', 'query & similarity'));
                        ts_headline                         
------------------------------------------------------------
 containing given <b>query</b> terms
 and return them in order of their <b>similarity</b> to the
 <b>query</b>.
(1 row)
gaussdb=# 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('english', 'query & similarity'),
'StartSel = <, StopSel = >');
                      ts_headline                      
-------------------------------------------------------
 containing given <query> terms
 and return them in order of their <similarity> to the
 <query>.
(1 row)
```
ts_headline使用原始文档，而不是tsvector摘录，因此使用起来可能很慢，应慎重使用。
