标题和描述未使用 Collective.dexteritytextindexer 进行索引

发布于 2024-12-05 13:31:24 字数 910 浏览 0 评论 0原文

我有很多 Dexterity 内容类型,其中一些只是容器,只留下标题和描述(来自 plone.app.dexterity.behaviors.metadata.IBasic 行为)。

我可以通过搜索标题或描述中的文本来找到它们。

但对于一些复杂的内容类型,我使用 collective.dexteritytextindexer 来索引更多字段和它工作正常,我可以在我标记为索引的字段上找到文本。

但是,标题和说明不再可用于搜索。我尝试了类似的操作:

class IMyContent(form.Schema):
    """My content type description
    """

    dexteritytextindexer.searchable('title')
    dexteritytextindexer.searchable('description')

    dexteritytextindexer.searchable('long_desc')
    form.widget(long_desc = WysiwygFieldWidget)
    long_desc = schema.Text (
            title = _(u"Rich description"),
            description = _(u"Complete description"),
            required = False,
        )
    ...

但我看不到portal_catalog中SearchableText列上的标题和描述内容,因此结果没有显示它们。

知道我缺少什么吗?

干杯,

I have lots of Dexterity content types, some of them are just containers and are left with just the Title and Description (from plone.app.dexterity.behaviors.metadata.IBasic behavior).

I can find them by searching the text inside their title or description.

But for some complex content types I'm using collective.dexteritytextindexer to index some more fields and it works fine, I can find the text on the fields I marked to be indexed.

However the Title and Description are no longer available for searching. I tried something like:

class IMyContent(form.Schema):
    """My content type description
    """

    dexteritytextindexer.searchable('title')
    dexteritytextindexer.searchable('description')

    dexteritytextindexer.searchable('long_desc')
    form.widget(long_desc = WysiwygFieldWidget)
    long_desc = schema.Text (
            title = _(u"Rich description"),
            description = _(u"Complete description"),
            required = False,
        )
    ...

But I can't see the content of title and description on the SearchableText column in the portal_catalog, and thus the results don't show them.

Any idea what I'm missing?

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

几味少女 2024-12-12 13:31:24

遇到了几乎同样的问题。遵循 http://pypi.python.org/pypi/collective.dexteritytextindexer 上的文档我曾经

from collective import dexteritytextindexer
from plone.autoform.interfaces import IFormFieldProvider
from plone.directives import form
from zope import schema
from zope.interface import alsoProvides

class IMyBehavior(form.Schema):

    dexteritytextindexer.searchable('specialfield')
    specialfield = schema.TextField(title=u'Special field')

alsoProvides(IMyBehavior, IFormFieldProvider)

为自己的字段建立索引。但是,该代码

from plone.app.dexterity.interfaces import IBasic
from collective.dexteritytextindexer.utils import searchable

searchable(IBasic, 'title')
searchable(IBasic, 'description')

不起作用。 IBasic 导入失败。看来这可以通过导入轻松解决

from plone.app.dexterity.behaviors.metadata import IBasic

Got pretty much the same issue. Following the documentation on http://pypi.python.org/pypi/collective.dexteritytextindexer I used

from collective import dexteritytextindexer
from plone.autoform.interfaces import IFormFieldProvider
from plone.directives import form
from zope import schema
from zope.interface import alsoProvides

class IMyBehavior(form.Schema):

    dexteritytextindexer.searchable('specialfield')
    specialfield = schema.TextField(title=u'Special field')

alsoProvides(IMyBehavior, IFormFieldProvider)

to get my own fields indexed. However, the code

from plone.app.dexterity.interfaces import IBasic
from collective.dexteritytextindexer.utils import searchable

searchable(IBasic, 'title')
searchable(IBasic, 'description')

Didn't work. The import of IBasic fails. Seems this can easily be solved by importing

from plone.app.dexterity.behaviors.metadata import IBasic
_畞蕅 2024-12-12 13:31:24

问题可能是该字段来自 IBasic 或 IDublineCore 行为,而不是来自您的架构。不过,我对 Collective.dexteritytextindexer 的了解还不够,不知道如何解决这个问题。

另一种选择可能是只使用 plone.indexer 并创建您自己的 SearchableText 索引器,该索引器返回 "%s %s %s" % (context.title, context.description, context.long_desc,)。有关详细信息,请参阅敏捷文档。

The problem is probably that the field is coming from the IBasic or IDublineCore behaviour and not from your schema. I don't know enough about collective.dexteritytextindexer to know how to work around this, though.

Another option may be to just use plone.indexer and create your own SearchableText indexer that returns "%s %s %s" % (context.title, context.description, context.long_desc,). See the Dexterity docs for details.

我家小可爱 2024-12-12 13:31:24

作为参考,这是我最终编写的代码:

@indexer(IMyDexterityType)
def searchableIndexer(context):
    transforms = getToolByName(context, 'portal_transforms')
    long_desc = context.long_desc // long_desc is a rich text field
    if long_desc is not None:
        long_desc = transforms.convert('html_to_text', long_desc).getData()
    contacts = context.contacts // contacts is also a rich text field
    if contacts is not None:
        contacts = transforms.convert('html_to_text', contacts).getData()

    return "%s %s %s %s" % (context.title, context.description, long_desc, contacts,)
grok.global_adapter(searchableIndexer, name="SearchableText")

As a reference this is the code I ended up writing:

@indexer(IMyDexterityType)
def searchableIndexer(context):
    transforms = getToolByName(context, 'portal_transforms')
    long_desc = context.long_desc // long_desc is a rich text field
    if long_desc is not None:
        long_desc = transforms.convert('html_to_text', long_desc).getData()
    contacts = context.contacts // contacts is also a rich text field
    if contacts is not None:
        contacts = transforms.convert('html_to_text', contacts).getData()

    return "%s %s %s %s" % (context.title, context.description, long_desc, contacts,)
grok.global_adapter(searchableIndexer, name="SearchableText")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文