plonezope

Why does my content object not show up in the portal_catalog?


I am trying to implement a basic Zope2 content type directly without using dexterity or Archetypes because I need this to be extremely lean.

from OFS.SimpleItem import SimpleItem
from Products.ZCatalog.CatalogPathAwareness import CatalogAware
from persistent.list import PersistentList

class Doculite(SimpleItem, CatalogAware):
    """ implement our class """

    meta_type = 'Doculite'

    def __init__(self, id, title="No title", desc=''):
        self.id = id
        self.title = title
        self.desc = desc
        self.tags = PersistentList()
        self.default_catalog = 'portal_catalog'

    def add_tags(self, tags):
        self.tags.extend(tags)

    def Subject(self):
        return self.tags

    def indexObject(self):
        self.reindex_object()

From an external method I am doing this:

def doit(self):
    pc = self.portal_catalog
    res1 = pc.searchResults()
    o1 = self['doc1']
    o1.add_tags(['test1', 'test2'])
    o1.reindex_object()
    res2 = pc.searchResults()
    return 'Done'

I clear the catalog and run my external method. My object does not get into the catalog. But from the indexes tab, when I browse the Subject index, I can see my content item listed with the values. Both res1 and res2 and empty.

Why is my content item not showing up inside the searchResuts() of the catalog?


Solution

  • Plone needs every content object to provide an "allowedRolesAndUsers" index to return the object in searchResults.

    There is probably a zcml snippet that will enable this for my content type. But I was able to get things working by adding another method as follows:

    def allowedRolesAndUsers(self):
        return ['Manager', 'Authenticated', 'Anonymous']