[英]Cataloging multiple types under one index using plone.indexer
In configure.zcml
I have: 在
configure.zcml
我有:
<adapter name="getCountry" factory=".extender.country_indexer" />
In extender.py
I have: 在
extender.py
我有:
@indexer(IATFile)
@indexer(IATImage)
@indexer(IProject)
@indexer(IATDocument)
def country_indexer(context):
return _country_indexer(context)
But this does not catalog all those types under the getCountry
index. 但这并没有在
getCountry
索引下对所有这些类型进行分类。
If I comment out all but one decorator, it works for that type. 如果我注释掉除一个装饰器之外的所有装饰器,则它适用于该类型。
How do I manage to catalog all of them? 如何管理所有目录?
Some more info. 一些更多的信息。 Only one of the registrations is called with the proper callable.
只有其中一个注册被正确调用。 The others are called with DelegatingIndexerFactory:
其他的则用DelegatingIndexerFactory调用:
indexer.__init__ <plone.indexer.decorator.indexer instance at 0xafa6998> (<InterfaceClass Products.ATContentTypes.interfaces.file.IATFile>,)
indexer.__init__ <plone.indexer.decorator.indexer instance at 0xafa6f80> (<InterfaceClass Products.ATContentTypes.interfaces.image.IATImage>,)
indexer.__init__ <plone.indexer.decorator.indexer instance at 0xafa8050> (<InterfaceClass project.interfaces.project.IProject>,)
indexer.__init__ <plone.indexer.decorator.indexer instance at 0xafa8128> (<InterfaceClass Products.ATContentTypes.interfaces.document.IATDocument>,)
indexer.__call__ <plone.indexer.decorator.indexer instance at 0xafa8128> <function country_indexer at 0xafa76e0>
indexer.__call__ <plone.indexer.decorator.indexer instance at 0xafa8050> <plone.indexer.delegate.DelegatingIndexerFactory object at 0xafa5910>
indexer.__call__ <plone.indexer.decorator.indexer instance at 0xafa6f80> <plone.indexer.delegate.DelegatingIndexerFactory object at 0xafa5b90>
indexer.__call__ <plone.indexer.decorator.indexer instance at 0xafa6998> <plone.indexer.delegate.DelegatingIndexerFactory object at 0xafa5910>
I'm afraid the @indexer
decorator does not support chaining. 恐怕
@indexer
装饰器不支持链接。
There are several possible solutions: 有几种可能的解决方案:
Mark the content, which support _country_indexer
with a separate marker interface. 使用单独的标记界面标记支持
_country_indexer
的内容。 For example ICountry
? 例如
ICountry
?
This can be done with ZCML: 这可以使用ZCML完成:
<class class="dotted.name.to.my.class">
<implements interface="dotted.name.to.ICountry" />
</class>
Then use this interface for the indexer
然后将此接口用于
indexer
@indexer(ICountry)
def country_indexer(context):
return _country_indexer(context)
Interface
and implement the logic directly into the method: Interface
注册并将逻辑直接实现到方法中: @indexer(Interface)
def country_indexer(context):
SUPPORTED = [IATFile, IATImage, IProject, IATDocument]
...
@indexer(IATDocument)
def country_indexer_at_doc(context):
return _country_indexer(context)
@indexer(IATFile)
def country_indexer_at_file(context):
return _country_indexer(context)
@indexer(IATImage)
def country_indexer_at_img(context):
return _country_indexer(context)
...
And the zcml part: 和zcml部分:
<adapter name="getCountry" factory=".extender.country_indexer_at_doc" />
<adapter name="getCountry" factory=".extender.country_indexer_at_file" />
<adapter name="getCountry" factory=".extender.country_indexer_at_img" />
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.