Adrian Garner
Adrian Garner

Reputation: 5335

Update SearchableText index on dexterity type

I am trying to update SearchableText on my dexterity type ("Resource"), to include file contents from child items, by adding this to resource.py:

@indexer(IResource)
def subFiles(obj):
    searchable_text = obj.SearchableText()

    for item in obj.getFolderContents({'portal_type': 'File'}, full_object=True):
        searchable_text += item.SearchableText()
    return searchable_text

grok.global_adapter(subFiles, name="SearchableText")

I know I need an event to update this, but believe I should be able to see the index modified by manually "clearing and rebuilding" from the ZMI, however no changes take place on the value of SearchableText for objects of this content type. I am not seeing any errors either, so I am not sure where the problem lies.

Upvotes: 1

Views: 244

Answers (1)

Mathias
Mathias

Reputation: 6839

Well, I did not recognise here, that you are using dexterity.

You need the dexteritytextindexer behavior: https://github.com/collective/collective.dexteritytextindexer

Enable this on your container type.

<property name="behaviors">
    <element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
</property>

With the dexteritytextindexer you have a different approach to index the data on your container. Check the dexteritytextindexer.IDynamicTextIndexExtender.

Upvotes: 2

Related Questions