我正在使用 Sphinx 进行搜索,但结果非常奇怪。希望能得到帮助。
例如,如果我键入“50”,我会得到:
- 50 Cent
- 50 Lions
- 50 Foot Wave 等
这很好,但是当我搜索“50 Ce”时,我会得到:
- Ryczące Dwudziestki
- Spisek
- Bernhard Gal
- Cowabunga Go-Go
还有其他一些奇怪的结果。当我搜索“50 Cent”时,正确的结果位于顶部,然后下面是随机的结果。有什么想法吗?
PHP 代码:
$query = $_GET['query'];
if (!empty($query))
{
$sphinx->SetMatchMode(SPH_MATCH_ALL);
$sphinx->AddQuery($query, 'artists');
$sphinx->AddQuery($query, 'variations');
$sphinx->SetFilter('name', array(3));
$sphinx->SetLimits(0, 10);
$result = $sphinx->RunQueries();
echo '<pre>';
switch ($result)
{
case false:
echo 'Query failed: ' . $sphinx->GetLastError() . "\n";
break;
default:
if ($sphinx->GetLastWarning())
{
echo 'WARNING: ' . $sphinx->GetLastWarning() . "\n";
}
if (is_array($result[0]['matches']) && count($result[0]['matches']))
{
foreach ($result[0]['matches'] as $value => $info)
{
$artist = artistDetails($value);
echo $artist['name'] . "\n";
}
}
}
}
Sphinx索引和源代码:
source artists
{
type = mysql
sql_host = localhost
sql_user = user
sql_pass = pass
sql_db = db
sql_port = 3300
sql_query = \
SELECT \
id, name \
FROM artists;
#UNIX_TIMESTAMP(time)
#sql_attr_uint = group_id
#sql_attr_timestamp = time
sql_query_info = SELECT id,name FROM artists WHERE id=$id
}
index artists
{
source = artists
path = /var/sphinx/artists
docinfo = extern
charset_type = utf-8
}
enable_star = 1
。我没有修改默认值,我的查询结果仍然一样。此外,对于大多数用例(而非此用例),我认为将min_prefix_len
设置小于4可能是不必要的。如果有人能在这里评论性能,我将不胜感激。 - Josh Smithmin_prefix_len
的说法。对于搜索自动完成,将其设置为2会有很大的帮助。 - Josh Smith