changeset 2388:ca82098b3e5f

Add a file forgotten from the previous commits...
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sat, 14 Jul 2007 19:12:55 +0200
parents aad0a118e609
children abe038cca0c5 4ac1c1635aba
files MoinMoin/events/xapian_index.py
diffstat 1 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/events/xapian_index.py	Sat Jul 14 19:12:55 2007 +0200
@@ -0,0 +1,61 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - (re)building of Xapian indices
+"""
+import MoinMoin.events as ev
+
+
+def handle_renamed(event):
+    """Updates Xapian index when a page changes its name"""
+
+    request = event.request
+
+    if request.cfg.xapian_search:
+        from MoinMoin.search.Xapian import Index
+        index = Index(request)
+        if index.exists():
+            index.remove_item(event.old_page.page_name, now=0)
+            index.update_page(event.page.page_name)
+
+
+def handle_copied(event):
+    """Updates Xapian index when a page is copied"""
+
+    request = event.request
+
+    if request.cfg.xapian_search:
+        from MoinMoin.search.Xapian import Index
+        index = Index(request)
+        if index.exists():
+            index.update_page(event.page.page_name)
+
+def handle_changed(event, deleted=False):
+    """Updates Xapian index when a page is changed"""
+
+    request = event.request
+
+    if request.cfg.xapian_search:
+        from MoinMoin.search.Xapian import Index
+        index = Index(request)
+        if index.exists():
+            if deleted:
+                index.remove_item(event.page.page_name)
+            else:
+                index.update_page(event.page.page_name)
+
+
+def handle_deleted(event):
+    """Updates Xapian index when a page is deleted"""
+    event = ev.PageChangedEvent(event.request, event.page, event.comment, False)
+    handle_changed(event, deleted=True)
+    print "deleted"
+
+def handle(event):
+    if isinstance(event, ev.PageRenamedEvent):
+        handle_renamed(event)
+    elif isinstance(event, ev.PageCopiedEvent):
+        handle_copied(event)
+    elif isinstance(event, ev.PageChangedEvent):
+        handle_changed(event)
+    elif isinstance(event, ev.PageDeletedEvent):
+        handle_deleted(event)