我一直在尝试通过PHP使用sphinx,到目前为止,我绝对没有运气。
sphinx本身正在按预期运行(我通过linux终端的搜索命令正在运行)
Engine_Api_SphinxClient是安装包附带的sphinx的常规php api。唯一的区别是班级的命名。
// 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);
该setServer中的9312是sphinx配置文件中定义的监听帖子。 调试行给出“false”,我看到以下警告和注意事项:
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
我怀疑它与这四个通知有关。如果有人能提供关于问题的提示,我们将不胜感激。
答案 0 :(得分:7)
如果您重命名了类本身,您是否也更改了构造函数的名称(第430行)?
我怀疑构造函数没有被调用,所以_socket没有被初始化(这在构造函数中发生)
(如果这是问题,你可能只是将函数重命名为__construct(),以便它不依赖于调用类的内容。 http://php.net/manual/en/language.oop5.decon.php )