All Projects → cpliakas → psolr

cpliakas / psolr

Licence: MIT license
A simple PHP client for Apache Solr that is built on top of Guzzle and inspired by RSolr.

Programming Languages

PHP
23972 projects - #3 most used programming language

PSolr

Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Total Downloads License

A simple PHP client for Apache Solr that is built on top of Guzzle and inspired by RSolr.

Installation

PSolr can be installed with Composer by adding the library as a dependency to your composer.json file.

{
    "require": {
        "cpliakas/psolr": "*"
    }
}

After running php composer.phar update on the command line, include the autoloader in your PHP scripts so that the SDK classes are made available.

require_once 'vendor/autoload.php';

Please refer to the Composer's documentation for installation and usage instructions.

Usage

Client Instantiation

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

Searching Documents

$select = Request\Select::factory()
  ->setQuery('*:*')
  ->setStart(0)
  ->setRows(10)
;

$response = $select->sendRequest($solr);
$response->numFound();

For simple use cases:

$response = $solr->select(array('q' => '*:*'));

Adding Documents

$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)

Deleting Documents

$response = Request\Delete::factory()
    ->addId('123')
    ->addId('456')
    ->addQuery('platform:solr')
    ->sendRequest($solr)
;

Sending Arbitrary Solr Requests

$response = $solr->get('admin/ping?wt=json')->send()->json();

Refer to Guzzle's documentation for more details on making web requests.

Refer to Apache Solr's documentation for more details on the API.

Integrations

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].