SolrPhpClient 支持solr4.x 的问题

今天用最新版本的SolrPhpClient SolrPhpClient.r60.2011-05-04   支持之前搭建的环境 (PHP mysql  solr4.3.1) 时,进行查询时没有问题的


主要代码部分如下:
require_once('Apache/Solr/Service.php');
function searchBlogs($queryQ){
  $solr = new Apache_Solr_Service('localhost', 8080, '/solr/');
  if (get_magic_quotes_gpc() == 1)
  {
    $queryQ = stripslashes($queryQ);
  }
  try
  {
    $results = $solr->search($queryQ, 0, $GLOBALS['limit']);
  }
  catch (Exception $e)
  {
     die("<html><head><title>SEARCH EXCEPTION</title><body><pre>{$e->__toString()}</pre></body></html>");
  }
  if ($results)
  {
 $total = (int) $results->response->numFound;
 $start = min(1, $total);
 $end = min($GLOBALS['limit'], $total);
  }
  foreach ($results->response->docs as $doc)
  {
  // iterate document fields / values
   $s_id="";
   $s_title="";
   $s_content="";
   foreach ($doc as $field => $value)
   {
     if($field=='id'){
      $s_id=$value;
     }elseif($field=='title'){
      $s_title=$value;
     }elseif($field=='content'){
      $s_content=$value;
     }
   }
}
?>




但是发布内容,需要将新添加的内容建立索引时,按网上写的方法就报错了,代码如下:
  $solr = new Apache_Solr_Service('localhost', 8080, '/solr/');
  $doc =  new Apache_Solr_Document();
  $doc->addField('id', 1234);
  $doc->addField('title','chinese work');
  $doc->addField('content', 'chinese work partner');
  $solr->addDocument($doc);
  $solr->commit();
  $solr->optimize(true);

错误信息主要为:

Unknown commit parameter waitflush
Unknown attribute id in add: allowDups
Unknown attribute id in add: overwritePending
Unknown attribute id in add: overwriteCommitted



后来google 出原因是solr4.x 版本太高,当前的SolrPhpClient 版本还不能完美支持,解决办法如下:
找到Apache/Solr 文件夹下的 Service.php,将里面带有 waitflush  allowDups  overwritePending  overwriteCommitted部分的内容都去掉,就可以了,经测试,可以用上面的代码进行索引的更新了,问题解决。


你可能感兴趣的:(PHP,Solr,SolrPhpClient)