2013-05-16 34 views
2

我正在使用Solr PHP Client并且已启动并运行Solr 4.3.0示例。我没有修改schema.xml文件。当我运行这段代码我得到一个错误400使用Solr PHP客户端索引数据

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` 
+0

我使用相同的代码来提交我的数据,但仍无法在Solr管理员中搜索它。如果你是通过这个,你能帮我吗? – AppleBud

回答

4

这是一个已知问题的Solr 4.x和从Solr的PHP客户端调用commit。请参阅 Bug #62332 - As of solr 4.0 the waitFlush parameter is removed for commit了解详细信息以及修补问题的补丁。

+0

谢谢!你知道我如何应用这个补丁吗?这是我可以运行的shell脚本,如果我更改扩展名称?而且要清楚的是,Solr-PHP客户端是得到补丁的,是吗?不是Solr,对吗? – user1521567

+0

哦,它的PECL Solr PHP扩展程序得到了补丁。这看起来像它会变得复杂,虽然.. :( – user1521567

+0

看起来像你可以比较你的Service.php文件与这一个有必要的变化https://code.google.com/p/solr-php-client/ source/browse/trunk/Apache/Solr/Service.php#821,然后修改你的本地副本。 –

2

这就是我如何得到解决方案,我修改了提交方法。向_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); 
} 
0

您已更改此行。

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

也许Service.php这个文件的路径错了。我试图改变这条线。然后成功工作。

0

我有同样的问题,因为我已经安装了旧版本的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 

感谢this post