PHP code example of opendi / solrclient

1. Go to this page and download the library: Download opendi/solrclient library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

opendi / solrclient example snippets


use Opendi\Solr\Client\Client;

$guzzle = new \GuzzleHttp\Client([
    'base_uri' => "http://localhost:8983/solr/"
]);

$client = new Client($guzzle);

use Opendi\Solr\Client\Client;

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

$solr = new Client($guzzle);

use Opendi\Solr\Client\Client;

$solr = Client::factory('http://localhost:8983/solr/', [
    'timeout' => 10
]);

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

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

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

// Returns core status
$client->core('places')->status();

// Returns number of documents in a core
$client->core('places')->count();

// Deletes all records in the core
$client->core('places')->deleteAll();

// Deletes records matching a selector
$client->core('places')->deleteByQuery('name:Opendi');

// Deletes record with the given ID
$client->core('places')->deleteByID('100');

// Checks the core is up
$client->core('places')->ping();

// Optimizes core documents
$client->core('places')->optimize();

// Commits inserted documents
$client->core('places')->commit();