【无标题】ES 在PHP中的语法格式
2022/2/10 20:22:06
本文主要是介绍【无标题】ES 在PHP中的语法格式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public function searchDocument($param) { //以下拼接是根据这条sql进行转换的 // [data] => (find_in_set(channel,'RS,TM,CISS-Normal') or universal = 1) and (type like "%Ecommerce%" or type like "%Telephone%") and (title like '%测试%' or content like '%测试%' or find_in_set('测试',taglist) or filelist like '%测试%') and (find_in_set('C12+RC700',model) or model = '') // 通过 http://www.atotoa.com/ 转换了下面这条sql or 和 and 这种php结构 // select *from kb_faq where (a=1 or universal = 1) and (b = 2 or c=3) //'keys'=>$keys,'jx'=>$jx,'channel'=>$channel,'type'=>$type,$p,$page_size //下面的拼接就是围绕着这种结构体一点点拼的 if(!isset($param['keys']) && !isset($param['jx'])){ return 'error 缺少必要参数!'; } //分页偏移量 if(!isset($param['p']) || $param['p'] == ''){ $param['p'] = 0; } //分页条数 if(!isset($param['page_size']) || $param['page_size'] == ''){ $param['page_size'] = 30; } //es搜索条件 $esWhere = []; if($param['channel']){ $esWhere['bool']['must'][]['bool']['should'] = [['match' => ['channel' =>['query'=>$param['channel'],'analyzer'=>'ik_smart'] ]],['match' => ['universal' =>['query'=>1] ]]]; } if($param['type']){ $esWhere['bool']['must'][]['bool']['should'] = ['match' => ['type' =>['query'=>$param['type'],'analyzer'=>'ik_smart'] ]]; } if($param['keys']){ $esWhere['bool']['must'][]['bool']['should'] = [['match' => ['filelist' => ['query'=>$param['keys'],'analyzer'=>'ik_smart','minimum_should_match'=>'100%']]],['match' => ['taglist' =>['query'=>$param['keys'],'analyzer'=>'ik_smart','minimum_should_match'=>'100%'] ]],['match' => ['content' =>['query'=>$param['keys'],'analyzer'=>'ik_smart','minimum_should_match'=>'100%'] ]],['match' => ['title' =>['query'=>$param['keys'],'analyzer'=>'ik_smart','minimum_should_match'=>'100%'] ]]]; } if($param['jx']){ $esWhere['bool']['must'][]['bool']['should'] = [['match' => ['model' =>['query'=>'quan'] ]],['match' => ['model' =>['query'=>$param['jx'],'analyzer'=>'ik_smart'] ]]]; } // 排序 $esOrder = ['searchnum' => 'DESC']; $esOrder = json_encode($esOrder); // $esGroup = [['groupByfaq' => ['terms'=>['field'=>'faqcode','size'=>200]]],['aggs'=>['name'=>['top_hits'=>['size'=>10,'_source'=>'name']]]]]; // $esGroup = json_encode($esGroup); $esWhere = $esWhere ? json_encode($esWhere) : ''; //es搜索 '"aggs":'.$esGroup.' $Where = [ 'size' => $param['page_size'], 'from' => $param['p'], 'index' => $this->index, 'type' => $this->type, 'body' => '{ "query": '.$esWhere.','. '"sort": '.$esOrder.' }' ]; // print_r($Where);die; $response = $this->client->search($Where); $hits = isset($response['hits']['hits']) ? $response['hits']['hits'] : ''; $newArr = []; if($hits){ foreach ($hits as $k => $v){ $newArr[] = $hits[$k]['_source']; } } return $newArr; }
这篇关于【无标题】ES 在PHP中的语法格式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享
- 2024-11-01开源 PHP 商城项目 CRMEB 安装和使用教程
- 2024-11-01用php和mysql写无限分类,有哪几种方法-icode9专业技术文章分享
- 2024-10-31php数据分表导出时部分数据无法导出什么原因-icode9专业技术文章分享
- 2024-10-30有经验的 PHP 开发者学习一门新的编程语言,有哪些推荐的有前景的语言-icode9专业技术文章分享
- 2024-10-21php 检测图片是否篡改过-icode9专业技术文章分享
- 2024-10-20fruitcake/php-cors 该怎么使用-icode9专业技术文章分享
- 2024-10-18PHP7.1可以使用哪个版本的swoole-icode9专业技术文章分享