如何为敏捷内容类型向SearchableText添加关键字? [英] How do I add keywords to SearchableText for a Dexterity content type?

查看:111
本文介绍了如何为敏捷内容类型向SearchableText添加关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Plone 4.1的站点,该站点具有使用Dexterity 1.1开发的自定义内容类型.我的内容作者可以使用分类"选项卡将关键字添加到基本的克隆"页面,如果用户使用其中一个关键字进行搜索,则用户可以成功找到这些页面.

I have a site running Plone 4.1 which has a custom content type developed with Dexterity 1.1. My content authors can add keywords to basic Plone pages using the Categorization tab and users successfully find these pages if they search using one of the keywords.

我的内容作者还使用我开发的Dexterity自定义内容类型制作了页面.这是使用基于Python的文件系统架构定义的.如果用户在敏捷内容类型的标题和描述中搜索术语,则会在搜索结果中返回敏捷页面.如果他们在关键字字段中使用查询词进行搜索,则不会获得任何结果.但是,如果在标签列表中突出显示了适当的标签,则可以在高级"搜索表单下找到敏捷"页面.

My content authors have also produced pages using a Dexterity custom content type I developed. This was defined using a Python-based file system schema. If users search for terms in the title and description of a Dexterity content type they get back the Dexterity pages in the search results. If they search using a query term in the keywords field they get no results. However, under the Advanced search form they can find the Dexterity page if they highlight the appropriate tag in the list of tags.

我已经使用ZMI中的portal_catalog工具检查了搜索索引的内容.似乎正在将诸如Page之类的基本内容类型的关键字添加到SearchableText字段中,但是对于基于我的基于敏捷的自定义内容类型,则不是.

I've inspected the contents of the search index using the portal_catalog tool in ZMI. It appears keywords are being added to the SearchableText field for basic content types such as Page but for my Dexterity-based custom content type they are not.

我是否需要编写其他代码以将关键字字段的内容插入SearchableText索引中?

Do I need to write additional code to insert the contents of the keywords field into the SearchableText index?

推荐答案

假设您的Dexterity内容类型实现了IFoo,并且在模式中定义的keywords属性是字符串列表.

Let's say your Dexterity content type implements IFoo, and the keywords attribute defined in your schema is a list of strings.

您可以通过以下方式定义索引器:

You define your indexer in this way:

from five import grok
from plone.indexer.decorator import indexer
from my.dexteritycontent.foo import IFoo

@indexer(IFoo)
def searchableIndexer(context):
    keywords = " ".join(context.keywords)
    return "%s %s %s" % (context.title, context.description, keywords)

grok.global_adapter(searchableIndexer, name="SearchableText")

这篇关于如何为敏捷内容类型向SearchableText添加关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆