fastadmin集成xunsearch实战应用

背景

项目需求用到搜索引擎功能,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);
    }

完美解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值