Rig*_*ala 7 indexing plone dexterity
我希望为我的基于Dexterity的自定义内容类型的属性('sector')启用一个名为Sectors的特殊索引.
在我的架构中,在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,
)
(...)
Run Code Online (Sandbox Code Playgroud)
然后我在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
Run Code Online (Sandbox Code Playgroud)
最后在root包configure.zcml中:
<adapter name="Sectors" factory=".indexers.Sectors"/>
Run Code Online (Sandbox Code Playgroud)
但是,它似乎不起作用.即使重新安装产品后,我也看不到portal_catalog和catalog脑对象中的索引似乎也没有.
我究竟做错了什么?
Mat*_*kes 10
您没有定义目录索引.这只会使索引器可用.您需要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>
Run Code Online (Sandbox Code Playgroud)