我已经安装并测试了sphinx搜索,我收到通知:未定义的索引ID @第37行...请在下面查找我的代码...另外,我想打印结果在该区域的任何帮助是也非常感谢
<?php
include 'includes/config.php';
include 'sphinxapi.php';
$no=0;
$cl = new SphinxClient;
$cl->setServer("127.0.0.1", 9312);
$cl->setMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetLimits(0, 25);
//Sorts by relevance in descending order (best matches first)
$cl->SetSortMode (SPH_SORT_RELEVANCE); //"published asc/desc"
//Insert here text for searching
$q = '"' . $cl->EscapeString($_GET['q']) . '"/1';
$res = $cl->Query($q, 'resume');
if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";
} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n";
print "Query stats:\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " '$word' found $info[hits] times in $info[docs] documents\n";
print "\n";
if ( is_array($res["matches"]) )
{
$n = 1;
print "Matches:\n";
foreach ( $res["matches"] as $docinfo )
{
Line37==> print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";
foreach ( $res["attrs"] as $attrname => $attrtype )
{
$value = $docinfo["attrs"][$attrname];
if ( $attrtype==SPH_ATTR_MULTI || $attrtype==SPH_ATTR_MULTI64 )
{
$value = "(" . join ( ",", $value ) .")";
} else
{
if ( $attrtype==SPH_ATTR_TIMESTAMP )
$value = date ( "Y-m-d H:i:s", $value );
}
print ", $attrname=$value";
}
print "\n";
$n++;
}
}
}
?>
答案 0 :(得分:0)
默认情况下,不会是$ matches数组中的[id]值。 id存储为数组的键。
即会做
foreach ( $res["matches"] as $id => $docinfo )
要获取具有[id]值的数值数组,需要使用->SetArrayResult(true)
http://sphinxsearch.com/docs/current.html#api-func-setarrayresult