database.php 中与 laravel 5 的 Solr(日光浴室)连接

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

我使用 laravel 5 并想用它连接到 solr 5。我使用作曲家下载了日光浴室。但是当我尝试连接时出现错误。

有效方法

在我的控制器中(只是现在)我这样做了:

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

然后我在其他地方这样做:

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

到目前为止这有效。它returns正确的数字1: NumFound:1

问题

现在我将创建实例更改为:

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

我在 config/database.php 文件中添加了这段代码:

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

然后,当我再次 运行 脚本时,它说:

<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 Jetty://</small></i><hr/>

</body>
</html>

我希望我可以在 database.php 文件中设置与 solr 的连接,并在 .env 文件中设置它的变量。

我该如何解决这个问题?


解决方案

在 Bogdan 的帮助下,这是解决方案:

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

在 database.php 文件中:

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

我相信您需要获取数据库配置:

Config::get('database.solr')