1

I am not new with zend lucene but I have a trouble with searching using it. I search in documents by numbers using below code:

$term = new Zend_Search_Lucene_Index_Term($id, $idFieldName);
$docIds  = $index->termDocs($term);
foreach ($docIds as $id) {
    $doc = $index->getDocument($id);
    echo $doc->artist_name;
}
$index->commit();

and deleting a document by number using below code:

$term = new Zend_Search_Lucene_Index_Term($id, $idFieldName);
$docIds  = $index->termDocs($term);
foreach ($docIds as $id) {

    $doc = $index->getDocument($id);
    $index->delete($doc->lyric_id);

}
$index->commit(); 

When I delete a document, $index->numDocs() display that the document is deleted because the returned value is not equals the returned value of $index->count(). but the problem is, after deleting the document, I can search in it yet and I can display the value of its fields.

I checked that after optimizing the indexes but the problem is live yet. I need to remove completely a document or search in the documents that are not deleted from indexes.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

Loop through the search results and check if the document is deleted. If it is, remove it from the search results.

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";
} }

via Building Indexes: Updating Documents

JSuar
  • 21,056
  • 4
  • 39
  • 83