I am trying to use MySQL with Sphinx to provide fulltext searching on usernames in order to provide a user search/autocomplete feature.
I have everything set up using the sphinx php api and have managed to get a list of userid's returned with this code:
include('/usr/local/lib/php/sphinxapi.php');
$sphinx = new \SphinxClient();
$mysqlconn = mysql_connect("127.0.0.1:9306") or die ("Couldn't connect to MySQL.");
$results = $sphinx->Query("John", "users");
$ids = "";
foreach($results['matches'] as $id => $data) {
if($ids > ""){
$ids .= ",";
}
$ids .= $id;
}
echo json_encode($ids);
This returns a comma seperated list of userid's which have the word 'John' in eitheer their firstname or lastname column
Taking this approach I would now need to query the actual mysql database and pull out the users matching those ID's.
My question is what would be the most efficient way of doing this? Should I use a simple select with an IN()
clause or is there a far better way?
Also can Sphinx not return this data for me itself automatically in a more efficient manner?
Thanks in advance