【问题标题】:How do I add a custom Zope2 catalog index with plone.indexer?如何使用 plone.indexer 添加自定义 Zope2 目录索引?
【发布时间】:2012-06-15 01:23:25
【问题描述】:

我正在尝试根据此处的建议添加自定义目录索引:

My code 看起来像这样(h/t: supton):

from plone.indexer.decorator import indexer
from Products.ATContentTypes.interfaces.event import IATEvent
from Products.ATContentTypes.utils import DT2dt

@indexer(IATEvent)
def event_days(context, **kw):
    start = DT2dt(context.getStartDate())
    end = DT2dt(context.getEndDate())
    delta = end - start
    return delta.days

在以下 ZCML 注册:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:five="http://namespaces.zope.org/five"
    xmlns:genericsetup="http://namespaces.zope.org/genericsetup">

    <five:registerPackage package="." initialize=".initialize" />

    <genericsetup:registerProfile
        description="event_days_indexer"
        directory="profiles/default"
        name="default"
        provides="Products.GenericSetup.interfaces.EXTENSION"
        title="event_days_indexer"
    />

    <adapter name="event_days" factory=".indexers.event_days" />

</configure>

一切似乎都加载得很好,但是当我创建一个测试事件并重新索引目录时,索引仍然是空的。我错过了什么?

【问题讨论】:

  • 嗯,日志里有什么吗?
  • @Yuri: 如果有 AttributeError 就不会有。
  • @aclark:别告诉我你不知道如何在那个索引器中放一个pdb.set_trace().. :-P
  • @MartijnPieters 实际上我在函数上方有一个可以检查 IATEvent,但我没有想到更进一步(我希望有回溯)。

标签: plone zope catalog


【解决方案1】:

如果索引器遇到 AttributeError,则不会考虑将对象作为索引。

在这种情况下发生这种情况是因为 ATContentTypes 为 startDate 和 endDate 字段指定了自定义访问器。代替 context.getStartDate() 和 context.getEndDate(),使用 context.start() 和 context.end()

【讨论】:

  • 谢谢!我不会问为什么没有回溯……
  • @aclark:索引器总是吞下 AttributeErrors(然后他们索引 Missing.MV aka “缺失值”)。
  • @MartijnPieters 啊,谢谢。有什么地方可以找到缺失值吗? (相对于在 portal_catalog 中看到零结果)
  • @aclark:啊,不,我错了;当方法引发 AttributeError 时,索引通常根本不插入任何内容,并且对于此类列,CatalogBrain 值将为Missing.MV
猜你喜欢
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多