一 : 配置sphinx
二 : 启动sphinx
创建索引
./bin/indexer.exe -c ./etc/csft_mysql.conf --all
开启sphinx
./bin/searchd.exe -c ./etc/csft_mysql.conf
1: 把sphinx中的sphinxapi.php文件放入vendor下面的composer中
2: 在vendor文件夹中引入sphinxapi.php
3:在控制器中实例化sphinx
//实例化sphinx
$request = \Yii::$app->request;
$data = $request->post();
$sphinx = new \SphinxClient();
$sphinx->SetServer('127.0.0.1',9312);
$result = $sphinx->Query($data['title'].$data['author'],'*'); //$data['title'].$data['author'] 他们是要查询的字段
//获取搜索内容
$id = $result['matches'];
//处理
$list=array();
foreach($id as $k=>$v){
$con = Article::find()->where(['id'=>$k])->asArray()->one();
$list[] = str_replace($con['title'],"<font color='red'>".$data['title']."</font>",$con);
}