原 查问我看笔记功能的实现过程-全文搜索待开启,试试yiisoft/yii2-sphinx
查问我看笔记功能的实现的重点就是全文搜索,如果不用Yii自带的ActiveRecord的话,就要找扩展,先找了个yii-xunsearch,不行太差了,又找了yiisoft/yii2-elasticsearch,看了下使用方法和网上的文章,感觉太复杂了。试试yiisoft/yii2-sphinx
yiisoft/yii2-elasticsearch
yiisoft/yii2-sphinx
这里待续20200406 2217...
|-转 yii2框架中使用sphinx使用搜索引擎 多条件选择搜索
这个不是用的Yii2扩展yiisoft/yii2-sphinx的方式去用sphinx的,但是该文章提供了一个使用的思路,把符合条件的内容搜到了后,在把id的集合存到数组,用Yii自己的数据库模型去调用具体的搜索结果。
$res = $cl->Query ( $key, "mysql" );
if($res['total_found'] > 0){
$ids = [];
foreach ( $res['matches'] as $key => $row ) {
$ids[] = $row['id'];
}
$query = new Query();
$list = $query->select('j_id, post_tempt, ask_for')->from('job')->where(['in', 'j_id', $ids])->all();
https://blog.csdn.net/var_dz/article/details/53163389
最后发布于2016-11-14 19:52:45
首先,你需要安装spinx,具体安装可以百度一份如何安装,网上有很多,就不说了,
那么,安装完成后,打开sphinx(即你所建的sphinx安装目录),
找到这个文件,sphinx/etc/csft_mysql.conf文件,
在编译器中,打开这个文件,修改sphinx的源文件,配置
改完配置后,停止sphinx服务,打开cmd,进入到你安装的sphinx安装目录中
建立索引,
索引建立成功,开启sphinx服务
在使用sphinx之前,你需要把sphinx/api/sphinxapi.PHP文件,复制一份,放到yii2的web中,
与你的入口文件保持同级,方便调用
创建控制器,
[html] view plain copy
<?php
namespace frontend\controllers;
use Yii;
use app\models\Position;
//use yii\data\Pagination;//分页类
use yii\db\Query;//搜索类
class IndexController extends \yii\web\Controller
{
//下拉选项字段 搜索值
public function actionSearch_val()
{
$set = Yii::$app->request->get('set','');//接收搜索类型
$key = Yii::$app->request->get('key','');//接收值
require ( "sphinxapi.php" );//引入类
if(yii::$app->request->isAjax){
//echo $key.$set;die;
$cl = new SphinxClient ();
$cl->SetServer ( '127.0.0.1', 9312);
$cl->SetConnectTimeout ( 3 );
$cl->SetArrayResult ( true );
if(empty($key)){
$cl->SetMatchMode ( SPH_MATCH_FULLSCAN );
}else{
$cl->SetMatchMode ( SPH_MATCH_EXTENDED2 );
if($set == 1){
$key = $key;
}else if($set == 2){
$key = '@post_tempt ' .$key;
}else if($set == 3){
$key = '@ask_for ' .$key;
}
}
$res = $cl->Query ( $key, "mysql" );
if($res['total_found'] > 0){
$ids = [];
foreach ( $res['matches'] as $key => $row ) {
$ids[] = $row['id'];
}
$query = new Query();
$list = $query->select('j_id, post_tempt, ask_for')->from('job')->where(['in', 'j_id', $ids])->all();
//print_r($list);
} else {
$list = [];
}
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;...
|-原 运行php composer.phar require --prefer-dist yiisoft/yii2-sphinx
就是这么简单的安装
php composer.phar require --prefer-dist yiisoft/yii2-sphinx
一次性成功,nice
[root@izj]# php composer.phar require --prefer-dist yiisoft/yii2-sphinx Do not run Composer as root/super user! See https://getcomposer.org/root for details Using version ^2.0@dev for yiisoft/yii2-sphinx ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing yiisoft/yii2-sphinx (dev-master 04fd035): Downloading (100%) Package jeremeamia/superclosure is abandoned, you should avoid using it. Use opis/closure instead. Writing lock file Generating autoload files 10 packages you are using are looking for funding. Use the `composer fund` command to find out more! [root@izj]#
顺便删除了yii-xunsearch,开心 20200407 ...