[英]Index data with Solr PHP Client
我正在使用Solr PHP Client
并已启动并正在运行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`
这是Solr 4.x的一个已知问题,它是从Solr PHP客户端调用提交的。 请参阅错误#62332-从solr 4.0开始,删除了waitFlush参数以提交详细信息以及解决此问题的补丁程序。
这就是我获得解决方案的方式,我修改了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);
}
您已更改此行。
require_once( 'SolrPhpClient /阿帕奇/ 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
感谢这篇文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.