简体   繁体   English

使用plone.indexer在一个索引下分类多种类型

[英]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: 有几种可能的解决方案:

1. Marker interface (My Favorite) 1.标记界面(我的最爱)

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)

2. Register on Interface and implement the logic directly into the method: 2.在Interface注册并将逻辑直接实现到方法中:

@indexer(Interface)
def country_indexer(context):
    SUPPORTED = [IATFile, IATImage, IProject, IATDocument]
    ...

3. Duplicate your code several times 3.重复多次代码

@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.

相关问题 如何使用Plone中的日期列表索引一个字段日期 - How to index one field Dates with a list of dates in Plone 如何使用pandas在同一行索引下有多行 - How to have multiple rows under the same row index using pandas ValueError:无法使用长度与值不同的多索引选择索引器进行设置 - ValueError: cannot set using a multi-index selection indexer with a different length than the value 使用RabbitMQ和Plone - 芹菜与否? - Using RabbitMQ with Plone - Celery or not? 修复代码以摆脱 ValueError: cannot set using a multi-index selection indexer with different length - Fix the code to get rid of ValueError: cannot set using a multi-index selection indexer with a different length 如何解决“无法使用长度与值不同的多索引选择索引器进行设置” - How to solve “cannot set using a multi-index selection indexer with a different length than the value” 如何解决 - ValueError:无法使用长度与 Python 中的值不同的多索引选择索引器进行设置 - How to resolve - ValueError: cannot set using a multi-index selection indexer with a different length than the value in Python 修复以下错误:ValueError: cannot set using a multi-index selection indexer with a different length - Fix the following error: ValueError: cannot set using a multi-index selection indexer with a different length Django 中的一对一关系但有多种类型 - one-to-one relationship but of multiple types in Django Plone中的异步任务以查询Python包索引 - Asynchronous tasks in Plone to query Python Package Index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM