[Zope-Checkins] CVS: Zope2 - UnKeywordIndex.py:1.12.2.5

chrism@serenade.digicool.com chrism@serenade.digicool.com
Wed, 11 Apr 2001 14:48:00 -0400


Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory serenade.digicool.com:/home/chrism/sandboxes/2_3Branch/lib/python/SearchIndex

Modified Files:
      Tag: zope-2_3-branch
	UnKeywordIndex.py 
Log Message:
Merge fix for unnecessary writes to Keyword Indexes during indexing to 2_3 branch.



--- Updated File UnKeywordIndex.py in package Zope2 --
--- UnKeywordIndex.py	2001/03/28 22:19:17	1.12.2.4
+++ UnKeywordIndex.py	2001/04/11 18:47:59	1.12.2.5
@@ -118,28 +118,32 @@
         if type(newKeywords) is StringType:
             newKeywords = (newKeywords, )
 
-        # Now comes the fun part, we need to figure out what's changed
-        # if anything from the previous record.
         oldKeywords = self._unindex.get(documentId, None)
 
         if oldKeywords is None:
+            # we've got a new document, let's not futz around.
             try:
                 for kw in newKeywords:
                     self.insertForwardIndexEntry(kw, documentId)
+                self._unindex[documentId] = list(newKeywords)
             except TypeError:
                 return 0
         else:
+            # we have an existing entry for this document, and we need
+            # to figure out if any of the keywords have actually changed
             if type(oldKeywords) is not OOSet: oldKeywords=OOSet(oldKeywords)
             newKeywords=OOSet(newKeywords)
-            self.unindex_objectKeywords(
-                documentId, difference(oldKeywords, newKeywords))
-            for kw in difference(newKeywords, oldKeywords):
-                self.insertForwardIndexEntry(kw, documentId)
-        
-        self._unindex[documentId] = list(newKeywords)
-
+            fdiff = difference(oldKeywords, newKeywords)
+            rdiff = difference(newKeywords, oldKeywords)
+            if fdiff or rdiff:
+                # if we've got forward or reverse changes
+                self._unindex[documentId] = list(newKeywords)
+                if fdiff:
+                    self.unindex_objectKeywords(documentId, fdiff)
+                if rdiff:
+                    for kw in rdiff:
+                        self.insertForwardIndexEntry(kw, documentId)
         return 1
-    
 
     def unindex_objectKeywords(self, documentId, keywords):
         """ carefully unindex the object with integer id 'documentId'"""