在使用安瓿,点或空格查询时,Sphinx不会返回匹配项

时间:2015-02-25 19:28:51

标签: regex search sphinx

当我尝试搜索文字 C& A 时,即使C& A在搜索中被编入索引,sphinx也会返回0结果。当字母C' C'搜索,这意味着C& A已被索引。

我认为问题在于Sphinx并不将& 视为单词字符,因此将其视为单词分隔符。

到目前为止我尝试了什么

  1. 使用charsettable charset_table = 0..9,A..Z-> a..z,_,a..z,U + 410..U + 42F-> U + 430..U + 44F,U + 430。 .U + 44F,U + 0026

  2. 使用api转义字符串函数 $ escaped = $ cl-> EscapeString(" escaping-sample @ query / string");

  3. 尝试使用str_replace($ from,$ to,$ string)来转义字符的自定义代码
  4. 似乎没什么用。如何在Sphinx中更改此行为?

    使用Sphinx版本:2.0.4

2 个答案:

答案 0 :(得分:0)

经过大量阅读sphinx文档的努力,我无法找到解决此问题的方法。因此我采用了php的方式。这是我做的,

  1. 在sql索引查询中使用replace()将所有特殊字符替换为等效文本。

      

    选择ID,替换(替换(替换(姓名,'&','和'),'   ''空间'),' - ''连字符').....

  2. 从用户查询中,我使用与sql中的等效文本相应地替换了字符。

    //decode html encoding from input
    $text = html_entity_decode($text);
    
    // split and replace with &
    if(strpos($text, '&'))
    {      
    $array = explode("&",$text);
    $text = $array[0]. "and". $array[1];
    }
    
    // split and replace with hyphen
    if(strpos($text, '-'))
    {      
    $array = explode("-",$text);
    $text = $array[0]. "hyphen". $array[1];
    }
    
    // split and replace with space
    if(strpos($text, ' '))
    {      
    $array = explode(" ",$text);
    $text = $array[0]. "space". $array[1];
    }
    
  3. 现在,以&符号为例,当用户查询文本C& A时,sphinx将其视为canda并按预期返回匹配C& A.

    注意:在我的情况下,Sphinx已经索引了所有特殊字符,我在查询时只遇到了问题。

    编辑: 将Sphinx更新到最新版似乎已经解决了这个问题。 在索引conf中使用blend_chars。

答案 1 :(得分:0)

添加到配置目录中的exceptions.txt文件:

C&A => C&A