[Zope-Checkins] CVS: Products/ZCTextIndex - IIndex.py:1.12.2.1 ZCTextIndex.py:1.48.2.3

Tres Seaver tseaver at palladion.com
Mon Sep 5 12:54:34 EDT 2005


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv10056/lib/python/Products/ZCTextIndex

Modified Files:
      Tag: Zope-2_7-branch
	IIndex.py ZCTextIndex.py 
Log Message:


 - Collector #1815: ZCTextIndex.index_object() now handles either
   strings or lists of strings.


=== Products/ZCTextIndex/IIndex.py 1.12 => 1.12.2.1 ===
--- Products/ZCTextIndex/IIndex.py:1.12	Thu Jun  5 15:43:54 2003
+++ Products/ZCTextIndex/IIndex.py	Mon Sep  5 12:54:03 2005
@@ -68,6 +68,9 @@
         """Add a document with the specified id and text to the index. If a
         document by that id already exists, replace its text with the new
         text provided
+        text  may be either a string (Unicode or otherwise) or a list
+        of strings from which to extract the terms under which to
+        index the source document.
         """
 
     def unindex_doc(docid):


=== Products/ZCTextIndex/ZCTextIndex.py 1.48.2.2 => 1.48.2.3 ===
--- Products/ZCTextIndex/ZCTextIndex.py:1.48.2.2	Tue May 17 14:10:40 2005
+++ Products/ZCTextIndex/ZCTextIndex.py	Mon Sep  5 12:54:03 2005
@@ -152,7 +152,14 @@
     ## Pluggable Index APIs ##
 
     def index_object(self, documentId, obj, threshold=None):
-        """ wrapper to handle indexing of multiple attributes """
+        """Wrapper for  index_doc()  handling indexing of multiple attributes.
+
+        Enter the document with the specified documentId in the index
+        under the terms extracted from the indexed text attributes,
+        each of which should yield either a string or a list of
+        strings (Unicode or otherwise) to be passed to index_doc().
+        """
+        # XXX We currently ignore subtransaction threshold
 
         # needed for backward compatibility
         try: fields = self._indexed_attrs
@@ -168,12 +175,22 @@
                 text = text()
             if text is None:
                 continue
-            all_texts.append(text)
+            # To index each attribute separately, we could use the
+            # following line, but we have preferred to make a single
+            # call to  index_doc()  for all attributes together.  
+            # res += self.index.index_doc(documentId, text)
+            if text:
+                if isinstance(text, (list, tuple, )):
+                    all_texts.extend(text)
+                else:
+                    all_texts.append(text)
 
-        if all_texts:        
-            return self.index.index_doc(documentId, ' '.join(all_texts))
-        else:
-            return 0
+        # 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
 
     def unindex_object(self, docid):
         if self.index.has_doc(docid):



More information about the Zope-Checkins mailing list