dimanche 29 novembre 2015

Solr (solarium) connection with laravel 5 in database.php

I use laravel 5 and want to connect to solr 5 with it. I downloaded solarium using composer. But when i try to connect it gives an error.

What works

In my controller (just for now) i did this:

public function __construct()
{

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

    // create a client instance
    $this->client = new \Solarium\Client($config);
}

Then somewhere else i do this:

$temp = $this->client;

// get a select query instance
$query = $temp->createQuery($temp::QUERY_SELECT);

// this executes the query and returns the result
$resultset = $temp->execute($query);

// display the total number of documents found by solr
echo 'NumFound: '.$resultset->getNumFound();

So far this works. It returns the correct number of 1: NumFound: 1

Problem

Now i changed creating the instance to:

$this->client = new \Solarium\Client(\Config::get('solr')); 

I added this code in the config/database.php file:

'solr' => [

    'endpoint' => [
        'localhost' => [
            'host'     => '127.0.0.1',
            'port'     => 8983,
            'database' => '/solr/my_solr_instance',
        ],
    ],


],

Then, when i run the script again, it says:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/select. Reason:
<pre> Not Found</pre></p><hr><i><small>Powered by http://Jetty</small></i><hr/>

</body>
</html>

I would expect that i can set the connection to solr within the database.php file and et the variables of it in the .env file.

How can i solve this issue?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire