更新日期:2024年09月11日
高亮搜索结果
搜索结果的理想显示是:
列出每篇文档中与搜索相关的部分,
并标识为什么与查询相关。
搜索引擎能够显示标识了搜索词的文档片段。
GBase 8c 提供了函数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:分隔文档中出现的查询词,以区别于其他摘录词。当包含有空格或
GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
641
逗号时,必须用双引号将字符串引起来。
MaxWords,MinWords:定义摘录的最长和最短值。
ShortWord:在摘录的开始和结束会丢弃此长度或更短的词。默认值3 会消除常见的英
语冠词。
HighlightAll:布尔标志。如果为真,整个文档将作为摘录。忽略前面三个参数的值。
MaxFragments:
要显示的文本摘录或片段的最大数量。
默认值0 表示选择非片段的摘录
生成方法。
大于0 的值表示选择基于片段的摘录生成。
此方法查找带有尽可能多查询词
的文本片段,并显示查询词周围的上下文片段。因此,查询词临近每个片段的中间,且
查询词两边都有词。
每个片段至多有MaxWords,
并且长度为ShortWord 或更短的词在
每一个片段开始和结束被丢弃。如果在文档中没有找到所有的查询词,则文档中开头
将显示MinWords 单片段。
FragmentDelimiter:当有一个以上的片段时,通过该字符串分隔这些片段。不声明选项
时,采用下面的缺省值:
StartSel=, StopSel=,
MaxWords=35, MinWords=15, ShortWord=3, HighlightAll=FALSE, MaxFragments=0,
FragmentDelimiter=" ... "
例如:
gbase=#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 query terms
and return them in order of their similarity to the
query. (1 row)
gbase=#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
GBase 8c SQL 参考手册
南大通用数据技术股份有限公司
642
-------------------------------------------------------
containing given
and return them in order of their
ts_headline 使用原始文档,而不是tsvector 摘录,因此使用起来会慢,应慎重使用。