Friday, June 27, 2008

How to search in file fields in custom content-types in Plone 2.5

If you have a file upload field in your custom content type, you have to mark it as implementing IIndexableContent and provide a method indexableContent. For my custom type, which has a file field called "file", the method looks like this:

def indexableContent(self, fields):
if 'SearchableText' in fields:
file = self.getFile()
if file:
# file is a file object
mimetype = file.getContentType()
icc = ICC()
icc.addBinary('SearchableText',
str(file),
mimetype,
'iso-8859-15',
None)
return icc
return None

No comments: