0

Sphinxを実行していて、検索できます(YAY)が、結果を取得したときに、選択したIDがない場合は、次のようになります。

source willem
{
type                            = mysql
sql_host                        = localhost
sql_user                        = root
sql_pass                        = ********
sql_db                          = test
sql_port                        = 3306

sql_query       = SELECT id, question, answer, UNIX_TIMESTAMP(created) AS date_added FROM faq


sql_attr_timestamp  = date_added

sql_ranged_throttle = 0

# document info query, ONLY for CLI search (ie. testing and debugging)
sql_query_info      = SELECT id, question, answer, UNIX_TIMESTAMP(created) AS date_added FROM faq WHERE id = $id
}

index willem {
source = willem
path = /home/willem/sphinx
morphology = stem_en
min_word_len = 3
min_prefix_len = 0
}

searchd {
compat_sphinxql_magics = 0
port = 3313
log = /home/willem/searchd.log
query_log = /home/willem/query.log
pid_file = /home/willem/searchd.pid
max_matches = 10000
}

そしてこれが私のPHPコードです:

$this->load->library('SphinxClient');
    $this->sphinxclient->SetServer('localhost', 3313);
    //$this->sphinxclient->SetLimits(10, 10);
    $this->sphinxclient->SetMatchMode( SPH_MATCH_ANY );
    $this->sphinxclient->SetSortMode( SPH_SORT_RELEVANCE );
    //$this->sphinxclient->SetWeights ( array ( 100, 1 ) );
    $res = $this->sphinxclient->Query('contact', 'willem');
    $error = $this->sphinxclient->GetLastError();
    var_dump($res);var_dump($error);

そしてこれが結果です:

array(10) {
["error"]=>
string(0) ""
["warning"]=>
string(0) ""
["status"]=>
int(0)
["fields"]=>
array(2) {
[0]=>
string(8) "question"
[1]=>
string(6) "answer"
}
["attrs"]=>
array(1) {
["date_added"]=>
int(2)
}
["matches"]=>
array(1) {
[6]=>
array(2) {
  ["weight"]=>
  string(1) "2"
  ["attrs"]=>
  array(1) {
    ["date_added"]=>
    int(0)
  }
}
}
["total"]=>
string(1) "1"
["total_found"]=>
string(1) "1"
["time"]=>
string(5) "0.000"
["words"]=>
array(1) {
["contact"]=>
array(2) {
  ["docs"]=>
  string(1) "1"
  ["hits"]=>
  string(1) "3"
}
}
}
string(0) ""

したがって、結果は取得しますが、idフィールドは取得しません。データベースから見つかったフィールドを取得するには、結果が必要です。

前もって感謝します。

PS:初めての投稿ですが、何か間違ったことをしたり、質問に答える別のトピックを見逃したりした場合は、stackoverflowがこれまでで最高の教師です。

4

1 に答える 1

3
["matches"]=>
array(1) {
[6]=>
array(2) {

それがIDです。6は、一致したドキュメントのIDです。

ただできる

$ids = array_keys($res['matches']); 

IDの配列を取得するには、後で使用できます。

于 2013-01-22T13:31:10.927 に答える