谁一开始就是大神?

sphinx配置咨询[2.0]

配置如下,URL链接也是正确的 如:r=search/index&keyword=网站建设&page=4
但是结果始终之在第一页:200.png
请问是哪里错了。

`public function actionIndex(){

$sphinx = new SphinxClient();
$sphinx->setMatchMode(SPH_MATCH_ANY);
$sphinx->SetServer ( 'localhost', 9312 );//coreseek的主机名和端口
$sphinx->SetArrayResult ( true );//设置返回结果集为php数组格式
$key=Yii::$app->request->post('keyword','网站建设');
if(!$key){
	$key=Yii::$app->request->get('keyword');
}
$result = $sphinx->query ($key, "mysql");//xxxx是查询的内容,mysql是测试的配置文件中系统默认的类名

$total=$result['total'];
$config = ['params' => ['keyword' => $key],'totalCount'=>$total,'defaultPageSize'=>10];
$pagination = new Pagination($config);
$sphinx->SetLimits($pagination->offset,$pagination->limit,1000);
$sphinx->SetMaxQueryTime(10);//最大搜索时间
$result = $sphinx->query ($key, "mysql");
if($result['total']){
	$ids = ArrayHelper::getColumn($result['matches'], 'id');
}else{
	$ids =[];
}
$rows=Company::find()->where(['in','id',$ids])->asArray()->all();
    return $this->render('index',[
        'rows'=>$rows,
        'pagination'=>$pagination,
        'total'=>$total,
        'keyword'=>$key,
    ]);
}

`

可以这样解决,自己手动获取$page
再把它放到Pagination的配置里面去
你记得,本身不配置params的时候,它都是从get参数里去取的,所以在你的引导超链接里岛上w关键字,在控制器里去拿到查询,这样分页会自带这个关键字的。这样的分页,什么都不用配置,感觉比较好
点击第二页也还是显示的选中第一页吗?那展示出来的数据是第一页的还是第二页的?视图的代码呢
请问你的这个sphinx是怎么配置的,能就这样实例化的用?

赞(0) 打赏
未经允许不得转载:菜鸟之家 » sphinx配置咨询[2.0]

评论 抢沙发

登录

找回密码

注册