Back to index

moin  1.9.0~rc2
xapian_index.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - (re)building of Xapian indices
00004 
00005     @copyright: 2007 MoinMoin:KarolNowak
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import MoinMoin.events as ev
00010 
00011 
00012 def _get_index(request):
00013     try:
00014         from MoinMoin.search.Xapian import XapianIndex
00015         return XapianIndex(request)
00016     except ImportError:
00017         pass
00018 
00019 
00020 def handle_renamed(event):
00021     """Updates Xapian index when a page changes its name"""
00022 
00023     request = event.request
00024 
00025     if request.cfg.xapian_search:
00026         index = _get_index(request)
00027         if index and index.exists():
00028             index.update_item(event.old_page.page_name, now=False)
00029             index.update_item(event.page.page_name)
00030 
00031 
00032 def handle_copied(event):
00033     """Updates Xapian index when a page is copied"""
00034 
00035     request = event.request
00036 
00037     if request.cfg.xapian_search:
00038         index = _get_index(request)
00039         if index and index.exists():
00040             index.update_item(event.page.page_name)
00041 
00042 
00043 def handle_changed(event):
00044     """Updates Xapian index when a page is changed"""
00045 
00046     request = event.request
00047 
00048     if request.cfg.xapian_search:
00049         index = _get_index(request)
00050         if index and index.exists():
00051             index.update_item(event.page.page_name)
00052 
00053 
00054 def handle_deleted(event):
00055     """Updates Xapian index when a page is deleted"""
00056     event = ev.PageChangedEvent(event.request, event.page, event.comment)
00057     handle_changed(event)
00058 
00059 
00060 def handle_attachment_change(event):
00061     """Updates Xapian index when attachment is added or removed"""
00062 
00063     request = event.request
00064 
00065     if request.cfg.xapian_search:
00066         index = _get_index(request)
00067         if index and index.exists():
00068             index.update_item(event.pagename, event.filename)
00069 
00070 
00071 def handle(event):
00072     if isinstance(event, ev.PageRenamedEvent):
00073         handle_renamed(event)
00074     elif isinstance(event, ev.PageCopiedEvent):
00075         handle_copied(event)
00076     elif isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
00077         handle_changed(event)
00078     elif isinstance(event, ev.PageDeletedEvent):
00079         handle_deleted(event)
00080     elif isinstance(event, (ev.FileAttachedEvent, ev.FileRemovedEvent)):
00081         handle_attachment_change(event)
00082