yii框架中sphinx单条件搜索

1、sphinx单条件搜索创建索引、开启搜索服务,以下是我创建的表单

<center>
       <form action="index.php?r=sphinx/sphinx" method="post">
	    <input type="hidden" name="_csrf" value="<?= yii::$app->request->csrfToken?>" />
		<p>作者:<input type="text" name="value"></p>
		<p><input type="submit" value="搜索"></p>
	</form>
</center>


2、然后将coreseek中的csft_mysql.conf类方法yii框架的 yii\vendor\composer\ 下

在yii\vendor\autoload.php中添加

require_once __DIR__ . '/composer' . '/sphinxapi.php';

让其自动加载,如下

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';
require_once __DIR__ . '/composer' . '/sphinxapi.php';

return ComposerAutoloaderInit32b8eb537f8e12e57c5e7bade69d01f0::getLoader();/


3、在控制器中引用,然后编辑,如下,如果打印出数据库数据,就是成功了


<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\Search;
use SphinxClient; 
class SphinxController extends Controller
{
	public function actionIndex(){
		 return $this->render('index');
	}
	//sphinx单条件搜索
	public function actionSphinx(){
		//接收要搜索的值    
        $data=Yii::$app->request->post(); 
        $sphinx= new SphinxClient(); //实例化sphinx    
        $sphinx->SetServer('127.0.0.1',9312);//创建链接,9312微端口号   
        $res=$sphinx->Query($data['title'],"*");//执行搜索    
        //sphinx搜素把搜索结果的ID放在matches中返回    
        $id=implode(',', array_keys($res['matches'])) ;//取到结果的ID,拼接字符串  
        //以结果的ID集,来循坏取到每一条数据  
       	$where="id in ($id)";
         $arr= Search::find()->where($where)->asArray()->all();    
          
         
        //打印查看结果    
        print_r($arr);die;    
	}
}



基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计),个人经导师指导并认可通过的高分设计项目,评审分98分,项目中的源码都是经过本地编译过可运行的,都经过严格调试,确保可以运行!主要针对计算机相关专业的正在做大作业、毕业设计的学生和需要项目实战练习的学习者,资源项目的难度比较适中,内容都是经过助教老师审定过的能够满足学习、使用需求,如果有需要的话可以放心下载使用。 基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoot和微服务架构的养老机构管理系统源码(毕业设计)基于SpringBoo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值