繁体   English   中英

Solr(Solarium)与laravel 5在database.php中的连接

[英]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();

到目前为止,这有效。 它返回正确的数字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')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM