Zend Lucene Search – part2 – Real time indexing

From ganeshhs.com

For creating the index from the existing data, we need to create the index. Isn’t it a better idea to index each data when its created, to index the real time data we need to open the index which was created earlier, rest of the other things remains same as discussed in the Zend lucene Search – part1.

  1. <?phprequire_once ‘Zend/Search/Lucene.php’;$index = Zend_Search_Lucene::open(“/var/www/lucene-data/blog-index”);
  2. $doc = new Zend_Search_Lucene_Document();
  3. $doc->addField(Zend_Search_Lucene_Field::Keyword(‘url’,
  4. http://ganeshhs.com/url-3&#8221;));
  5. $doc->addField(Zend_Search_Lucene_Field::UnIndexed(‘articleId’,
  6. 3));
  7. $doc->addField(Zend_Search_Lucene_Field::UnIndexed(‘postedDateTime’,
  8. “20007-12-29 01:40:00”));
  9. $doc->addField(Zend_Search_Lucene_Field::Text(‘title’,
  10. “Porting PHP to Javascript : php js”));
  11. $doc->addField(Zend_Search_Lucene_Field::UnStored(‘contents’,
  12. “During graduation got interested in web technology, to kick start i started reading html, javascript.”));
  13. $doc->addField(Zend_Search_Lucene_Field::Text(‘category’,
  14. “Javascript”));
  15. $index->addDocument($doc);
  16. $index->commit();
  17. $index->optimize();

Related articles:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s