5

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.

Pramod Sivadas
  • 873
  • 2
  • 9
  • 28

2 Answers2

3

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

Pramod Sivadas
  • 873
  • 2
  • 9
  • 28
2

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.

Community
  • 1
  • 1
JSuar
  • 21,056
  • 4
  • 39
  • 83
  • I tried optimizing the index. When optimized it removed the files like with extension .del but when searched the index, the deleted documents are also returned in the search results. – Pramod Sivadas Jan 01 '13 at 05:43
  • Why not loop through and use `$index->isDeleted($id)` to remove the deleted documents from the search results. – JSuar Jan 01 '13 at 07:38