1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| public function save(Doctrine_Connection $conn = null)
{
$conn = $conn ? $conn : AnapathTable::getConnection();
$conn->beginTransaction();
try
{
$ret = parent::save($conn);
$this->updateLuceneIndex();
$conn->commit();
return $ret;
}
catch (Exception $e)
{
$conn->rollBack();
throw $e;
}
}
public function updateLuceneIndex()
{
$index = AnapathTable::getLuceneIndex();
// remove existing entries
foreach ($index->find('pk:'.$this->getId()) as $hit)
{
$index->delete($hit->id);
}
$doc = new Zend_Search_Lucene_Document();
// store anapath primary key to identify it in the search results
$doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
// index anapath fields
$doc->addField(Zend_Search_Lucene_Field::UnStored('poids', $this->getPoids, 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('gleason', $this->getGleason(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('gleason_max', $this->getGleasonMax(), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('gleason_tertiaire', $this->getGleasonTertiaire(), 'utf-8'));
// add anapath to the index
$index->addDocument($doc);
$index->commit();
}
public function delete(Doctrine_Connection $conn = null)
{
$index = AnapathTable::getLuceneIndex();
foreach ($index->find('pk:'.$this->getId()) as $hit)
{
$index->delete($hit->id);
}
return parent::delete($conn);
} |
Partager