2012-08-14 206 views
3

我一直在試圖通過PHP使用獅身人面像,到目前爲止,我已經絕對沒有運氣。獅身人面像php api不工作

獅身人面像本身如預期的那樣發揮作用(通過Linux終端我的搜索命令工作)

的Engine_Api_SphinxClient是獅身人面像常規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配置文件中定義的監聽文章。 調試行給出「假」,我看到下面的警告和注意事項:

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

什麼在線上的SphinxClient.php?什麼斷言失敗? – Tchoupi 2012-08-14 00:59:54

+0

該行上的代碼是:'code'assert(is_numeric($ v));'code'。 $ v是剛剛傳入函數的參數。第177行是該函數的第一行。好吧,無論如何,這些代碼可以在互聯網上免費下載,如果您有興趣,可以下載它。 – Furyvore 2012-08-14 17:15:36

回答

7

如果您重命名類本身,您是否也更改構造函數的名稱(430行左右)?

我懷疑構造心不是獲取調用,所以_socket不initalized)(發生在構造函數)

(如果是這樣的問題,你很可能只是重命名功能__construct(使其不取決於什麼類叫 http://php.net/manual/en/language.oop5.decon.php

+0

謝謝,那正是問題所在。 – Furyvore 2012-08-14 17:12:46

+0

@barryhunter,謝謝! – shiva8 2012-08-14 17:25:55