37899 2016-07-29 09:27:49 3374次浏览 0条回复 1 0 0

引用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];
}
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册