使用sphinx关键字高亮显示 [ 新手入门 ]
引用sphinx类搜索
<?php
namespace app\controllers;
use Yii;
use app\models\Cai;
use yii\data\Pagination;
use yii\web\Controller;
use SphinxClient;
?>
// 查询数据分页
$query=Cai::find()->where($where);
$pages = new pagination(['totalCount'=>$query->count(),'pageSize'=>2]);
$datas=$query->limit($pages->limit)->offset($pages->offset)->asArray()->all();
// 高亮显示
$opt = array('before_match'=>'<font style="font-weight:bold; color:red">','after_match'=>'</font>');
foreach ($datas as $k => $v){
$row = $cl ->BuildExcerpts($v, 'mysql', $search, $opt);
$datas[$k]['c_id'] = $row[0];
$datas[$k]['con'] = $row[1];
$datas[$k]['a'] = $row[2];
}
共 0 条回复
没有找到数据。
37899
注册时间:2016-10-31
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝1
- 金钱30
- 威望0
- 积分30