From 78bc9a5466a0eaa2b3d1d1b976f76ff9aa668a2d Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Sun, 23 Nov 2008 11:26:17 +0100 Subject: [PATCH] Remove from the index on delete. --- src/IDF/Search.php | 27 +++++++++++++++++++++++++++ src/IDF/WikiPage.php | 1 + 2 files changed, 28 insertions(+) diff --git a/src/IDF/Search.php b/src/IDF/Search.php index d36588e..bc56c70 100644 --- a/src/IDF/Search.php +++ b/src/IDF/Search.php @@ -160,4 +160,31 @@ class IDF_Search extends Pluf_Search } return array('total' => $total, 'new' => $new_words, 'unique'=>$n); } + + /** + * Remove an item from the index. + * + * You must call this function when you delete items wich are + * indexed. Just add the call: + * + * IDF_Search::remove($this); + * + * in the preDelete() method of your object. + * + * @param mixed Item to be removed + * @return bool Success + */ + public static function remove($item) + { + if ($item->id > 0) { + $sql = new Pluf_SQL('model_id=%s AND model_class=%s', + array($item->id, $item->_model)); + $items = Pluf::factory('IDF_Search_Occ')->getList(array('filter'=>$sql->gen())); + foreach ($items as $tl) { + $tl->delete(); + } + } + return true; + } + } \ No newline at end of file diff --git a/src/IDF/WikiPage.php b/src/IDF/WikiPage.php index 16d0cd6..40f8770 100644 --- a/src/IDF/WikiPage.php +++ b/src/IDF/WikiPage.php @@ -141,6 +141,7 @@ class IDF_WikiPage extends Pluf_Model function preDelete() { IDF_Timeline::remove($this); + IDF_Search::remove($this); } function get_current_revision()