我使用laravel 5,并希望用它连接到solr 5。我使用composer下载了solarium。但当我尝试连接时,会出现错误。
什么有效
在我的控制器中(只是现在)我这样做了:
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文件中设置它的变量。
我该如何解决这个问题?
解决方案
在博格丹的帮助下,这就是解决方案:
$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')