[Zope-Checkins] CVS: Zope2 - UnTextIndex.py:1.33.2.7

Jim Fulton jim@digicool.com
Sat, 17 Mar 2001 12:30:41 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory korak:/tmp/cvs-serv22774

Modified Files:
      Tag: zope-2_3-branch
	UnTextIndex.py 
Log Message:
UnTextIndexes now refer directly to their lexicons.

Added logic in conversion code to implement the rule above
and to unscrew some hysterical breakage.



--- Updated File UnTextIndex.py in package Zope2 --
--- UnTextIndex.py	2001/03/17 15:38:08	1.33.2.6
+++ UnTextIndex.py	2001/03/17 17:30:41	1.33.2.7
@@ -140,8 +140,7 @@
     meta_type = 'Text Index'
 
 
-    def __init__(self, id, ignore_ex=None,
-                 call_methods=None, lexicon=None):
+    def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None):
         """Create an index
 
         The arguments are:
@@ -168,7 +167,9 @@
             ## if no lexicon is provided, create a default one
             self._lexicon = Lexicon()
         else:
-            self._lexicon = lexicon
+            # We need to hold a reference to the lexicon, since we can't
+            # really change lexicons.
+            self._lexicon = self.getLexicon(lexicon)
 
 
     def getLexicon(self, vocab_id):
@@ -181,10 +182,6 @@
 
         if type(vocab_id) is not StringType:
             vocab = vocab_id # we already havd the lexicon
-
-            # Through some sick hysterical accident, some lexicons
-            # simply wrap other lexicons, unless they don't. Waaaaaa.
-            vocab = getattr(vocab, 'lexicon', vocab)
             return vocab
         else:
             vocab = getattr(self, vocab_id)
@@ -205,6 +202,16 @@
         self._unindex = IOBTree()
 
     def _convertBTrees(self, threshold=200):
+
+        if hasattr(getattr(self, 'aq_base', self), 'lexicon'):
+            # some old text indexes are in a weird state in which their
+            # *real* lexicon is in an attribute 'lexicon'.
+            self._lexicon=getattr(self.lexicon, 'aq_base', self.lexicon)
+            del self.lexicon
+        elif type(self._lexicon) is type(''):
+            # Turn the name reference into a hard reference. 
+            self._lexicon=self.getLexicon(self._lexicon)
+
         if type(self._index) is IOBTree: return
 
         from BTrees.convert import convert