本文整理汇总了PHP中SphinxClient::buildExcerpts方法的典型用法代码示例。如果您正苦于以下问题:PHP SphinxClient::buildExcerpts方法的具体用法?PHP SphinxClient::buildExcerpts怎么用?PHP SphinxClient::buildExcerpts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SphinxClient
的用法示例。
在下文中一共展示了SphinxClient::buildExcerpts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
$posts[] = $rows;
}
}
//print_r($posts);
$options = array('before_match' => "<span style='color:red'>", 'after_match' => '</span>');
?>
<h3>搜索结果</h3>
<table border="1" >
<tr>
<th>id</th>
<th>weight</th>
<th>title</th>
<th>content</th>
</tr>
<?php
foreach ($posts as $items) {
$rows = @$sp->buildExcerpts($items, 'ind_post', $key, $options);
//print_r($rows);
echo "<tr>";
echo "<td>" . $items['id'] . "</td>";
echo "<td>" . $items['weight'] . "</td>";
echo "<td>" . $rows[2] . "</td>";
echo "<td>" . $rows[3] . "</td>";
echo "</tr>";
}
?>
</table>
示例2:
$i = $start;
for ($pg; $pg < $gPageSize && $i < $row_num; $pg++) {
# $Timer2->start();////////////////
if ($light) {
$row = mysql_fetch_assoc($rst);
if (strlen($row['description'])) {
$row['description'] = m_substr($row['description'], 0, 80);
} else {
$row['description'] = m_substr($row['fullcontent'], 0, 80);
}
if ($row['title']) {
$row['title'] = m_substr($row['title'], 0, 80);
} else {
$row['title'] = m_substr($row['url'], 0, 80);
}
$rst2 = $sphinx->buildExcerpts($row, "mysql", $keyword, $opts);
//"mysql"为索引名!
} else {
$rst2 = mysql_fetch_array($rst);
}
$i = $i + 1;
echo "<pre>";
#echo "Hits:{$rst2[5]} ";
echo "<a href=\"{$rst2[1]}\" class='fot' target='_blank'>{$rst2[2]}</a><br>";
// echo "关键字:{$rst2[3]}<br>";
echo "{$rst2[3]}<br>";
echo "<span style='color:#006400;'>{$rst2[4]} | {$rst2[1]}</span><br>";
echo "</pre>";
# $Timer2->stop();////////////////
# $format_number2 = number_format($Timer2->show(false), 3, '.', '');
# echo "<p>本条耗时<b style='color:red;'>{$format_number2}s</b>。<br></p>";
示例3: in
//设置字符集
mysql_set_charset("utf8");
//准备sql语句
$sql = "select id,title,content from post where id in(".$ids.")";
//发送sql语句
$result = mysql_query($sql);
//处理结果皆
$opts = array(
#格式化摘要,高亮字体设置
#在匹配关键字之前插入的字符串,默认是<b>
"before_match" => "<span style='font-weight:bold;color:red'>",
#在匹配关键字之后插入的字符串,默认是</b>
"after_match" => "</span>"
);
while($row = mysql_fetch_assoc($result)){
$res = $sphinx->buildExcerpts($row,"main",$keyword,$opts);
echo "标题:".$res['1']."<br />";
echo "内容:".$res['2']."<br />";
echo "<hr>";
}
//关闭
mysql_close($conn);