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

Andreas Jung andreas@digicool.com
Mon, 18 Feb 2002 11:56:54 -0500


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

Modified Files:
      Tag: ajung-textindexng-branch
	TextIndexNG.py 
Log Message:
- minor tweaks to get around problems with wrong default char. encoding
- removed a hack to retrieve objects for near searches


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.37 => 1.2.2.38 ===
         try:
             source = getattr(obj, self.id)
-            if callable(source): source = str(source())
-            else:                source = str(source)
+            if callable(source): source = source()
+            
+            if not isinstance(source, UnicodeType):
+                source = str(source)
+
         except (AttributeError, TypeError):
             return 0
         
@@ -770,11 +773,20 @@
         return valid_positions
 
 
-    # THIS IS A BAD BAD HACK !
+    def getDataFromObject(self, docId): 
+        """ get data from a object (used for near search) """
+
+        # HACK: we must ask the catalog for the path for a given 
+        # docId :-(
+        path = self.catalog.paths[docId]
+
+        # retrieve the object
+        obj = self.catalog.unrestrictedTraverse( path )
+
+        # and its attribute
+        data = getattr(obj, self.id)
+        if callable(data): data = data()
 
-    def getDataFromObject(self, docId):
-        obj = self.__OBJECTS[docId]
-        data = getattr(obj,self.id)
         return data