Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Lucene Delete Document Issue

Tags:

zend-lucene

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.

like image 520
Pramod Sivadas Avatar asked Dec 21 '12 15:12

Pramod Sivadas


2 Answers

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

like image 182
Pramod Sivadas Avatar answered Oct 29 '22 05:10

Pramod Sivadas


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.

like image 29
JSuar Avatar answered Oct 29 '22 06:10

JSuar