为什么PHP Solr扩展会出现异常“不成功的查询请求”

时间:2012-11-20 07:55:10

标签: php exception solr

我使用PHP Solr extension,当我运行下面的代码时,我得到了异常:

  

致命错误:未捕获异常'SolrClientException',消息'查询失败:响应代码404。

我不明白,出了什么问题,我也成功使用了Solr客户端。

include "bootstrap.php";

$options = array
(
    'hostname' => SOLR_SERVER_HOSTNAME,
    'login'    => SOLR_SERVER_USERNAME,
    'password' => SOLR_SERVER_PASSWORD,
    'port'     => SOLR_SERVER_PORT,
);

$client = new SolrClient($options);    
$query = new SolrQuery();   
$query->setQuery('lucene');    
$query->setStart(0);    
$query->setRows(50);    
$query->addField('cat')->addField('features')->addField('id')-> addField('timestamp');    
$query_response = $client->query($query);    
$response = $query_response->getResponse();    
print_r($response);    
?>

我的bootstrap.php文件是:

<?php

/* Domain name of the Solr server */
//define('SOLR_SERVER_HOSTNAME', 'solr.example.com');//solr.example.com
define('SOLR_SERVER_HOSTNAME', 'localhost');//solr.example.com


define('SOLR_SECURE', true);


/* HTTP Port to connection */
//define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8080 : 8443));

/* HTTP Basic Authentication Username */
define('SOLR_SERVER_USERNAME', '');//admin

/* HTTP Basic Authentication password */
define('SOLR_SERVER_PASSWORD', '');//changeit

/* HTTP connection timeout */
/* This is maximum time in seconds allowed for the http data transfer operation. Default value is 30 seconds */
define('SOLR_SERVER_TIMEOUT', 10);

/* File name to a PEM-formatted private key + private certificate (concatenated in that order) */
define('SOLR_SSL_CERT', 'certs/combo.pem');

/* File name to a PEM-formatted private certificate only */
define('SOLR_SSL_CERT_ONLY', 'certs/solr.crt');

/* File name to a PEM-formatted private key */
define('SOLR_SSL_KEY', 'certs/solr.key');

/* Password for PEM-formatted private key file */
define('SOLR_SSL_KEYPASSWORD', 'StrongAndSecurePassword');

/* Name of file holding one or more CA certificates to verify peer with*/
define('SOLR_SSL_CAINFO', 'certs/cacert.crt');

/* Name of directory holding multiple CA certificates to verify peer with */
define('SOLR_SSL_CAPATH', 'certs/');

2 个答案:

答案 0 :(得分:8)

当我查询Solr时,我收到了类似的错误消息。

错误来自于我正在使用集合,因此您需要在配置中指定它:

$options = array
(
        'hostname' => 'localhost',
        'login'    => '',
        'password' => '',
        'port'     => 8983,
        'path'     => 'solr/collection', // <-- Add your collection here
);

答案 1 :(得分:1)

我能看到的问题是行

define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8080 : 8443));

是使用端口8080还是8443的安全连接? 我假设正常连接是8080,安全是8443,但线条暗示相反,安全端口是8080,正常连接是8443