[英]SPHINX search php query, how to display results from an array?
我开始学习狮身人面像搜索php api
运行此查询后
<?php
include('sphinxapi.php');
$cl = new SphinxClient();
$cl->SetServer( "192.168.0.100", 9312 );
$cl->SetMatchMode( SPH_MATCH_ANY );
$result = $cl->Query( "mimmi", "searchtest" );
if ( $result === false ) {
echo "Query failed: " . $cl->GetLastError() . ".\n";
}
else {
if ( $cl->GetLastWarning() ) {
echo "WARNING: " . $cl->GetLastWarning() . "
";
}
if ( ! empty($result["matches"]) ) {
foreach ( $result["matches"] as $doc => $docinfo ) {
echo "$doc\n";
}
print_r( $result );
}
}
exit;
?>
如何正确显示结果,它会显示这样的输出
2183 3262 5256 7812 838 1475 1701 6184 1816 Array ( [error] => [warning] => [status] => 0 [fields] => Array ( [0] => namn [1] => title [2] => identification_text [3] => id [4] => namn [5] => title [6] => identification_text [7] => description ) [attrs] => Array ( ) [matches] => Array ( [2183] => Array ( [weight] => 6 [attrs] => Array ( ) ) [3262] => Array ( [weight] => 6 [attrs] => Array ( ) ) [5256] => Array ( [weight] => 6 [attrs] => Array ( ) ) [7812] => Array ( [weight] => 6 [attrs] => Array ( ) ) [838] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1475] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1701] => Array ( [weight] => 4 [attrs] => Array ( ) ) [6184] => Array ( [weight] => 4 [attrs] => Array ( ) ) [1816] => Array ( [weight] => 2 [attrs] => Array ( ) ) ) [total] => 9 [total_found] => 9 [time] => 0.001 [words] => Array ( [mimmi] => Array ( [docs] => 9 [hits] => 46 ) ) )
我不知道该怎么做,我如何显示结果。
此时,您希望获取从sphinx返回的ID并使用它们查询您的数据库。
<?php
$IDs = implode(",",array_keys($result["matches"]));
$sql = "SELECT * FROM `tbl` WHERE `id` IN ($IDs) ORDER BY FIELD(`id`,$IDs)";
?>
您在/etc/sphinxsearch/sphinx.conf中声明的字段将在$ result ['matches']中可用:
sql_field_string = my_field # will be both indexed and stored
这样,就不需要查询数据库了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.