[Zope3-checkins] CVS: Zope3/src/zope/app/index/keyword - index.py:1.2

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


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

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/keyword/index.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/index/keyword/index.py:1.1	Sun Aug  3 01:41:10 2003
+++ Zope3/src/zope/app/index/keyword/index.py	Tue Aug  5 04:33:28 2003
@@ -13,69 +13,17 @@
 ##############################################################################
 """This is a keyword index which can be subscribed to an event service.
 
-Events related to object creation and deletion are translated into
-index_doc() and unindex_doc() calls.
-
-This (along with field and text indexes) should be refactored to abstract
-out the common code.
-
 $Id$
 """
 
-from zope.component import getService, queryAdapter
-from zope.app.services.servicenames import HubIds
 from zope.context import ContextMethod
-from zope.app.interfaces.event import ISubscriber
 from zope.index.keyword.index import KeywordIndex 
 from zope.interface import implements
 
-from zope.app.interfaces.services.hub import \
-     IRegistrationHubEvent, \
-     IObjectRegisteredHubEvent, \
-     IObjectUnregisteredHubEvent, \
-     IObjectModifiedHubEvent
-
 from zope.app.interfaces.index.keyword import IUIKeywordCatalogIndex
 from zope.app.interfaces.catalog.index import ICatalogIndex
+from zope.app.index import InterfaceIndexingSubscriber
 
-class KeywordCatalogIndex(KeywordIndex):
-
-    implements(ISubscriber, ICatalogIndex, IUIKeywordCatalogIndex)
-
-    def __init__(self, field_name, interface=None):
-        KeywordIndex.__init__(self)
-        self._field_name = field_name
-        self._interface = interface
-
-    field_name = property(lambda self: self._field_name)
-    interface = property(lambda self: self._interface)
-
-    def _getValue(self, object):
-        if self._interface is not None:
-            object = queryAdapter(object, self._interface)
-            if object is None: return None
-
-        value = getattr(object, self._field_name, None)
-        if value is None: return None
-
-        if callable(value):
-            try: value = value()
-            except: return None
-
-        return value
-
-    def notify(self, event):
-        """An event occurred.  Index or unindex the object in response."""
-
-        if (IObjectRegisteredHubEvent.isImplementedBy(event) or
-            IObjectModifiedHubEvent.isImplementedBy(event)):
-            value = self._getValue(event.object)
-            if value is not None:
-                self.index_doc(event.hubid, value)
-        elif IObjectUnregisteredHubEvent.isImplementedBy(event):
-            try:
-                self.unindex_doc(event.hubid)
-            except KeyError:
-                pass
-    notify = ContextMethod(notify)
+class KeywordCatalogIndex(InterfaceIndexingSubscriber, KeywordIndex):
+    implements(ICatalogIndex, IUIKeywordCatalogIndex)
 




More information about the Zope3-Checkins mailing list