[Zope3-checkins] CVS: Zope3/src/zope/app/index/field - index.py:1.11

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


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

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/field/index.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/index/field/index.py:1.10	Sun Jul 13 23:53:20 2003
+++ Zope3/src/zope/app/index/field/index.py	Tue Aug  5 04:33:25 2003
@@ -36,47 +36,10 @@
 
 from zope.app.interfaces.index.field import IUIFieldIndex, IUIFieldCatalogIndex
 from zope.app.interfaces.catalog.index import ICatalogIndex
+from zope.app.index import InterfaceIndexingSubscriber
 
-class FieldCatalogIndex(FieldIndexWrapper):
-
-    implements(ISubscriber, ICatalogIndex, IUIFieldCatalogIndex)
-
-    def __init__(self, field_name, interface=None):
-        FieldIndexWrapper.__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 FieldCatalogIndex(InterfaceIndexingSubscriber, FieldIndexWrapper):
+    implements(ICatalogIndex, IUIFieldCatalogIndex)
 
 class FieldIndex(FieldCatalogIndex):
 




More information about the Zope3-Checkins mailing list