当前位置: 首页 > 工具软件 > php_solr > 使用案例 >

php使用solr,php使用solr笔记

牛迪
2023-12-01

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();

 类似资料: