Sphinx不会从结果中返回ID

时间:2013-01-22 10:12:25

标签: php linux sphinx

我有Sphinx正在运行,我可以搜索(YAY),但是当我得到结果时,我的选择的id不存在,这是我的sphinx.conf:

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是有史以来最好的老师。

1 个答案:

答案 0 :(得分:3)

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

这就是那里的身份证。 6是匹配文档的id。

可以做到

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

获取一组id,以后可以使用。