cpliakas / psolr
A PHP 客户端用于 Apache Solr。
0.6.3
2014-02-18 12:53 UTC
Requires
- php: >=5.3.0
- guzzle/service: ~3.0
Requires (Dev)
- pdepend/pdepend: ~1.0
- phploc/phploc: ~2.0
- phpunit/phpunit: ~3.0
- satooshi/php-coveralls: dev-master
README
一个简单的 PHP 客户端,用于 Apache Solr,基于 Guzzle 构建,并受到 RSolr 的启发。
安装
可以使用 Composer 安装 PSolr,将其作为依赖项添加到您的 composer.json 文件中。
{ "require": { "cpliakas/psolr": "*" } }
在命令行上运行 php composer.phar update
后,请将自动加载器包含到您的 PHP 脚本中,以便 SDK 类可用。
require_once 'vendor/autoload.php';
有关安装和用法说明,请参阅 Composer 的文档。
使用
客户端实例化
use PSolr\Client\SolrClient; use PSolr\Request as Request; // Connect to a Solr server. $solr = SolrClient::factory(array( 'base_url' => 'http://myserver.com:8080', // defaults to "http://localhost:8983" 'base_path' => '/solr/myIndex', // defaults to "/solr" ));
搜索文档
$select = Request\Select::factory() ->setQuery('*:*') ->setStart(0) ->setRows(10) ; $response = $select->sendRequest($solr); $response->numFound();
对于简单用例
$response = $solr->select(array('q' => '*:*'));
添加文档
$add = Request\Add::factory(); $document = new Request\Document(); $document->id = '123'; $document->title = 'Test document'; $document->tag = 'Category 1'; $document->tag = 'Category 2'; $add->addDocument($document); $response = $add->sendRequest($solr)
删除文档
$response = Request\Delete::factory() ->addId('123') ->addId('456') ->addQuery('platform:solr') ->sendRequest($solr) ;
发送任意 Solr 请求
$response = $solr->get('admin/ping?wt=json')->send()->json();
有关发送 Web 请求的详细信息,请参阅 Guzzle 的文档。
有关 API 的详细信息,请参阅 Apache Solr 的文档。