Sphinx 0.9.9 已配置为与 MySql 配合使用。
我最近注意到 Sphinx 不适用于包含多次出现的 < 或 > 字符的搜索词。
工作的 PHP 代码:
// Initialize SphinxClient class object
$cl = new SphinxClient ();
// Set the server and port
$cl->SetServer ( "127.0.0.1", 9313 );
// Initialize prefixed query
$query_prefix = '';
// Set the limit
$cl->SetLimits((int)$offset, (int)$count);
// Set the match mode
$cl->setMatchMode(SPH_MATCH_EXTENDED);
// Set the ranking mode
$cl->setRankingMode(SPH_RANK_WORDCOUNT);
// Set sorting
$cl->SetSortMode(SPH_SORT_EXTENDED,'@relevance DESC, updated_date DESC' );
$query_main = '@(name,description)';
// Initialize the search index
$search_index = 'index_common';
$search_text = $cl->EscapeString($search_text);
// Run the search query
$resp = $cl->Query($query_prefix . '('. $query_main . '"^' . $search_text . '$" | "' .
$search_text . '" | (' . $search_text . ') | "'
. $search_text . '"/1 | (' . $search_text_wild . ')) ' ,$search_index);
如果我输入不带引号的“>>”等搜索词,它会生成以下查询:
(@(name,description)"^>>$" | ">>" | (>>) | ">>"/1 | (*>>*))
并且不会给出任何响应,例如在系统中找不到搜索词时。这种情况发生在 < 和 > 多次出现时,而不是单个出现时。
这是 Sphinx 中的已知问题还是有办法克服(使 Sphinx 在此类特殊情况下正常工作)?
最佳答案
<< 用作严格的顺序运算符 - 我认为还有非官方的 >> 语法。
所以这可能会导致问题。你可以尝试转义它们,我猜 EscapeString 不会这样做。
但请记住,除非 < 和 > 在您的字符集表中,否则它们永远无法匹配。
(另外,当您说没有得到响应时,请务必检查 $cl->getLastError()
!!
关于php - 在 Sphinx 0.9.9 中搜索多个 < 或 > 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13801220/