lionear / solr-client
PHP Solr 客户端
1.0.0
2018-01-16 19:01 UTC
Requires
- php: ~7.1
- guzzlehttp/guzzle: ^6.2
- illuminate/support: ^5.2
- symfony/console: ^4
- symfony/filesystem: ^4
- symfony/finder: ^4
- symfony/stopwatch: ^4
Requires (Dev)
- phpmd/phpmd: ~2.3
- phpunit/phpunit: ~4.8 || ~5.0
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-09-29 03:47:11 UTC
README
这是一个PHP库,旨在简化与SOLR服务器的交互
这个分支已与Symfony 4兼容,版本1.0
安装
推荐方法是通过composer
composer require lionear\php-solr-client
请确保包含自动加载器
require_once "vendor/autoload.php"
使用
快速入门
$client = new SolrClient('localhost', '8983'); $client->setCore('gettingstarted'); // Adding document $client->add( new SolrDocument([ 'id' => 1, 'title_s' => 'Title' ]); ); $client->commit(); // Searching document $result = $client->query('title_s:title'); echo $result->getNumFound(); // 1 foreach ($result->getDocs() as $doc) { echo $doc->title_s; // 'Title' } // Getting a single document $doc = $client->get(1); echo $doc->title_s; // 'Title'
搜索
可以将搜索参数传递给search()函数,该函数将返回一个SolrSearchResult实例
// Search with custom parameters $result = $client->search([ 'q' => '+title:fish -description:shark', 'rows' => 15, 'start' => 0 ]); // Pagination Support $nextPage = $result->next(15, $client); // Facet support $result = $solr->setFacet('subject')->query('*:*'); $subjectFacet = $result->getFacet('subject');
索引
// autocommit enabled to commit after every add $doc = new SolrDocument; $doc->id = 2; $doc->title_s = "Second Document"; $doc->description_s = "Some description"; $client->add($doc);
删除
// delete by id field $client->remove(2); // delete by query $client->removeByQuery('id:2');
游标
为了使用SOLR CursorMark功能,这对于导出记录非常有用
// search for all documents that has a subject field match aquatic, by 10 at a time $search = [ 'q' => 'subject:aquatic' ]; while($payload->getNextCursorMark() != $payload->getCursorMark()) { $payload = $client->cursor($payload->getNextCursorMark(), 10, $search); print_r($payload); }
命令
以协助对现有SOLR服务器进行常见操作
// List of help commands
bin/console help
// List of help commands for solr:run command
bin/console solr:run -h
// Run optimize on default SOLR instance
bin/console solr:run -d optimize
// Exports all records from collection1 to /tmp/export/ directory
bin/console solr:export -s localhost -p 8983 -c collection1 -t /tmp/export/
// Import the records to another SOLR instance
bin/console solr:import -s example.org -p 8983 -c collection2 -t /tmp/export/