[Zope-Coders] Patch for KeywordIndexes

Tres Seaver tseaver@zope.com
30 May 2003 17:34:30 -0400


On Fri, 2003-05-30 at 17:21, Sidnei da Silva wrote:
> If no one object (or if someone provides a better way to do this) I
> would like to apply the following patch for KeywordIndexes on
> 2_6-branch and HEAD. Its just completely annoying that this worked
> before, and now its so stupidly broken :(

I don't think your patch works correctly:  the test for "string-like" is
not the same as a test for iterability.  As a check, try indexing an
object with a "string" property (instead of "lines" or "tokens").  I'll
bet you end up indexing each letter of the string as a "keyword".

> Index: lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
> ===================================================================
> RCS file: /cvs-repository/Zope/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py,v
> retrieving revision 1.11.6.1
> diff -u -r1.11.6.1 KeywordIndex.py
> --- lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	28 Feb 2003 15:58:18 -0000	1.11.6.1
> +++ lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	30 May 2003 21:20:15 -0000
> @@ -88,14 +88,16 @@
>          newKeywords = getattr(obj, self.id, ())
>          if callable(newKeywords):
>              newKeywords = newKeywords()
> -        if hasattr(newKeywords,'capitalize'): # is it string-like ?
> +        try:
> +            # Test for iterability
> +            for n in newKeywords: pass
> +        except TypeError:
>              newKeywords = (newKeywords, )
> -        else:
> -            # Uniqueify keywords
> -            unique = {}
> -            for k in newKeywords:
> -                unique[k] = None
> -            newKeywords = unique.keys()
> +        # Uniqueify keywords
> +        unique = {}
> +        for k in newKeywords:
> +            unique[k] = None
> +        newKeywords = unique.keys()
>          return newKeywords
>  
>      def unindex_objectKeywords(self, documentId, keywords):

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com