我已经安装并测试了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++;
}
}
}
?>
默认情况下,不是$matches数组中的[id]值。id被存储为数组的键。
foreach ( $res["matches"] as $id => $docinfo )
要获得一个数值数组,值为[id],需要使用->SetArrayResult(true)
http://sphinxsearch.com/docs/current.html api-func-setarrayresult