为内容类型添加索引

为内容类型添加索引
建立索引有两种方法,第一种方法是采用catalog.xml注册;另外一种方法是采用plone.indexer模块,利用命名适配器方法建立索引。
第一种方法:
When we defined validators for film and cinema code, we made use of two new catalog indexes, filmCode and cinemaCode. We can now add the indexes to the catalog with the catalog.xml import step:
<object name="portal_catalog"> <index name="filmCode" meta_type="FieldIndex"> <indexed_attr value="filmCode"/> </index> <index name="cinemaCode" meta_type="FieldIndex"> <indexed_attr value="cinemaCode"/> </index> <column value="filmCode"/> <column value="cinemaCode"/> </object>
Be aware that the catalog.xml import step will delete and recreate the
index if the profile is later re-applied in full, requiring a reindex that can
be very slow on large sites.
第二方法:
from five import grok from plone.indexer import indexer ... @grok.adapter(IFilm, name='start') @indexer(IFilm) def filmStartIndexer(context): return context.startDate The @indexer decorator from plone.indexer is used to turn the function into an indexer, and to limit it so that it only operates on objects providing IFilm. We then use five.grok to register it as a named adapter from IFilm with the name "start".The adapter name matches the catalog index.
结论:
第二种方法,由于提供了接口限制了被索引的内容类型,效率要明星优于第一种方法。
设置