php使用solr筆記

error_reporting(E_ALL);
            ini_set("display_errors",1);
            $options = array('hostname' => '121.40.78.29','wt' => 'json','path' => '/solr/goods',"port"=>"8080");
            $client = new SolrClient($options);
            $query = new SolrQuery();

            $tagkey = "馬代夫";
            $query->setParam("q",$tagkey);
            $query->setParam("qt","search");
            $query->setParam("fl","id,uid,recommend,istop,ishot,category,name,tags,close_time,start_city");
            $query->setParam("df","name");
            $query->setParam("defType","edismax");

            //經過一些條件篩選啦
            //$params->setParam("fq","recommend:true && ishot:false");
            $query->setParam("fq","category:1");

            //根據需求,標題匹配60,標籤匹配40
            $query->setParam("qf","name^60 tags^40");

            //1.關鍵詞和標題徹底匹配的權重最高 if(exists(query({!v=uid:"+tag+"})),10000,0)
            //2.商家是壹旅程的100,若是uid=3的時候,權重加上100,不然不加 if(exists(query({!v=uid:3})),100,0))
            //3.若是用戶選擇了「推薦」(是修改老的產品功能,如今有熱門) 該產品權重增長120分
            $query->setParam("bf",'sum(if(exists(query({!v=name:'.$tagkey.'})),10000,0),if(exists(query({!v=uid:3})),100,0),if(exists(query({!v=ishot:true})),120,0))');
            $query->setStart(0);
            $query->setRows(20);

            $resp = $client->query($query);
            $r = $resp->getResponse();
            $this->display();
相關文章
相關標籤/搜索