Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with plone.indexer and Dexterity

I wish to enable a special index, called Sectors, for a attribute ('sectors') of my Dexterity based custom content-type.

In my schema, inside types/mycontent.py I have:

class IMyContent(form.Schema):
    """
    My Content
    """
    sectors = schema.Set(
            title=_(u"Sectors"),
            description=_(u"Select some sectors"),
            value_type=schema.Choice(vocabulary=vocs.sectors),
            required=True,
        )

    (...)

I then define the index in this way, inside indexers.py

from plone.indexer.decorator import indexer
from zr.content.types.mycontent import IMyContent

@indexer(IMyContent)
def Sectors(obj):
    """Indexer for Sectors attribute.
    """
    d = getattr(obj, "sectors", u"")
    return d if d else None

Finally in the root package configure.zcml:

<adapter name="Sectors" factory=".indexers.Sectors"/>

However, it does not seem to work. Even after reinstalling the product, I don't see the index in portal_catalog and catalog brain object do not seem to have it either.

What am I doing wrong?

like image 431
Rigel Di Scala Avatar asked Jul 11 '11 13:07

Rigel Di Scala


1 Answers

You aren't defining the catalogue index. This will just make the indexer available to be added. You require a catalog.xml in your GenericSetup profile with:

<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">
 <index name="Sectors" meta_type="KeywordIndex">
  <indexed_attr value="Sectors"/>
 </index>
</object>
like image 164
MatthewWilkes Avatar answered Sep 22 '22 00:09

MatthewWilkes