Apache Solr with Php


Apache Solr with Php

我正在尝试为我的一个项目设置apache solr搜索。我已经在我的开发服务器上安装了solr 3.6,并且可以通过

访问它。
http://127.0.0.1:8080/solr/admin/

我试图把样例应用程序可在php手册,但它是设置用户名和密码为solr。我不确定从哪里可以得到这个信息。我也尝试过下面的代码从网络,但我得到500错误每当我运行它

$options = array (
    'hostname' => '127.0.0.1',
);
//$client = new SolrClient($options, "4.0"); // use 4.0 for any version of Solr 4.x, ignore this parameter for previous versions
$doc = new SolrInputDocument();
$doc->addField('id', 100);
$doc->addField('title', 'Hello Wolrd');
$doc->addField('description', 'Example Document');
$doc->addField('cat', 'Foo');
$doc->addField('cat', 'Bar');
$response = $client->addDocument($doc);
$client->commit();
/* ------------------------------- */
$query = new SolrQuery();
$query->setQuery('hello');
$query->addField('id')
->addField('title')
->addField('description')
->addField('cat');
$queryResponse = $client->query($query);
$response = $queryResponse->getResponse();
print_r( $response->response->docs );

请帮

你的solr版本是3.6,所以你应该分配$client = new SolrClient($options);

$client = new SolrClient($options, "4.0"); // I see that in your code you commented this line which is required thinking that it is only for solt 4.x in your case, you should uncomment it and only remove the "4.0" in order to create a client.

创建客户端:

$options = array (
    'host' => "localhost",
    'port' => 8983, //port is required
    'path' => '/solr/collection1', //collection1 or core are mandatory it can be just /solr/
);
$client = new SolrClient($options); //for solr 3.x

根据示例代码,您没有在$options数组中设置端口。应该是:

  var $options = array(
       'hostname' => '127.0.0.1',
       'port' => '8080',
  );

这可能是500错误的原因。

你需要添加3个东西host, port和webapp。我希望你已经包含了service.php文件。

var $options = array(
   'hostname' => '127.0.0.1',
   'port' => '8080', //Port number where solr runs.
   'webapp' => '/solr/',  //path of the webapp.
);

主站配置

对于您的主站点的settings.php文件,您不需要更改太多。将$databases数组保留为。主站点将存储所有用户名、密码和会话。对于在您的主站点中的settings.php文件,您不需要更改太多。将$databases数组保留为。主站点将存储所有用户名、密码和会话。

$databases = array(
    'default' =>
    array(
        'default' =>
        array(
            'database' => 'drupal1',
            'username' => 'username',
            'password' => 'password',
            'host' => 'localhost',
            'port' => '',
            'driver' => 'mysql',
            'prefix' => '',
        ),
    ),
);

从站点配置

对于某些表,特别是那些包含用户信息的表,从站点应该连接到主站点的数据库。对于从站点中的settings.php文件,您需要指定主站点数据库并调用其用户和其他表。我们可以通过在$databases数组的"prefix"键中添加配置设置来实现。
$databases = array(
    'default' =>
    array(
        'default' =>
        array(
            'database' => 'drupal2',
            'username' => 'username',
            'password' => 'password',
            'host' => 'localhost',
            'port' => '',
            'driver' => 'mysql',
            'prefix' => array(
                'default' => 'drupal2.',
                'users' => 'drupal1.',
                'sessions' => 'drupal1.',
                'role' => 'drupal1.',
                'authmap' => 'drupal1.',
                'users_roles' => 'drupal1.',
            ),
        ),
    ),
);

有关更详细的说明,请访问-如何在php中设置和使用Apache Solr