View Single Post
  #1 (permalink)  
Old 02-27-2007, 10:27 AM
bongobongo bongobongo is offline
Junior Member
 
Join Date: Feb 2007
Posts: 1
Default Problem with "updating" (delete and add) a document.

Hi.

Have been testing lucene for a couple of days now and have trouble when I want to "update" (delete and add) a document in the index.

I have inserted earlier this doc to the index using:
....
....
$index = new Zend_Search_Lucene($indexPath);
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Keyword('id' , 'aaaaaa'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('cont ', 'lucene looks promising'));
$index->addDocument($doc);
$index->commit();

The above gets inserted and is searchable using the words in UnStored field.

I'm able to search a previously added document in the index and delete it like this:
$index = new Zend_Search_Lucene($indexPath);
$removeID = "aaaaaa";
$hits = $index->find('id:' . $removeID);
foreach ($hits as $hit) {
$index->delete($hit->id);
echo "<br>TEST: doc deleted";
}
$index->commit();

The above code works.
The doc is no longer searchable.... and the echo "...TEST.." is output.

Now I insert the same document again with another cont value like this.....
....
....
$index = new Zend_Search_Lucene($indexPath);
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Keyword('id' , 'aaaaaa'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('cont ', 'lucene looks promising nature hiking'));
$index->addDocument($doc);
$index->commit();
....

The weird thing now is that the doc is searchable again using the words from the docs first inserted record (lucene looks promising),
but not when I search using the newly "added" words (nature or hiking).

Any clue on what is going on here?
Using windows and ZendFramework 0.8.0

**** ALSO FOUND THIS ****

create new index only. DONE... see dir has been created etc...

Next call to script:
Insert a document. DONE.

Next call to script:
Search the document: 1 hit... ok.

Next call to script:
Insert another document: DONE.

Next call to script:
Search index for last inserted document. NO HIT. WHY ( the last insert was committed using $index->commit();

Next call to script:
$index->optimize();
Then same search as last time.... Now I get 1 HIT.

I thought adding documents only added new segments to the index..... AND that those segments should also
be searchable.... is it not supposed to be so?

Do I really have to call: $index->optimize(); after each addition of a new document to make the document
visible to new searches?

Changed my delete - add code to use the $index->optimize(); after commit... and now that works...
BUT.. having to use the optimizer to make the newly added documents seems very odd to me....
if there is many documents indexed then that will probably cause a lot of overhead...

Is this a bug ... or ....?

Getting a headace here....

Would appreciate if someone could help me explain what is going on?


**********************

Last edited by bongobongo : 02-27-2007 at 05:17 PM.
Reply With Quote