PHP code example of tsterker / solarium

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

    

tsterker / solarium example snippets


        'Solarium' => TSterker\Solarium\Facades\Solarium::class,

use TSterker\Solarium\Facades\Solarium;
// you can alias this in config/app.php if you like

Solarium::getEndpoint()->setCollection($this->collection);
// or configure a default core/collection in the config/solarium.php

$select = Solarium::createSelect();

$docs = Solarium::select($select)->getDocuments();

use TSterker\Solarium\SolariumManager;

class Searcher
{
    protected $solarium;

    protected $collection = 'default-collection';

    public function __construct(SolariumManager $solarium)
    {
        $solarium->getEndpoint()->setCollection($this->collection);
        $this->solarium = $solarium;
    }

    /* @return \Solarium\QueryType\Select\Result\Document[] */
    public function all(): array
    {
        $select = $this->solarium->createSelect();

        return $this->solarium->select($select)->getDocuments();
    }
}

app(Searcher::class)->all();

$this->app->singleton('solarium.adapter', function () {
    $factory = new Psr17Factory();
    return new Psr18Adapter(new Psr18Client(), $factory, $factory);
});
sh
$ php artisan vendor:publish --provider TSterker\\Solarium\\SolariumServiceProvider