[Zope-Checkins] CVS: Zope2 - Catalog.py:1.70.6.4 ZCatalog.py:1.88.6.8 ZCatalogIndexes.py:1.1.2.10

Matthew T. Kromer matt@digicool.com
Mon, 21 May 2001 14:22:19 -0400 (EDT)


Update of /cvs-repository/Zope2/lib/python/Products/ZCatalog
In directory korak.digicool.com:/tmp/cvs-serv3069/lib/python/Products/ZCatalog

Modified Files:
      Tag: ajung-dropin-registry
	Catalog.py ZCatalog.py ZCatalogIndexes.py 
Log Message:
Separating out ZCatalogIndexes to being a dumb object -- still not complete
but this is a working checkpoint



--- Updated File Catalog.py in package Zope2 --
--- Catalog.py	2001/05/10 17:59:26	1.70.6.3
+++ Catalog.py	2001/05/21 18:22:18	1.70.6.4
@@ -334,6 +334,10 @@
         Types: 'FieldIndex', 'TextIndex', 'KeywordIndex'.
         """
 
+        raise NotImplementedError, """Catalog.addIndex is no longer implemented.
+        Please use Catalog.replaceIndexes and then directly manage the replaced
+        indexes."""
+
         if self.indexes.has_key(name):
             raise 'Index Exists', 'The index specified already exists'
 

--- Updated File ZCatalog.py in package Zope2 --
--- ZCatalog.py	2001/05/14 18:57:39	1.88.6.7
+++ ZCatalog.py	2001/05/21 18:22:18	1.88.6.8
@@ -88,6 +88,7 @@
 import Globals
 from OFS.Folder import Folder
 from OFS.FindSupport import FindSupport
+from OFS.ObjectManager import ObjectManager
 from DateTime import DateTime
 import string, urlparse, urllib, os, sys, time
 import Products
@@ -101,6 +102,7 @@
 from AccessControl import getSecurityManager, full_read_guard
 from zLOG import LOG, ERROR
 from ZCatalogIndexes import ZCatalogIndexes
+from Products.PluginIndexes.common.PluggableIndex import PluggableIndexInterface
 
 StringType=type('')
 
@@ -154,6 +156,9 @@
          'action': 'manage_catalogView',
          'target': 'manage_main',
          'help':('ZCatalog','ZCatalog_Cataloged-Objects.stx')},
+        {'label': 'Indexes',            # TAB: Indexes
+         'action': 'Indexes/manage_workspace',
+        },
         {'label': 'Properties',         # TAB: Properties
          'action': 'manage_propertiesForm',
          'help': ('OFSP','Properties.stx')},
@@ -213,6 +218,8 @@
     manage_objectInformation = DTMLFile('dtml/catalogObjectInformation',
                                         globals())
 
+    #Indexes = ZCatalogIndexes()
+
     threshold=10000
     _v_total=0
     _v_transaction = None
@@ -237,28 +244,35 @@
             self.vocab_id = vocab_id
 
         self._catalog = Catalog(vocabulary=self.vocab_id)
+
+        self._indexes = {}
+
+        #indexes = ZCatalogIndexes('Indexes',vocabulary=self.vocab_id,caller=self)
+        indexes = self._indexes
+
+        self.Indexes = ZCatalogIndexes('Indexes',vocabulary=self.vocab_id,
+            caller=self, indexes=indexes)
 
-        indexes = ZCatalogIndexes('Indexes',vocabulary=self.vocab_id,caller=self)
-        self._setObject('Indexes', indexes)
+        #self._setObject('Indexes', indexes)
 
         self._catalog.replaceIndexes(indexes)
 
         self._catalog.addColumn('id')
-        self._catalog.addIndex('id', 'FieldIndex')
+        self.addIndex('id', 'FieldIndex')
 
         self._catalog.addColumn('title')
-        self._catalog.addIndex('title', 'TextIndex')
+        self.addIndex('title', 'TextIndex')
 
         self._catalog.addColumn('meta_type')
-        self._catalog.addIndex('meta_type', 'FieldIndex')
+        self.addIndex('meta_type', 'FieldIndex')
 
         self._catalog.addColumn('bobobase_modification_time')
-        self._catalog.addIndex('bobobase_modification_time', 'FieldIndex')
+        self.addIndex('bobobase_modification_time', 'FieldIndex')
 
         self._catalog.addColumn('summary')
-        self._catalog.addIndex('PrincipiaSearchSource', 'TextIndex')
+        self.addIndex('PrincipiaSearchSource', 'TextIndex')
 
-        self._catalog.addIndex('path','PathIndex')
+        self.addIndex('path','PathIndex')
 
     def __len__(self): return len(self._catalog)
 
@@ -747,6 +761,56 @@
         tt=time.time()-tt
         ct=time.clock()-ct
         return 'Finished conversion in %s seconds (%s cpu)' % (tt, ct)
+
+    #
+    # Indexing methods 
+    #
+
+    def addIndex(self, name, type):
+        print "Add index %s, type %s" % (name, type)
+
+        # Convert the type by finding an appropriate product which supports
+        # this interface by that name.  Bleah
+
+        products = ObjectManager.all_meta_types(self, interfaces=(
+            PluggableIndexInterface,))
+
+        print "Products: %s" % products
+
+        p = None
+
+        for prod in products:
+            if prod['name'] == type: 
+                p = prod
+                break
+
+        if p is None:
+            raise ValueError, "Index of type %s not found" % type
+
+        base = p['instance']
+
+        if base is None:
+            raise ValueError, "Index type %s does not support addIndex" % type
+
+        index = base(name, self)
+
+        self._indexes[name] = index
+
+
+    def delIndex(self, name ):
+        print "del index %s" % (name)
+
+        # Lame.....this needs to be fixed
+        del self._indexes[name]
+
+
+    def clearIndex(self, name ):
+        print "clear index %s" % (name)
+
+        # Lame.....this needs to be fixed
+        self._indexes[name].clear()
+
+
     
 Globals.default__class_init__(ZCatalog)
 
@@ -806,6 +870,3 @@
         if not (role in pr):
             return 0
     return 1
-
-
-

--- Updated File ZCatalogIndexes.py in package Zope2 --
--- ZCatalogIndexes.py	2001/05/15 13:37:23	1.1.2.9
+++ ZCatalogIndexes.py	2001/05/21 18:22:18	1.1.2.10
@@ -89,7 +89,7 @@
 from OFS.FindSupport import FindSupport
 from OFS.History import Historical
 from OFS.SimpleItem import SimpleItem
-from OFS.ObjectManager import ObjectManager
+from OFS.ObjectManager import ObjectManager, IFAwareObjectManager
 
 import string, os, sys, time
 
@@ -101,7 +101,7 @@
 
 _marker = []
 
-class ZCatalogIndexes (Folder, Persistent, Implicit):
+class ZCatalogIndexes (IFAwareObjectManager, Folder, Persistent, Implicit):
     """A mapping object, responding to getattr requests by looking up
     the requested indexes in an object manager."""
 
@@ -139,9 +139,14 @@
         )
     )
 
-    def __init__(self, name="Indexes", vocabulary=None,caller=None):
+    def __init__(self, name="Indexes", vocabulary=None,caller=None,
+        indexes=None):
+
         self.id = name
-        self._indexes = {}
+        if indexes is None:
+            self._indexes = {}
+        else:
+            self._indexes = indexes
         self._vocab_id = vocabulary
         self.caller    = caller