[Zope-CVS] CVS: Products/ZCTextIndex - ZCTextIndex.py:1.16

Guido van Rossum guido@python.org
Mon, 20 May 2002 15:33:34 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv31204

Modified Files:
	ZCTextIndex.py 
Log Message:
index_object(): don't die if obj doesn't have an attribute named
_fieldname; simply return 0 in this case.


=== Products/ZCTextIndex/ZCTextIndex.py 1.15 => 1.16 ===
     def index_object(self, docid, obj, threshold=None):
         # XXX We currently ignore subtransaction threshold
-        count = self.index.index_doc(docid, self._get_object_text(obj))
+        text = getattr(obj, self._fieldname, None)
+        if text is None:
+            return 0
+        if callable(text):
+            text = text()
+        count = self.index.index_doc(docid, text)
         self._p_changed = 1 # XXX
         return count
 
@@ -131,15 +136,6 @@
     def clear(self):
         """reinitialize the index"""
         self.index = self._index_factory(self.lexicon)
-
-    ## Helper ##
-
-    def _get_object_text(self, obj):
-        x = getattr(obj, self._fieldname)
-        if callable(x):
-            return x()
-        else:
-            return x
 
     ## User Interface Methods ##