Client for Apache Solr

Installs: 166

Dependents: 0

Stars: 1

Watches: 5

Forks: 1

Language: PHP

0.5.0 2015-04-07 10:36 UTC


Classes for the busy PHP developer to work with Apache Solr.

Codeship Status for opendi/solrclient


First, you must construct a Guzzle HTTP client and set the base_url option to the Solr endpoint you wish to work with. Then use it to create a Solr Client.

use Opendi\Solr\Client\Client;

$guzzle = new \GuzzleHttp\Client([
    'base_url' => "http://localhost:8983/solr/"

$client = new Client($guzzle);

It's also possible to pass some default request options, such as headers and timeouts to the Guzzle client.

use Opendi\Solr\Client\Client;

$guzzle = new \GuzzleHttp\Client([
    'base_url' => "http://localhost:8983/solr/",
    'defaults' => [
        'timeout' => 10

$solr = new Client($guzzle);

See Guzzle documentation for all options.

There is a helper factory() method which does the same as above.

use Opendi\Solr\Client\Client;

$url = "http://localhost:8983/solr/";

$defaults = [
    'timeout' => 10

$solr = Client::factory($url, $defaults);

Working with cores

A core is solar terminology for a collection of records. To select a core, use the core($name) method on the Solr Client.

$core = $client->core('places');

// Perform a select query
$select = Solr::select()->search('name:Franz');

// Perform an update query
$update = Solr::update()->body('{}');

The Core object also offers some helper methods:

// Returns core status

// Returns number of documents in a core

// Deletes all records in the core

// Deletes records matching a selector

// Deletes record with the given ID