1

I've included Solarium as required on composer.json, did composer install and everything went fine.

However, when I try to create a client stance, I get an error:

Class 'Solarium\Client' not found

The code I'm using goes like this:

public function __construct()
{
    $config = array(
        'endpoint' => array(
            'localhost' => array(
                'host' => '127.0.0.1',
                'port' => 8983,
                'path' => '/solr/my_solr_instance',
                )
            )
        );

    $this->client = new \Solarium\Client($config);
}

Any ideas on how to fix this?

Paulo Manrique
  • 263
  • 1
  • 4
  • 13

2 Answers2

3

After installing solarium in laravel ..

create a file solr.php in config

return [
    'endpoint' => [
        'Collection' => [
            'host' => '192.168.0.1',
            'port' => '8983',
            'path' => '/solr',
            'core' => 'collection1'
        ],
    ]
];

IN your controller construction initiate client object

// create a client instance
        $this->client = new \Solarium\Client();
        $this->endpoint =  $this->client->createEndpoint(Config::get('solr.endpoint.Collection'));

In search function

$query = $this->client->createSelect();
$query->setQuery("*:*");
$resultset = $this->client->select($query, $this->endpoint);
Manish Nakar
  • 4,286
  • 1
  • 18
  • 13
0

I have a new approach for this initiate client from the controller. I have found this solution here as below it is not good to post complete code.

https://universaldetails.com/details/how-to-use-php-solarium-in-a-laravel-project

I have tried it and tested also so will help you.