[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - GlobbingLexiconNG.py:1.1.2.9

Andreas Jung andreas@digicool.com
Wed, 20 Mar 2002 18:59:09 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv25234

Modified Files:
      Tag: ajung-textindexng-branch
	GlobbingLexiconNG.py 
Log Message:
using indexsuppport.vocabBatchInsert for inserting forward and backward entries


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/GlobbingLexiconNG.py 1.1.2.8 => 1.1.2.9 ===
 from Products.PluginIndexes.TextIndex.randid import randid
 from types import ListType
+from indexsupport import vocabBatchInsert
 
 from BTrees.IIBTree import IISet, union, IITreeSet
 from BTrees.OIBTree import OIBTree
@@ -75,11 +76,6 @@
 
         return digrams
 
-
-    def getWordIdList(self,words):
-        """ return a list a wordIds for a list of words """
-        return [ self.getWordId(word)   for word in words] 
-
     
     def getWordId(self, word):
         """Provided 'word', return the matching integer word id."""
@@ -96,31 +92,32 @@
         return self._inverseLex.get(wid, None)
 
 
-    def assignWordId(self, word):
+    def insertDigrams(self, words):
         """Assigns a new word id to the provided word, and return it."""
 
-        # Double check it's not in the lexicon already, and if it is, just
-        # return it.
-        if self._lexicon.has_key(word):
-            return self._lexicon[word]
+        for word in words:
+            wid = self._lexicon[word]
 
-        inverse=self._inverseLex
-        wid = randid()
-        while not inverse.insert(wid, word):
-            wid = randid()
+            for digram in self.createDigrams(word):
+                set = self._digrams.get(digram, None)
 
-        self._lexicon[word] = wid
+                if set is None:
+                    self._digrams[digram] = set = IISet()
+                set.insert(wid)
 
-        # Now take all the digrams and insert them into the digram map.
 
-        for digram in self.createDigrams(word):
-            set = self._digrams.get(digram, None)
+    def getWordIdList(self,words):
+        """ return a list a wordIds for a list of words """
+
+        wids = vocabBatchInsert(
+                    self._lexicon,
+                    self._inverseLex,
+                    words
+                )
 
-            if set is None:
-                self._digrams[digram] = set = IISet()
-            set.insert(wid)
+        self.insertDigrams(words)
 
-        return wid
+        return wids
 
     
     def get(self, pattern):
@@ -134,7 +131,6 @@
         # single characters
 
         r = IISet()
-
         if len(pattern)==1: return r 
 
         # no globbing
@@ -146,7 +142,6 @@
             else:
                 r.insert(result)               
                 return r
-
 
         # we are in globbing country