# sphinxapi BuildExcerpts（创建高亮文本摘要） 方法参数说明

**URL:** <https://www.shiqidu.com/t/topic/201>\
**Category:** 开发调优\
**Tags:** Sphinx\
**Created:** [2017 年8 月 2 日 02:34 UTC](https://www.shiqidu.com/t/topic/201 "2017-08-02T02:34:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2017 年8 月 2 日 02:34 UTC](https://www.shiqidu.com/t/topic/201/1 "2017-08-02T02:34:42Z")

</div>

首先官方参数说明

```php
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.

---

<div class="post-metadata">

作者： ![myvic](https://www.shiqidu.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@myvic](https://www.shiqidu.com/u/myvic)\
发布日期： [2018 年8 月 6 日 10:44 UTC](https://www.shiqidu.com/t/topic/201/2 "2018-08-06T10:44:33Z")

</div>

我：‘exact\_phrase’ =\> true

这个设置true,报下面错误，请问你解决了吗？

报错：searchd error: exact\_phrase is deprecated, use phrase search operator with query\_mode=1

---

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2018 年8 月 6 日 11:54 UTC](https://www.shiqidu.com/t/topic/201/3 "2018-08-06T11:54:46Z")

</div>

这个参数被废弃了，不能用了。
