[Zope-Coders] Patch for KeywordIndexes
Sidnei da Silva
sidnei@x3ng.com
Fri, 30 May 2003 20:13:59 -0300
--OgqxwSJOaUobr8KG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Fri, May 30, 2003 at 05:34:30PM -0400, Tres Seaver wrote:
| 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".
You're right. It needs to test for string-like *and* for
iterability. Here's the fixed version.
--
Sidnei da Silva (dreamcatcher) <sidnei@x3ng.com.br>
X3ng Web Technology <http://www.x3ng.com.br>
GNU/Linux user 257852
Debian GNU/Linux 3.0 (Sid) 2.4.20-powerpc ppc
Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.
--OgqxwSJOaUobr8KG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="keywordindex.patch"
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 23:10:59 -0000
@@ -90,12 +90,15 @@
newKeywords = newKeywords()
if hasattr(newKeywords,'capitalize'): # is it string-like ?
newKeywords = (newKeywords, )
- else:
- # Uniqueify keywords
- unique = {}
- for k in newKeywords:
- unique[k] = None
- newKeywords = unique.keys()
+ try: # Test for iterability
+ for n in newKeywords: pass
+ except TypeError:
+ newKeywords = (newKeywords, )
+ # Uniqueify keywords
+ unique = {}
+ for k in newKeywords:
+ unique[k] = None
+ newKeywords = unique.keys()
return newKeywords
def unindex_objectKeywords(self, documentId, keywords):
--OgqxwSJOaUobr8KG--