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.

 <?phprequire_once 'Zend/Search/Lucene.php';$index = Zend_Search_Lucene::open("/var/www/lucene-data/blog-index");

$doc = new Zend_Search_Lucene_Document();

$doc->addField(Zend_Search_Lucene_Field::Keyword('url',

"http://ganeshhs.com/url-3"));

$doc->addField(Zend_Search_Lucene_Field::UnIndexed('articleId',

3));

$doc->addField(Zend_Search_Lucene_Field::UnIndexed('postedDateTime',

"20007-12-29 01:40:00"));

$doc->addField(Zend_Search_Lucene_Field::Text('title',

"Porting PHP to Javascript : php js"));

$doc->addField(Zend_Search_Lucene_Field::UnStored('contents',

"During graduation got interested in web technology, to kick start i started reading html, javascript."));

$doc->addField(Zend_Search_Lucene_Field::Text('category',

"Javascript"));

$index->addDocument($doc);

$index->commit();

$index->optimize();

Related articles:
Zend Lucene Search - part1 - creating index
Zend Lucene Search - part3 - retrieving the indexed data
Zend Lucene Search - part4 - Search Results Highlighting
Home Page

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Simpy
  • StumbleUpon
  • Technorati
  • YahooMyWeb