[GMG-Devel] [PATCH 33/83] Add listener for model delete event.

Alon Levy alon at pobox.com
Tue Feb 25 14:58:16 EST 2014


From: Praveen Kumar <praveen97uma at gmail.com>

---
 mediagoblin/plugins/search/base.py      | 6 ++++++
 mediagoblin/plugins/search/listeners.py | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/mediagoblin/plugins/search/base.py b/mediagoblin/plugins/search/base.py
index 2b6e2b6..09654f2 100644
--- a/mediagoblin/plugins/search/base.py
+++ b/mediagoblin/plugins/search/base.py
@@ -173,6 +173,12 @@ class SearchIndex(object):
         self.update_document(**document)
         _log.info("Updated document %s"%(document['title']))
 
+    def delete_document_from_model_obj(self, model_obj):
+        id_stored = unicode(model_obj.id)
+        self._open_search_index()
+        self.search_index.delete_by_term('id_stored', id_stored)
+        _log.info("Deleted document %s"%(model_obj.title))
+
     def _process_query(self, query):
         query = unicode(query)
         query = MultifieldParser(self.field_names,
diff --git a/mediagoblin/plugins/search/listeners.py b/mediagoblin/plugins/search/listeners.py
index 8d6c192..8212957 100644
--- a/mediagoblin/plugins/search/listeners.py
+++ b/mediagoblin/plugins/search/listeners.py
@@ -37,7 +37,8 @@ class ORMEventsListener(object):
         index.update_document_from_model_obj(target)
 
     def delete_event_handler(self, mapper, connection, target):
-        pass
+        index = self.index_registry.get_index_for_object(target)
+        index.delete_document_from_model_obj(target)
     
     def activate_listeners(self):
         self.listeners = [
-- 
1.8.5.3



More information about the devel mailing list