Problem with plone.indexer and agility

I want to include a special index called Sectors for the attribute (sectors) of my custom Dexterity-based content type.

In my schema, inside the /mycontent.py types, I have:

class IMyContent(form.Schema): """ My Content """ sectors = schema.Set( title=_(u"Sectors"), description=_(u"Select some sectors"), value_type=schema.Choice(vocabulary=vocs.sectors), required=True, ) (...) 

Then I define the index this way, inside indexers.py

 from plone.indexer.decorator import indexer from zr.content.types.mycontent import IMyContent @indexer(IMyContent) def Sectors(obj): """Indexer for Sectors attribute. """ d = getattr(obj, "sectors", u"") return d if d else None 

Finally, in the configure.zcml root package:

 <adapter name="Sectors" factory=".indexers.Sectors"/> 

However, it does not work. Even after reinstalling the product, I do not see that the index in the portal_directory and the object of the object in the directory were not there either.

What am I doing wrong?

+7
source share
2 answers

You do not define a directory index. It will just add an index. You need the catalog.xml file in the GenericSetup profile with:

 <?xml version="1.0"?> <object name="portal_catalog" meta_type="Plone Catalog Tool"> <index name="Sectors" meta_type="KeywordIndex"> <indexed_attr value="Sectors"/> </index> </object> 
+10
source

The decision made may be somewhat unclear, so here are a few clarifications:

1) DO NOT edit the global global setting.

If you are doing something extremely strange, you will install your site as a series of plone extensions and have a folder structure, for example:

 app.plugin/ app.plugin/app/ app.plugin/app/configure.zcml app.plugin/app/profiles/ app.plugin/app/profiles/default app.plugin/app/profiles/default/types app.plugin/app/profiles/default/types/Folder.xml app.plugin/app/profiles/default/types/app.mydexteritytype.xml app.plugin/app/profiles/default/types.xml app.plugin/app/profiles/default/portlets.xml app.plugin/app/profiles/default/catalog.xml <---- ADD THIS 

2) You do not need to have an xml block (according to the decision) in the catalog.xml file, you can simply create an index from the ZMI interface. However, if you do, it will be reset the next time you plug in your plugins. Therefore, you probably want to.

3) After installing your .xml directory, go to the ZMI interface to portal_catalog and make sure that the pointer exists on the indexes tab. If it is not, you are messed up.

4) To create an index, you need to go to the "advanced" tab and select the rebuild command.

5) The indexer eagerly consumes exceptions and does not raise them (it is especially important for AttributeError, you cannot index some values ​​that you want to index), so if you want to make sure that your indexer is actually running, try adding log or print in it:

 @indexer(IMyDexterityType) def dummy_indexer(obj, **kw): try: print('indexed: %r' % obj) return obj.title except Exception as e: print('index fail: %r' % e) return '' 

If you don’t see anything else, for example:

 2013-08-12 16:42:28 INFO GenericSetup.archetypetool Archetype tool imported. 2013-08-12 16:42:28 INFO GenericSetup.resourceregistry Stylesheet registry imported. 2013-08-12 16:42:28 INFO GenericSetup.resourceregistry Javascript registry imported. indexed: <MyDexterityType at /Plone/test/cat-document-0> indexed: <MyDexterityType at /Plone/test/hello> 

6) grok.global_adapter (), as indicated in some documents ( http://developer.plone.org/reference_manuals/external/plone.app.dexterity/advanced/catalog-indexing-strategies.html?highlight=custom%20indexing# creating-custom-indexers ) deals with registering virtual properties and do not mitigate the need to customize your .xml directory.

Finally, someone drew a working example on github, which is very useful:

https://github.com/aclark4life/event_days_indexer

0
source

All Articles