Reputation: 401
I've been trying to use sphinx through PHP, and so far I've had absolutely no luck whatsoever.
sphinx itself is functioning as expected (my search commands via the linux terminal are working)
the Engine_Api_SphinxClient is the regular php api for sphinx that comes with the installation package. the only difference is the naming of the class.
// Connect to sphinx server
$sp = new \Engine_Api_SphinxClient();
// Set the server
$sp->SetServer('localhost', 9312);
// SPH_MATCH_ALL will match all words in the search term
$sp->SetMatchMode(SPH_MATCH_ANY);
// We want an array with complete per match information including the document ids
$sp->SetArrayResult(true);
$sp->setFieldWeights(array(
'thesis'=>2,
'body'=>1
));
/**
* Run the search query. Here the first argument is the search term
* and the second is the name of the index to search in.
* Search term can come from a search form
*/
$results = $sp->Query('gun', 'test1');
debug($results);
The 9312 in that setServer is the listening post defined in the sphinx config file. The debug line gives "false", and I see the following warnings and notices:
Errors
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 998
Warning: assert(): Assertion failed in /library/Engine/Api/SphinxClient.php on line 177
Warning: assert(): Assertion failed in /library/Engine/Api/SphinxClient.php on line 177
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1006
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1054
Warning: Invalid argument supplied for foreach() in /library/Engine/Api/SphinxClient.php on line 1070
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 564
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 569
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 477
Notice: Undefined property: Engine_Api_SphinxClient::$_socket in /library/Engine/Api/SphinxClient.php on line 478
Warning: fclose() expects parameter 1 to be resource, null given in /library/Engine/Api/SphinxClient.php on line 478
My suspicion is that it has something to do with those four notices. if anyone can provide a hint as to what the problem is, it would be greatly appreciated.
Upvotes: 3
Views: 1985
Reputation: 21091
If you renamed the class itself, did you also change the name of the constructor (around line 430)?
I suspect the constructor isnt getting called, so _socket is not initalized (which happens in the constructor)
(If this is the issue, you could probably just rename the function to __construct() so that its not dependant on what the class is called. http://php.net/manual/en/language.oop5.decon.php )
Upvotes: 7