我希望为基于 Dexterity 的自定义内容类型的属性(“扇区”)启用一个名为“扇区”的特殊索引。
在我的架构中,在 types/mycontent.py 中,我有:
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,
)
(...)
然后我在 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
最后在根包configure.zcml中:
<adapter name="Sectors" factory=".indexers.Sectors"/>
但是,似乎不起作用。即使重新安装产品后,我也没有在portal_catalog 中看到索引,并且目录大脑对象似乎也没有它。
我做错了什么?
最佳答案
您没有定义目录索引。这只会使索引器可供添加。您的 GenericSetup 配置文件中需要一个具有以下内容的 Catalog.xml:
<?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>
关于indexing - plone.indexer 和 Dexterity 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6651174/