Sphinx PHP search
- by James
I'm doing a Sphinx search but turning up some really weird results. Any help is appreciated.
So for example if I type "50", I get:
50 Cent
50 Lions
50 Foot Wave, etc.
This is great, but when I search "50 Ce", I get:
Ryczace Dwudziestki
Spisek
Bernhard Gal
Cowabunga Go-Go
And other crazy results. Also when I search for "50 Cent", the correct result is at the top, but then random results below. Any ideas why?
PHP code:
$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 Index and Source:
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
}