我正在尝试扩展我的内容类型的 SearchableText 索引。
我通过在模型文件中将多个字段标记为 indexer:searchable="true" 成功地包含了多个字段。
但是我无法从我的类型的 py 扩展 SearchableText,如下所示:
class IMyBehavior(form.Schema):
dexteritytextindexer.searchable('description')
description = schema.Text(title=u'Precis')
alsoProvides(IMyBehavior, IFormFieldProvider)
class MySearchableTextExtender(object):
adapts(IMyBehavior)
implements(dexteritytextindexer.IDynamicTextIndexExtender)
def __init__(self, context):
self.context = context
def __call__(self):
"""Extend the searchable text with a custom string"""
return 'some more searchable words'
我不得不承认,我真的不知道头等舱是如何运作的。我是否必须在此类中设置可搜索字段才能扩展第二个类中的 SearchableText ?
如果我从模型中删除所有索引器:searchable =“true”,则 SearchableText 只是空的。
第一个类是否同时尝试注册模式?如果是这样,如果它只是扩展 SearchableText,它应该是什么样子?
The collective.dexteritytextindexer
提供了两个重要的功能:
正如您已经取得的成就,dexteritytextindexer
让你有能力把values
进入克隆人的SearchableText
指数。通过增加dexteritytextindexer.searchable(FIELDNAME)
对于您的表单,该字段的值将出现在SearchableText
。在 Archetypes 中,您可以通过添加相同的功能searchable=True
到字段定义。
collective.dexteritytextindexer
还让您能够extend通过注册手动搜索可搜索文本IDynamicTextIndexExtender
适配器。它extends的值来自part 1
使用适配器中的值。
我想您的情况的问题是您错过了注册适配器:https://github.com/collective/collective.dexteritytextindexer#extending-indexed-data https://github.com/collective/collective.dexteritytextindexer#extending-indexed-data
例子:
<adapter
factory=".yourbehavior.MySearchableTextExtender"
provides="collective.dexteritytextindexer.IDynamicTextIndexExtender"
name="IMyBehavior"
/>
这是一个工作示例:
这段代码扩展了SearchableText
具有其子级的 searchableText 的容器。
IDynamicTextIndexExtender 适配器:https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/indexer.py https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/indexer.py
使用 zcml 注册适配器:https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/behaviors.zcml#L21 https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/behaviors.zcml#L21
最重要的部分 - 测试实施:https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/tests/test_indexer.py#L31 https://github.com/4teamwork/ftw.simplelayout/blob/a7d631de3984b8c1747506b9411045fdf83bc908/ftw/simplelayout/tests/test_indexer.py#L31
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)