背景
项目需求用到搜索引擎功能,fastadmin框架有比较成熟的插件xunsearch,如何灵活的提供给第三方产品使用。实战中根据不同条件查询记录
示例
//全文搜索public function search(){$keywords = $this->request->request('keywords');$type = (int)$this->request->request('type');$starttime = $this->request->request('starttime');$endtime = $this->request->request('endtime');//$description_type = $this->request->request('description_type');$format_type = $this->request->request('format_type');$free_type = $this->request->request('free_type');$page = $this->request->request('page');$page = $page?$page:1;$pagenum = $this->request->request('pagenum');$pagenum = $pagenum?$pagenum:20;$string='';if($type==1){if($keywords){$string=$string.'title:'.$keywords;}}elseif($type==2){if($keywords) {$string=$string.'description:'.$keywords;}}elseif($type==3){if($keywords){$string=$string.'author:'.$keywords;}}elseif($type==4){if($keywords){$string=$string.'source:'.$keywords;}}else{$string=$keywords;}if($format_type){if($string){$string=$string.' AND '.'formatId:'.$format_type;}else{$string=$string.'formatId:'.$format_type;}}if($free_type){if($string){$string=$string.' AND '.'is_free:'.$free_type;}else{$string=$string.'is_free:'.$free_type;}}$param=array();$from=$starttime;$to=$endtime;$param['body']=Xunsearch::instance('tnl')->search($string,$page,$pagenum,"createtime desc",true,false,false,$from,$to);$this->success('请求成功',$param);}
完美解决。