Recommended way to get summed up plain text of all blocks of a content item. in backend

Is text_strip(get_blocks_text(obj)) the way to go?
It works. I'm curious if this is recommended or if there is a better, performant suggestion.

from plone.restapi.indexers import get_blocks_text, text_strip

catalog = getToolByName(self.context, 'portal_catalog')
brains = catalog()

documents = []
for brain in brains:
    obj = brain.getObject()
    blocks_text = text_strip(get_blocks_text(obj))
1 Like

What is the role of the catalog here? SearchableText is not stored in the metadata so you've to recalculate it. From the plone point of view, you should use the SearchableText adapter that does basically the same + adding title, description and other fields. If you just want blocks, yes but you might have to consider IDynamicTextIndexExtender:

Yes, this is what the SearchableText indexer does for content with blocks.