首先官方参数说明
public array SphinxClient::buildExcerpts ( array $docs , string $index , string $words [, array $opts ] )
$docs Array of strings with documents’ contents.
$index Index name.
$words Keywords to highlight.
$opts 如下
| Option | Description |
|---|---|
| “before_match” | A string to insert before a keyword match. Default is “”. |
| “after_match” | A string to insert after a keyword match. Default is “”. |
| “chunk_separator” | A string to insert between snippet chunks (passages). Default is " … ". |
| “limit” | Maximum snippet size, in symbols (codepoints). Integer, default is 256. |
| “around” | How much words to pick around each matching keywords block. Integer, default is 5. |
| “exact_phrase” | Whether to highlight exact query phrase matches only instead of individual keywords. Boolean, default is FALSE. |
| “single_passage” | Whether to extract single best passage only. Boolean, default is FALSE. |
中文解释
$docs 为包含各文档内容的数组。【注意!如果数组里里有int类型需要转换成string。如:(string) 1】
$index 为索引名。
$words 为包含需要高亮的关键字的字符串。
下面是$opts可选参数。
before_match和 after_match 就不说了,就是匹配的keyword前后要插入的字符串。
chunk_separator 在摘要词组(段落)之间插入的字符串。默认为" … "。
limit 摘要最多包含的符号(codepoints)数。这个codeopints是什么意思具体可以百度下,不做深入说明,因为我也不太明白 。
around 每个关键词块左右选取的词的数量。整数,默认为 5.
exact_phrase 是否突出显示精确的查询短语匹配而不是单个关键字。布尔值,默认值为FALSE。【这货有点奇怪,在我使用coreseek时如果这个设置为true会导致无法高亮关键词,并抛出下面的异常received zero-sized searchd response】
single_passage 是否仅提取匹配到的最佳的一个区块。布尔值,默认为false.