首页 > 数据库 > > 控制文本搜索-高亮搜索结果
搜索结果的理想显示是:列出每篇文档中与搜索相关的部分,并标识为什么与查询相关。搜索引擎能够显示标识了搜索词的文档片段。GaussDB 200提供了函数ts_headline支持这部分功能。
ts_headline([ config regconfig, ] document text, query tsquery [, options text ]) returns textts_headline的输入是带有查询条件的文档,其返回文档中的摘录,在摘录中查询词是高亮显示的。用来解析文档的分词器由config参数指定。如果省略config,则使用default_text_search_config的值所指定的分词器。
指定options字符串时,需由一个或多个option=value对组成,且必须用逗号分隔。options可以是下面的选项:
不声明选项时,采用下面的缺省值:
StartSel=<b>, StopSel=</b>,
MaxWords=35, MinWords=15, ShortWord=3, HighlightAll=FALSE,
MaxFragments=, FragmentDelimiter=" ... "
比如:
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)
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摘录,因此使用起来会慢,应慎重使用。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3169869/ ,如需转载,请注明出处,否则将追究法律责任。