Sphinx 在使用双字符、点或 space 查询时不 return 匹配
Sphinx doesn't return matches while querying with amphersand, dot or space
当我尝试搜索文本 C&A 时,sphinx 返回了 0 个结果,即使 C&A 在搜索中已编入索引。它 returns C&A 当搜索字母 'C' 时,这意味着 C&A 已经被索引。
我认为问题在于 Sphinx 不将 & 视为单词字符,而是将其视为单词分隔符。
到目前为止我尝试了什么
使用了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
使用了api转义字符串函数
$escaped = $cl->EscapeString ( "escaping-sample@query/string" );
- 尝试使用自定义代码转义字符 str_replace ( $from, $to, $string )
似乎没有任何效果。如何在 Sphinx 中更改此行为?
使用 Sphinx 版本:2.0.4
经过大量阅读 sphinx 文档后,我找不到任何方法来解决这个问题。因此我选择了 php 方式。这是我所做的,
在 sql 索引查询中使用 replace() 将所有特殊字符替换为其等效文本。
Select id,Replace(Replace( Replace(name, '&', 'and'),'
','space'),'-','hyphen').....
根据用户查询,我相应地用 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];
}
现在,以 & 符号为例,当用户查询文本 C&A 时,sphinx 将其视为 canda 并且 returns 匹配 C&A 符合预期。
注意:在我的例子中,Sphinx 已经索引了所有特殊字符,我只是在查询时遇到问题。
编辑:
将 Sphinx 更新到最新版本似乎已经解决了这个问题。
在您的索引配置中使用 blend_chars。
添加到配置目录中的 exceptions.txt
文件:
C&A => C&A
当我尝试搜索文本 C&A 时,sphinx 返回了 0 个结果,即使 C&A 在搜索中已编入索引。它 returns C&A 当搜索字母 'C' 时,这意味着 C&A 已经被索引。
我认为问题在于 Sphinx 不将 & 视为单词字符,而是将其视为单词分隔符。
到目前为止我尝试了什么
使用了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
使用了api转义字符串函数 $escaped = $cl->EscapeString ( "escaping-sample@query/string" );
- 尝试使用自定义代码转义字符 str_replace ( $from, $to, $string )
似乎没有任何效果。如何在 Sphinx 中更改此行为?
使用 Sphinx 版本:2.0.4
经过大量阅读 sphinx 文档后,我找不到任何方法来解决这个问题。因此我选择了 php 方式。这是我所做的,
在 sql 索引查询中使用 replace() 将所有特殊字符替换为其等效文本。
Select id,Replace(Replace( Replace(name, '&', 'and'),' ','space'),'-','hyphen').....
根据用户查询,我相应地用 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]; }
现在,以 & 符号为例,当用户查询文本 C&A 时,sphinx 将其视为 canda 并且 returns 匹配 C&A 符合预期。
注意:在我的例子中,Sphinx 已经索引了所有特殊字符,我只是在查询时遇到问题。
编辑: 将 Sphinx 更新到最新版本似乎已经解决了这个问题。 在您的索引配置中使用 blend_chars。
添加到配置目录中的 exceptions.txt
文件:
C&A => C&A