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:
Post a Comment
Note: Only a member of this blog may post a comment.