Friday, October 5, 2007

Case sensitive search in Zope 2.9.7

I'm not 100% happy with this function, and I'm wondering if I'm doing too much work. Especially waking up the object when the word object is not found in the object.Description attribute. Is there a better way?

def getWords(word):
pc = app.msrd.portal_catalog
results = []
for brain in pc(SearchableText=word):
if word in brain.Description:
results.append(brain.getPath())
continue
try:
content = brain.getObject()
for field in content.schema.fields():
name = field.__dict__['__name__']
if 'body' in name or 'Body' in name:
accessor = field.__dict__['accessor']
text = content[accessor]()
if word in text:
results.append(content.absolute_url())
continue
except:
continue
return results

No comments: