17 Mar
Posted by Ganesh H S , Bangalore, India as zend framework
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
6 Responses
Stelio
April 16th, 2008 at 3:53 am
1Nice tutorial…
How to update document in Index ->example
Ganesh H S , Bangalore, India
April 19th, 2008 at 2:23 am
2Stelio -
As written in this tutorial, you have to open the document which you want to update and index the data which you want modify. Zend Search Lucene will take care of it.
Rauan
May 30th, 2008 at 1:58 pm
3Hi, Ganesh. I’m indexing my data almost the same way. But now i have exceptions(there are don’t throw if i creating new index, and vice-verse for non-empty index). Posted it here http://framework.zend.com/issues/browse/ZF-3356.
Have U ever stumbled upon such troubles?
Ganesh H S , Bangalore, India
May 31st, 2008 at 2:41 am
4Hey rauan-
The link http://framework.zend.com/issues/browse/ZF-3356 you posted is broken, can you elaborate on the real problem? I didn’t understand your message.
Rauan
May 31st, 2008 at 3:13 am
5Ok. The problem is that when I’m committing the document to index script fails with exception
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1335492579 bytes) in Zend/Search/Lucene/Storage/File/Filesystem.php
But it’s really-really strange why it’s trying to allocate over ~1.24 Gb while my index is only 270Kb. The script is written on the same principles as your example.
Ganesh H S , Bangalore, India
June 2nd, 2008 at 1:12 am
6Rauan-
Try these -
#1. Delete the existing indexed files -
Go to the path which you mentioned when creating index, that will be the folder, go inside the folder, delete the files which exists and run the script to index again.
#2. Use these commands at the end of the script -
$index->commit();
$index->optimize();
$index is a zend search lucene document object($index = new Zend_Search_Lucene_Document();)
#3. Whats the size of the data you are indexing, and since the indexed data is stored as files, make sure you have that much space in the file system.
If you still have a problem feel free to contact me or u can ping me to my chat ids -
ganesh.ganny at gmail.com
ganesh_ganny at yahoo.co.in
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Blogroll
Recent Comments
Recent Posts
Ganesh H S is proudly powered by WordPress - BloggingPro theme by: Design Disease