[Checkins] SVN: Products.ZCTextIndex/trunk/ Fixed problem discribed here : https://dev.plone.org/ticket/13310 : ZCTextIndex not reindexed when the new value is an empty value

Gauthier Bastien cvs-admin at zope.org
Tue Nov 13 15:56:32 UTC 2012


Log message for revision 128273:
  Fixed problem discribed here : https://dev.plone.org/ticket/13310 : ZCTextIndex not reindexed when the new value is an empty value

Changed:
  U   Products.ZCTextIndex/trunk/CHANGES.txt
  U   Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/ZCTextIndex.py
  U   Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testZCTextIndex.py

-=-
Modified: Products.ZCTextIndex/trunk/CHANGES.txt
===================================================================
--- Products.ZCTextIndex/trunk/CHANGES.txt	2012-11-13 12:25:11 UTC (rev 128272)
+++ Products.ZCTextIndex/trunk/CHANGES.txt	2012-11-13 15:56:32 UTC (rev 128273)
@@ -3,8 +3,10 @@
 
 2.13.4 (unreleased)
 -------------------
+- Fixed problem where the index was not reindexed if the new value was an empty value
+  leading to inconsistence between the object attribute (that is empty) and the index
+  that still contains the old indexed value [gauthier.bastien]
 
-
 2.13.3 (2011-07-28)
 -------------------
 

Modified: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/ZCTextIndex.py
===================================================================
--- Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/ZCTextIndex.py	2012-11-13 12:25:11 UTC (rev 128272)
+++ Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/ZCTextIndex.py	2012-11-13 15:56:32 UTC (rev 128273)
@@ -176,7 +176,6 @@
         try: fields = self._indexed_attrs
         except: fields  = [ self._fieldname ]
 
-        res = 0
         all_texts = []
         for attr in fields:
             text = getattr(obj, attr, None)
@@ -195,9 +194,7 @@
         # Check that we're sending only strings
         all_texts = filter(lambda text: isinstance(text, basestring), \
                            all_texts)
-        if all_texts:
-            return self.index.index_doc(documentId, all_texts)
-        return res
+        return self.index.index_doc(documentId, all_texts)
 
     def unindex_object(self, docid):
         if self.index.has_doc(docid):

Modified: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testZCTextIndex.py
===================================================================
--- Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testZCTextIndex.py	2012-11-13 12:25:11 UTC (rev 128272)
+++ Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testZCTextIndex.py	2012-11-13 15:56:32 UTC (rev 128273)
@@ -176,6 +176,37 @@
         nbest, total = zc_index.query('Tuesday Tim York')
         self.assertEqual(len(nbest), 0)
 
+    def testReindex(self):
+        lexicon = PLexicon('lexicon', '',
+                            Splitter(),
+                            CaseNormalizer(),
+                            StopWordRemover())
+        caller = LexiconHolder(self.lexicon)
+        zc_index = ZCTextIndex('name',
+                                None,
+                                caller,
+                                self.IndexFactory,
+                               'text',
+                               'lexicon')
+        doc = Indexable('Hello Tim')
+        zc_index.index_object(1, doc)
+        nbest, total = zc_index.query('glorious')
+        self.assertEqual(len(nbest), 0)
+        nbest, total = zc_index.query('Tim')
+        self.assertEqual(len(nbest), 1)
+        # reindex with another value
+        doc.text = 'Goodbye George'
+        zc_index.index_object(1, doc)
+        nbest, total = zc_index.query('Tim')
+        self.assertEqual(len(nbest), 0)
+        nbest, total = zc_index.query('Goodbye')
+        self.assertEqual(len(nbest), 1)
+        # reindex with an empty value
+        doc.text = ''
+        zc_index.index_object(1, doc)
+        nbest, total = zc_index.query('George')
+        self.assertEqual(len(nbest), 0)
+
     def testStopWords(self):
         # the only non-stopword is question
         text = ("to be or not to be "



More information about the checkins mailing list