dongpu1879 2015-07-29 18:10
浏览 47

从Mysql中向Solr V5添加多个文档的方法导致PHP

I just followed the example on this page as to how to add multiple documents from a database using Perl Solr extension.

Example Code:

$users = $dbh->prepare($sql);

$users->execute();

$result = $users->fetchAll(PDO::FETCH_ASSOC);

foreach($result as $k=>$r){
  $docs_array[$k] = new SolrInputDocument();

  $docs_array[$k]->addField('model_id', $r['model_id']);

  $docs_array[$k]->addField('name', $r['name']);
}

$updateResponse = $client->addDocument($docs_array);

It isn't working and giving this error:

Argument 1 passed to SolrClient::addDocument() must be an instance of SolrInputDocument, array given

So I guess the only way to make that work is adding documents one by one in each loop, like this:

foreach($result as $k=>$r){

  $doc = new SolrInputDocument();

  $doc->addField('model_id', $r['model_id']);

  $doc->addField('name', $r['name']);

  $updateResponse = $client->addDocument($doc);

}

Since there isn't enough document on this extension, I'd like to make sure if it is an appropriate way of doing that. Thank you.

  • 写回答

1条回答 默认 最新

  • duanjunao9348 2015-07-30 14:42
    关注

    You're linking to the documentation for addDocument->s<- while calling addDocument (without the plural s at the end).

    Use the correct method (addDocuments) and the documentation will be correct.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置