[Zope-Checkins] CVS: Zope2 - Catalog.py:1.65

Jim Fulton jim@digicool.com
Sat, 17 Mar 2001 14:03:18 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/Products/ZCatalog
In directory korak:/tmp/cvs-serv28464

Modified Files:
	Catalog.py 
Log Message:
An argument named 'type' shadowed the builtin. Waaaa.

New catalogs have 'lexicon' attributes that are lexicon names, but
old catalogs store their lexicons directly. This makes it hard
to manage text indexes correctly. Added some code to assure that
when a text index is added, we always pass the actual lexicon.

When converting BTrees, convert indexes in context. This is necessary
to help UnTextIndexes get their (previously) acquired lexicons.

UnTextIndexes now refer directly to their lexicons.



--- Updated File Catalog.py in package Zope2 --
--- Catalog.py	2001/03/16 18:25:16	1.64
+++ Catalog.py	2001/03/17 19:03:18	1.65
@@ -200,6 +200,7 @@
 
 
         for index in self.indexes.values():
+            if hasattr(index, '__of__'): index=index.__of__(self)
             index._convertBTrees(threshold)
 
         lexicon=self.lexicon
@@ -333,8 +334,8 @@
             rec.remove(rec[_index])
             self.data[key] = tuple(rec)
 
-    def addIndex(self, name, type):
-        """Create a new index, of one of the following types
+    def addIndex(self, name, index_type):
+        """Create a new index, of one of the following index_types
 
         Types: 'FieldIndex', 'TextIndex', 'KeywordIndex'.
         """
@@ -349,17 +350,19 @@
         # pluggable and managable
 
         indexes = self.indexes
-        if type == 'FieldIndex':
+        if index_type == 'FieldIndex':
             indexes[name] = UnIndex.UnIndex(name)
-        elif type == 'TextIndex':
-            indexes[name] = UnTextIndex.UnTextIndex(name, None, None,
-                                                    self.lexicon)
-        elif type == 'KeywordIndex':
+        elif index_type == 'TextIndex':
+            lexicon=self.lexicon
+            if type(lexicon) is type(''): lexicon=getattr(self, lexicon)
+            indexes[name] = UnTextIndex.UnTextIndex(name, None, None, lexicon)
+        elif index_type == 'KeywordIndex':
             indexes[name] = UnKeywordIndex.UnKeywordIndex(name)
         else:
-            raise 'Unknown Index Type', ("%s invalid - must be one of %s"
-                                         % (type, ['FieldIndex', 'TextIndex',
-                                                   'KeywordIndex']))
+            raise 'Unknown Index Type', (
+                "%s invalid - must be one of %s"
+                % (index_type, ['FieldIndex', 'TextIndex', 'KeywordIndex'])
+                )
 
         self.indexes = indexes