【问题标题】:Solr (solarium) connection with laravel 5 in database.phpSolr(日光浴室)与 database.php 中的 laravel 5 连接
【发布时间】:2016-03-03 03:43:11
【问题描述】:

我使用 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: 发现数: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',
        ],
    ],
],

【问题讨论】:

    标签: php laravel solr laravel-5 solarium


    【解决方案1】:

    我相信你需要得到 database 配置:

    Config::get('database.solr')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-01
      • 2013-07-04
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      相关资源
      最近更新 更多