php - 在 Sphinx 0.9.9 中搜索多个 < 或 > 失败

标签 php mysql search-engine sphinx

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/

相关文章:

php - 显示百分比结果

django - 真正有效的 Django 搜索引擎解决方案?

c# - 用于测试搜索引擎功能的文本文件

php - PHP 和 MySQL : Unable to search with more than a single keyword, 中的搜索引擎给出 PDOException 错误

php - 在mysql数据库中将文本保存为pre

php - Laravel - 在 Eloquent 中连接 3 个表

mysql - 从数据库中仅查找一个小于条件的条目

mysql - 按星期几分组销售

php - 如何在没有 $this 的情况下调用类内部的函数?

php - UTF-8贯穿始终