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.
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.