[Checkins] SVN: zope.index/trunk/ Insure proper unindex behavior if index_doc is called with a empty sequence.

Tres Seaver cvs-admin at zope.org
Mon Mar 12 23:30:22 UTC 2012


Log message for revision 124584:
  Insure proper unindex behavior if index_doc is called with a empty sequence.
  

Changed:
  U   zope.index/trunk/CHANGES.txt
  U   zope.index/trunk/src/zope/index/keyword/index.py
  U   zope.index/trunk/src/zope/index/keyword/tests.py

-=-
Modified: zope.index/trunk/CHANGES.txt
===================================================================
--- zope.index/trunk/CHANGES.txt	2012-03-12 18:21:13 UTC (rev 124583)
+++ zope.index/trunk/CHANGES.txt	2012-03-12 23:30:18 UTC (rev 124584)
@@ -4,6 +4,8 @@
 3.6.4 (unreleased)
 ------------------
 
+- Insure proper unindex behavior if index_doc is called with a empty sequence.
+
 - Use the standard Python doctest module instead of zope.testing.doctest
 
 3.6.3 (2011-12-03)

Modified: zope.index/trunk/src/zope/index/keyword/index.py
===================================================================
--- zope.index/trunk/src/zope/index/keyword/index.py	2012-03-12 18:21:13 UTC (rev 124583)
+++ zope.index/trunk/src/zope/index/keyword/index.py	2012-03-12 23:30:18 UTC (rev 124584)
@@ -75,12 +75,14 @@
         if isinstance(seq, basestring):
             raise TypeError('seq argument must be a list/tuple of strings')
 
+        old_kw = self._rev_index.get(docid, None)
         if not seq:
+            if old_kw:
+                self.unindex_doc(docid)
             return
 
         seq = self.normalize(seq)
 
-        old_kw = self._rev_index.get(docid, None)
         new_kw = self.family.OO.Set(seq)
 
         if old_kw is None:

Modified: zope.index/trunk/src/zope/index/keyword/tests.py
===================================================================
--- zope.index/trunk/src/zope/index/keyword/tests.py	2012-03-12 18:21:13 UTC (rev 124583)
+++ zope.index/trunk/src/zope/index/keyword/tests.py	2012-03-12 23:30:18 UTC (rev 124584)
@@ -138,7 +138,14 @@
         self.assertEqual(type(index._fwd_index['zope']),
             type(self.IFSet()))
 
+    def test_index_with_empty_sequence_unindexes(self):
+        index = self._makeOne()
+        self._populate(index)
+        self._search(index, 'cmf', self.IFSet([5]))
+        index.index_doc(5, ())
+        self._search(index, 'cmf', self.IFSet([]))
 
+
 class CaseInsensitiveKeywordIndexTestsBase:
 
     def _getTargetClass(self):



More information about the checkins mailing list