PHP code example of cpliakas / psolr

1. Go to this page and download the library: Download cpliakas/psolr 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/ */

    

cpliakas / psolr example snippets




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

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