使用Solr PHP客户端索引数据

使用Solr PHP客户端索引数据,php,solr,Php,Solr,我正在使用Solr-PHP客户端,并启动并运行了Solr 4.3.0示例。我没有修改schema.xml文件。当我运行此代码时,我得到一个400错误: Uncaught exception 'Apache_Solr_HttpTransportException' with message '400' Status: Bad Request.' 该文档未显示在索引中。有趣的是,如果我重新启动Jetty,文档就会被索引。这是我的密码。我想知道我是否遗漏了什么。我认为这是我的输入与模式匹配的问题,但

我正在使用
Solr-PHP客户端
,并启动并运行了
Solr 4.3.0
示例。我没有修改
schema.xml
文件。当我运行此代码时,我得到一个
400
错误:

Uncaught exception 'Apache_Solr_HttpTransportException' with message '400' Status: Bad Request.'
该文档未显示在索引中。有趣的是,如果我重新启动
Jetty
,文档就会被索引。这是我的密码。我想知道我是否遗漏了什么。我认为这是我的输入与模式匹配的问题,但是
id
似乎是唯一必需的字段,而这些其他字段在模式中。我不知道该怎么办

require_once('SolrPhpClient/Apache/Solr/Service.php');

$solr = new Apache_Solr_Service('localhost', 8983, '/solr/');

if($solr->ping() == null){
    die('could not ping solr');
}

$document = new Apache_Solr_Document();
$document->id = 'guid1';
$document->title = 'Title1';
$document->subject = 'The subject is solr';
$document->description = 'This is the description';

$solr->addDocument($document);
$solr->commit();
我得到的完整错误消息是

Fatal error: Uncaught exception 'Apache_Solr_HttpTransportException' with message ''400' Status: Bad Request' in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php:364 
Stack trace: 
#0 C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php(829): Apache_Solr_Service->_sendRawPost('http://localhos...', '<commit expunge...', 3600)  
#1 C:\xampp\htdocs\dev\indexerSOLR_PHP.php(20): Apache_Solr_Service->commit()  
#2 {main} thrown in C:\xampp\htdocs\dev\SolrPhpClient\Apache\Solr\Service.php on line 364`
致命错误:在C:\xampp\htdocs\dev\solrpclient\Apache\Solr\HttpTransportException.php:364中出现未捕获异常“Apache\u Solr\u HttpTransportException”,消息为“400”状态:错误请求
堆栈跟踪:

#0 C:\xampp\htdocs\dev\solrpclient\Apache\Solr\Service.php(829):Apache\u Solr\u Service->\u sendRawPost('http://localhos...“,”这是Solr 4.x和从Solr PHP客户端调用commit的已知问题。请参阅
有关详细信息和修复问题的修补程序。

这就是我获得解决方案的原因,我修改了提交方法。在_updateurl变量中添加了“&commit=true”

public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
{
    $expungeValue = $expungeDeletes ? 'true' : 'false';
    $flushValue = $waitFlush ? 'true' : 'false';
    $searcherValue = $waitSearcher ? 'true' : 'false';

    //$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
            //$this->post=$rawPost;        
    return $this->_sendRawGet($this->_updateUrl.'&commit=true', $timeout);
}
public函数提交($expungeDeletes=false,$waitFlush=true,$waitSearcher=true,$timeout=3600)
{
$expungeValue=$expungeDeletes?'true':'false';
$flushValue=$waitFlush?'true':'false';
$searcherValue=$waitSearcher?'true':'false';
//$rawPost='';
//$this->post=$rawPost;
返回$this->_sendRawGet($this->_updateUrl.&commit=true',$timeout);
}

您必须更改此行

require_once('solrppclient/Apache/Solr/Service.php');=>require_once('Service.php')


可能Service.php此文件的路径错误。我尝试更改此行,然后成功运行。

我遇到了相同的问题,因为我安装了旧版本的php Solr扩展(0.9.11)

要获取最新版本,请执行以下操作:

pecl download solr-beta
tar xvzf solr-2.1.0.tgz # This can be different depending on the last release number
cd solr-2.1.0/
phpize
./configure
make
sudo make install
# add extension=solr.so to your php.ini / distribution extension loader

谢谢。

谢谢!你知道我是如何应用补丁的吗?如果我更改扩展名,这是一个可以运行的shell脚本吗?很清楚,Solr PHP客户端是get修补的对象,是吗?不是Solr,对吗?噢,get修补的是PECL Solr PHP扩展。这看起来很复杂(看起来你可以将你的Service.php文件与这个有必要更改的文件进行比较,然后只修改你的本地副本。我使用相同的代码提交数据,但仍然无法在Solr Admin上搜索。如果你完成了,你能帮我吗?