Solarium简易使用
Solarium是什么
原文: https://www.hoehub.com/PHP/97.html
Solarium
是Solr
的PHP
客户端类库
官方描述:
What is Solarium?Solarium is a PHP Solr client library that accurately model Solr concepts. Where many other Solr libraries only handle the communication with Solr, Solarium also relieves you of handling all the complex Solr query parameters using a well documented API.
简易使用
// 引入类 use Solarium\Core\Client\Client as 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 = new SolrClient($config); // 设置默认的Endpoint $solrClient->setDefaultEndpoint('endpoint1'); // 实例查询器 $query = $solrClient->createSelect(); // 查询姓名为张小明的文档 $query->createFilterQuery('name')->setQuery('name:张小明'); // 对应url大概是这样 http://localhost:8983/solr/SResume/select?q=name%3A张小明&wt=json&indent=true // 查询性别为m的 $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 // 查询年龄在20岁以上的 $query->createFilterQuery('age')->setQuery('age:[20 TO *]'); // 对应url大概是这样 http://localhost:8983/solr/SResume/select?q=age%3A%5B20+TO+*%5D&wt=json&indent=true // 区间查询 $query->createFilterQuery('age')->setQuery('age:[20 TO 30]'); // 对应url大概是这样 http://localhost:8983/solr/SResume/select?q=age%3A%5B20+TO+30%5D&wt=json&indent=true $query->setFields('score', 'name', 'gender', 'deleted_at', 'age'); $query->setSorts(['score' => $query::SORT_DESC]); // 按分数排序 $query->setOmitHeader(false); // 获取结果 $resultSet = $this->solrClient->select($query);
相关推荐
spylyt 2020-09-11
upxiaofeng 2020-06-11
TyCoding 2020-05-03
upxiaofeng 2020-04-30
lionelf 2020-04-20
TyCoding 2020-04-08
TyCoding 2020-03-26
wenchanter 2020-03-26
roygbip 2020-02-16
wsxsxz 2020-02-03
lionelf 2020-02-03
lionelf 2020-02-03
TyCoding 2020-02-01
heniancheng 2020-01-31
lionelf 2020-01-30
TyCoding 2020-01-10