[Zope-Checkins] CVS: Zope/lib/python/Products/ZCTextIndex - Lexicon.py:1.18.26.1

Casey Duncan casey@zope.com
Thu, 29 May 2003 23:53:42 -0400


Update of /cvs-repository/Zope/lib/python/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv13282

Modified Files:
      Tag: casey-zctextindex-fewer-conflicts-branch
	Lexicon.py 
Log Message:
Some experimental changes to reduce write conflicts with ZCTextIndex


=== Zope/lib/python/Products/ZCTextIndex/Lexicon.py 1.18 => 1.18.26.1 ===
--- Zope/lib/python/Products/ZCTextIndex/Lexicon.py:1.18	Mon Dec  2 00:27:51 2002
+++ Zope/lib/python/Products/ZCTextIndex/Lexicon.py	Thu May 29 23:53:11 2003
@@ -16,6 +16,7 @@
 
 from BTrees.IOBTree import IOBTree
 from BTrees.OIBTree import OIBTree
+from BTrees.Length import Length
 
 import ZODB
 from Persistence import Persistent
@@ -37,6 +38,7 @@
         # we never saw before, and that isn't a known stopword (or otherwise
         # filtered out).  Returning a special wid value for OOV words is a
         # way to let clients know when an OOV word appears.
+        self.length = Length()
         self._nextwid = 1
         self._pipeline = pipeline
 
@@ -46,7 +48,8 @@
 
     def length(self):
         """Return the number of unique terms in the lexicon."""
-        return self._nextwid - 1
+        # Overridden in instances
+        return len(self._wids)
 
     def words(self):
         return self._wids.keys()
@@ -59,11 +62,11 @@
 
     def sourceToWordIds(self, text):
         last = _text2list(text)
-        for t in last:
-            self._nbytes += len(t)
+        #for t in last:
+        #    self._nbytes += len(t)
         for element in self._pipeline:
             last = element.process(last)
-        self._nwords += len(last)
+        #self._nwords += len(last)
         return map(self._getWordIdCreate, last)
 
     def termToWordIds(self, text):
@@ -132,7 +135,8 @@
     def _getWordIdCreate(self, word):
         wid = self._wids.get(word)
         if wid is None:
-            wid = self._new_wid()
+            self.length.change(1)
+            wid = self.length()
             self._wids[word] = wid
             self._words[wid] = word
         return wid