0

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

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 回答