How do I add keywords to SearchableText for a Dexterity content type?

隐身守侯 提交于 2019-12-10 14:19:24

问题


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.

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.

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.

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


回答1:


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")


来源:https://stackoverflow.com/questions/8852132/how-do-i-add-keywords-to-searchabletext-for-a-dexterity-content-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!