Updating documents in Solr using PHP
Let us see how we can use PHP code along with Solarium library to update documents in Solr.
First check if there are any documents with the word
smith
in our index.http://localhost:8080/solr/collection1/select/?q=smith
We can see
numFound=0
, which means that there are no such documents. Let us add a book to our index with the last name of the author assmith
.$updateQuery = $client->createUpdate(); $testdoc = $updateQuery->createDocument(); $testdoc->id = 123456789; $testdoc->cat = 'book'; $testdoc->name = 'Test book'; $testdoc->price = 5.99; $testdoc->author = 'Hello Smith'; $updateQuery->addDocument($testdoc); $updateQuery->addCommit(); $client->update($updateQuery);
If we run the same select query again, we can see that now there is one document in our index with the author as
Smith
. Let us now update the author's name toJack Smith
and the price tag to7.59
:$testdoc = $updateQuery->createDocument(); $testdoc->id = 123456789...