什么是Solrium原文:https://www.hoehub.com/PHP/97.htmlSolarium是Solr的PHP客户端库Solarium是一个PHPSolr客户端库,可以准确地模拟Solr的概念。在业务层面使用Solarium可以更专业,不管官方对Solr底层通信的描述:WhatisSolarium?Solrium是一个PHPSolr客户端库,可以准确地模拟Solr概念。许多其他Solr库仅处理与Solr的通信,而Solarium还使您免于使用记录良好的API处理所有复杂的Solr查询参数。易于使用//导入类使用Solarium\Core\Client\Client作为SolrClient;demo$config=['endpoint'=>['endpoint1'=>['host'=>'localhost','port'=>'8983','path'=>'/solr','core'=>'endpoint1','timeout'=>15,],'endpoint2'=>['host'=>$host,'port'=>$port,'path'=>$path,'core'=>'endpoint2','timeout'=>15,],...]];//实例client$solrClient=newSolrClient($config);//设置默认端点$solrClient->setDefaultEndpoint('endpoint1');//查询示例$query=$solrClient->createSelect();//查询姓名为张晓明的文档$query->createFilterQuery('name')->setQuery('name:ZhangXiaoming');//对应的url大概是这样的http://localhost:8983/solr/SResume/select?q=name%3A张晓明&wt=json&indent=true//查询$query->createFilterQuery('gender')->setQuery('gender:m');//对应的url大概是这样的http://localhost:8983/solr/SResume/select?q=gender%3Am&wt=json&indent=true//排除删除的$query->createFilterQuery('deleted_at')->setQuery('-deleted_at:*');//对应的url大概是这样的http://localhost:8983/solr/SResume/select?q=*%3A*&fq=-deleted_at%3A*&wt=json&indent=true//查询$query->createFilterQuery('age')->setQuery('age:[20TO*]');//对应的url大概是像这样http://localhost:8983/solr/SResume/select?q=age%3A%5B20+TO+*%5D&wt=json&indent=true//区间查询$query->createFilterQuery('age')->setQuery('age:[20TO30]');//对应的url大概是这样的http://localhost:8983/solr/SResume/select?q=age%3A%5B20+TO+30%5D&wt=json&indent=true$query->setFields('分数','姓名','性别','deleted_at','age');$query->setSorts(['score'=>$query::SORT_DESC]);//按分数排序$query->setOmitHeader(false);//得到结果$resultSet=$this->solrClient->select($query);
