Sphinx高亮故障的解决
2015.12.27
No Comments
关于BuildExcerpts失效问题
1.字符高亮不显示,注意关注参数:single_passage{Whether to highlight exact query phrase matches only instead of individual keywords. Boolean, default is FALSE}
2.关于标题正常,内容不显问题。参考下列内容
参考配置参数如下:
- //高亮显示的配置参数的数组
- $opts = array(
- "before_match" => "<span class=/"highlight/">",
- "after_match" => "</span>",
- "chunk_separator" => "...",
- "limit" => 60,
- "around" => 25,
- "single_passage" => true,
- "exact_phrase" => false
- );
- ......
- //高亮显示
- $highlight_name_array = search_highlight( $name_docs, $index, $words, $opts );
- $highlight_description_array = search_highlight( $description_docs, $index, $words, $opts );
- ......
- function search_highlight( $docs, $index, $words, $opts ) {
- $cl = new SphinxClient ();
- $arr_words = $cl->BuildExcerpts ( $docs, $index, $words, $opts );
- return $arr_words;
- }
- 遇到的情况却是标题里的高亮显示没有问题,但是介绍里的高亮却总是没有办法出来。
经过反复调试,发现和参数传递,过程处理,字符编码都没有关系,得到的结果在第二句search_highlight处理时总是固执的没有任何变化。
后来又把问题放在了参数设置上,将single_passage、exact_phrase两个参数去掉,替换before_match、after_match,都没有得到任何的成效。
一筹莫展时,突然看到了around这个参数,一般我们都设置为3,而这里设置为30,把这个参数改一改试试,发现It works!
经过调试,发现around值为25的时候能满足功能和产品的需求。
这个问题可能是Sphinx的一个bug,在某些特定条件下高亮的截取会失败,在有时间的时候我会阅读源码来调查这个问题的产生根源。
本段内容来自:@蒋宇捷的专栏
发表评论
要发表评论,您必须先登录。