Using PHP to add documents to the Solr index
Let us see the code to add documents to Solr using the Solarium library. When we execute the following query we can see that there are three books of the author George R R Martin in our Solr index:
http://localhost:8080/solr/collection1/select/?q=martin
Let us add the remaining two books, which have also been published to our index:
Create a solarium client using the following code:
$client = new Solarium\Client($config);
Create an instance of the update query using the following code:
$updateQuery = $client->createUpdate();
Create the documents you want to add and add fields to the document.
$doc1 = $updateQuery->createDocument(); $doc1->id = 112233445; $doc1->cat = 'book'; $doc1->name = 'A Feast For Crows'; $doc1->price = 8.99; $doc1->inStock = 'true'; $doc1->author = 'George R.R. Martin'; $doc1->series_t = '"A Song of Ice and Fire"'; $doc1->sequence_i = 4; $doc1->genre_s = 'fantasy';
Similarly, another document
$doc2...