I am trying to delete a document using zend lucene. The following is my code
$index = Zend_Search_Lucene::open('data/index');
foreach ($index->find('pk:' . $this->getId()) as $hit) {
$index->delete($hit->id);
}
$index->commit();
When I run this and checked my index folder there is a new file created like this _f4t5_1.del
But when I do a search, the deleted document is available in the search and also checked the
$index->numDocs();
This method also returns the same count before and after delete.
Any help is appreciated.
Just found the issue. The issue was due to a logical error in my code. After deleting I was calling another function which again added the document to the index. When I checked the document ID if found it to be different after deleting and that helped me to track the issue. Thanks for the help
This might be helpful: php lucene how to update and delete rows in index file
Have you checked to make sure the documents are actually deleted.
Zend_Search_Lucene::isDeleted($id) method may be used to check if a document is deleted.
for ($count = 0; $count < $index->maxDoc(); $count++) { if ($index->isDeleted($count)) { echo "Document #$id is deleted.\n"; } }
Have you tried running index optimization:
Index optimization removes deleted documents and squeezes documents' IDs in to a smaller range. A document's internal id may therefore change during index optimization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With