Reader small image

You're reading from  Apache Solr PHP Integration

Product typeBook
Published inNov 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781782164920
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Jayant Kumar
Jayant Kumar
author image
Jayant Kumar

Jayant Kumar is an experienced software professional with a bachelor of engineering degree in computer science and more than 14 years of experience in architecting and developing large-scale web applications. Jayant is an expert on search technologies and PHP and has been working with Lucene and Solr for more than 11 years now. He is the key person responsible for introducing Lucene as a search engine on www.naukri.com, the most successful job portal in India. Jayant is also the author of the book Apache Solr PHP Integration, Packt Publishing, which has been very successful. Jayant has played many different important roles throughout his career, including software developer, team leader, project manager, and architect, but his primary focus has been on building scalable solutions on the Web. Currently, he is associated with the digital division of HT Media as the chief architect responsible for the job site www.shine.com. Jayant is an avid blogger and his blog can be visited at http://jayant7k.blogspot.in. His LinkedIn profile is available at http://www.linkedin.com/in/jayantkumar.
Read more about Jayant Kumar

Right arrow

Updating documents in Solr using PHP


Let us see how we can use PHP code along with Solarium library to update documents in Solr.

  1. First check if there are any documents with the word smith in our index.

    http://localhost:8080/solr/collection1/select/?q=smith
  2. 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 as smith.

    $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);
  3. 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 to Jack Smith and the price tag to 7.59:

    $testdoc = $updateQuery->createDocument();
    $testdoc->id = 123456789...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Apache Solr PHP Integration
Published in: Nov 2013Publisher: PacktISBN-13: 9781782164920

Author (1)

author image
Jayant Kumar

Jayant Kumar is an experienced software professional with a bachelor of engineering degree in computer science and more than 14 years of experience in architecting and developing large-scale web applications. Jayant is an expert on search technologies and PHP and has been working with Lucene and Solr for more than 11 years now. He is the key person responsible for introducing Lucene as a search engine on www.naukri.com, the most successful job portal in India. Jayant is also the author of the book Apache Solr PHP Integration, Packt Publishing, which has been very successful. Jayant has played many different important roles throughout his career, including software developer, team leader, project manager, and architect, but his primary focus has been on building scalable solutions on the Web. Currently, he is associated with the digital division of HT Media as the chief architect responsible for the job site www.shine.com. Jayant is an avid blogger and his blog can be visited at http://jayant7k.blogspot.in. His LinkedIn profile is available at http://www.linkedin.com/in/jayantkumar.
Read more about Jayant Kumar