How to override/patch a indexer

During the migration from Archetypes to Dexterity all files are reindexed several times (e.g. when one of the parent-folders is migrated). This can take a lot of time and is completely unneccessary.

Patching the indexer-method with monkey-patching (collective-monkeypatcher and Products.contentmigration.utils.patch seems to be impossible. The only way I found is using a overrides.zcml and registering a empty function as a indexer. It would be more convenient to be able to switch indexers on and off on-the-fly in code during the migration.

Disabling the same for Archetypes is no issue since patching ATBlob.getIndexValue is trivial.

wild, wild guess, but could you use:


no_longer_searchable(IBasic, 'body')

(just during migration)

Does fit your use case?

@tomgross Great, that works fine in Plone 5.

But it does not really fit my use-case which is to skip indexing only for a certain piece of code and certain content. Still, it got me to not patch the indexer itself but walk up the stack and patch and later unpatch one of the calling methods instead. The obvious downside of this solution is that it prevents all indexing and not only the indexing of SeachableText for

So far I could not find a way to patch a indexer registered as an adpater (or a event-handler). I guess unregistering a adapter in python and re-registering it afterwards would be possible but so far I did not find a way. Also overriding it temporarily with a more specific adapter does not work since the Interfaces in question are already the most specific ones (IFile and IIndexer).

Maybe I can sit down with someone more ZCA-savy during the sprint in Finnland next week to come up with code that works.