Hi,
I have a problem with Zend_Search_Lucene. I'm trying to write a script
that checks if a document is already in the index and adds the document
only if it's not already in the index. The problem in that code is that
$index->termDocs($term) always returns an empty array (even if the
document is already in the index).
Can anyone help?
Here is my main indexing loop (which never displays "Document xxx
already in index"...):
$index = Zend_Search_Lucene::open($indexPath);
foreach ($medias as $media) {
// Check if the media is already in the index
$term = new Zend_Search_Lucene_Index_Term($media["media_id"],
"media_id");
$docIds = $index->termDocs($term);
if (count($docIds) == 0) { // Media not already in the index
print "Adding document " . $media["media_id"] . "\n";
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::unIndexed('media_id',
$media["media_id"]));
... add other fields ...
$index->addDocument($doc);
$index->commit();
} else {
print "Document " . $media["media_id"] . " already in index\n";
}
// Optimize the index from time to time
if ($cnt % 1000 == 0)
$index->optimize();
$cnt++;
}
$index->commit();
$index->optimize();
Cheers,
Olivier
--
- *Olivier RICORDEAU* -
[email protected]