【问题标题】:Index data with Solr PHP Client使用 Solr PHP 客户端索引数据
【发布时间】:2013-05-16 15:35:36
【问题描述】:

我正在使用 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 Admin 上搜索它。如果你完成了这个,你能帮帮我吗?

标签: php solr


【解决方案1】:

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

【讨论】:

  • 谢谢!你知道我如何应用补丁吗?如果我更改扩展名,这是我可以运行的 shell 脚本吗?需要明确的是,Solr-PHP-client 是被修补的,是吗?不是 Solr,对吗?
  • 哦,它是获得补丁的 PECL Solr PHP 扩展。不过,这似乎会很复杂.. :(
  • 看起来您可以将您的 Service.php 文件与具有必要更改 code.google.com/p/solr-php-client/source/browse/trunk/Apache/… 的文件进行比较,然后修改您的本地副本。
【解决方案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);
}

【讨论】:

    【解决方案3】:

    你已经改变了这一行。

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

    也许Service.php这个文件的路径不对。我试图改变这条线。然后顺利工作。

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2011-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多