Sphinx PHP search

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-19T02:41:19Z Indexed on 2010/03/19 13:11 UTC
Read the original article Hit count: 611

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
}

© Stack Overflow or respective owner

Related posts about sphinx

Related posts about sphinx-php