Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 630
Andrew Heckford Avatar asked Jan 13 '12 14:01

Andrew Heckford


1 Answers

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")
like image 143
Rigel Di Scala Avatar answered Nov 10 '22 01:11

Rigel Di Scala