简体   繁体   English

Solr PHP客户端索引数据

[英]Index data with Solr PHP Client

I'm using the Solr PHP Client and have the Solr 4.3.0 example up and running. 我正在使用Solr PHP Client并已启动并正在运行Solr 4.3.0示例。 I have not modified the schema.xml file. 我尚未修改schema.xml文件。 When I run this code I get a 400 error: 当我运行此代码时,出现400错误:

Uncaught exception 'Apache_Solr_HttpTransportException' with message '400' Status: Bad Request.'

The document does not show up in the index. 该文档未显示在索引中。 Interestingly, If I restart Jetty , the document is indexed. 有趣的是,如果我重新启动Jetty ,该文档将被索引。 Here's my code. 这是我的代码。 I was wondering if I'm missing something. 我想知道我是否想念一些东西。 I thought this was an issue with my input matching the schema, but id seems to be the only required field and these other fields are in the schema. 我认为这是我的输入与模式匹配的问题,但是id似乎是唯一必填字段,而其他字段在模式中。 I'm not sure what to do. 我不确定该怎么办。

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();

The full error message I get is 我收到的完整错误消息是

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`

This is a known issue with Solr 4.x and calling commit from the Solr PHP Client. 这是Solr 4.x的一个已知问题,它是从Solr PHP客户端调用提交的。 Please see Bug #62332 - As of solr 4.0 the waitFlush parameter is removed for commit for the details and a patch to fix the issue. 请参阅错误#62332-从solr 4.0开始,删除了waitFlush参数以提交详细信息以及解决此问题的补丁程序。

That is what how I got the solution, I modified commit method. 这就是我获得解决方案的方式,我修改了commit方法。 Added '&commit=true' to the _updateurl variable. 在_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);
}

You have change this line. 您已更改此行。

require_once('SolrPhpClient/Apache/Solr/Service.php'); require_once( 'SolrPhpClient /阿帕奇/ Solr的/ Service.php'); => require_once('Service.php'); => require_once('Service.php');

Maybe Service.php this file's path wrong. 也许Service.php这个文件的路径错误。 I try to changed this line. 我尝试更改此行。 Then work successfully. 然后工作成功。

I had the same issue because I have installed an old version of the PHP Solr extension (0.9.11). 我遇到了同样的问题,因为我安装了旧版本的PHP Solr扩展(0.9.11)。

To get a the latest one: 要获取最新版本:

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

Thanks to this post . 感谢这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM