[Zope3-checkins] CVS: Zope3/src/zope/app/index/text - index.py:1.15

Anthony Baxter anthony at interlink.com.au
Tue Aug 5 05:34:07 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/index/text
In directory cvs.zope.org:/tmp/cvs-serv24050/app/index/text

Modified Files:
	index.py 
Log Message:
Refactoring of the Catalog<->Index interface to extract common code. 

TextIndexes now index a particular interface+field combination, which 
defaults to ISearchableText/getSearchText. Making a new index hook into
the catalog is now a matter of two or three lines of python and some 
zcml.


=== Zope3/src/zope/app/index/text/index.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/index/text/index.py:1.14	Sun Jul 13 23:53:24 2003
+++ Zope3/src/zope/app/index/text/index.py	Tue Aug  5 04:33:31 2003
@@ -21,10 +21,9 @@
 $Id$
 """
 
-from zope.component import getService, queryAdapter
+from zope.component import getService
 from zope.app.services.servicenames import HubIds
 from zope.context import ContextMethod
-from zope.app.interfaces.event import ISubscriber
 from zope.index.text.textindexwrapper import TextIndexWrapper
 
 from zope.app.interfaces.services.hub import \
@@ -35,31 +34,14 @@
 from zope.app.interfaces.index.text import ISearchableText
 from zope.app.interfaces.index.text import IUITextIndex, IUITextCatalogIndex
 from zope.interface import implements
+from zope.app.index import InterfaceIndexingSubscriber
+from zope.app.interfaces.catalog.index import ICatalogIndex
 
-class TextCatalogIndex(TextIndexWrapper):
+class TextCatalogIndex(InterfaceIndexingSubscriber, TextIndexWrapper):
+    implements(ICatalogIndex, IUITextCatalogIndex)
 
-    implements(ISubscriber, IUITextCatalogIndex)
-
-    def notify(wrapped_self, event):
-        """An event occurred.  Index or unindex the object in response."""
-        if (IObjectRegisteredHubEvent.isImplementedBy(event) or
-            IObjectModifiedHubEvent.isImplementedBy(event)):
-            texts = wrapped_self._getTexts(event.object)
-            if texts is not None:
-                wrapped_self.index_doc(event.hubid, texts)
-        elif IObjectUnregisteredHubEvent.isImplementedBy(event):
-            try:
-                wrapped_self.unindex_doc(event.hubid)
-            except KeyError:
-                pass
-    notify = ContextMethod(notify)
-
-    def _getTexts(wrapped_self, object):
-        adapted = queryAdapter(object, ISearchableText, context=wrapped_self)
-        if adapted is None:
-            return None
-        return adapted.getSearchableText()
-    _getTexts = ContextMethod(_getTexts)
+    default_interface = ISearchableText
+    default_field_name = "getSearchableText"
 
 class TextIndex(TextCatalogIndex):
 
@@ -98,7 +80,7 @@
 
     def _update(wrapped_self, registrations):
         for location, hubid, wrapped_object in registrations:
-            texts = wrapped_self._getTexts(wrapped_object)
+            texts = wrapped_self._getValue(wrapped_object)
             if texts is not None:
                 wrapped_self.index_doc(hubid, texts)
     _update = ContextMethod(_update)




More information about the Zope3-Checkins mailing list