class SearchContainer(ReadonlyContainer): __name__ = 'search' def __init__(self): self.clear() def clear(self): self.tag_container = SearchByTagContainer(self) self.catalog = Catalog() self.catalog['tags'] = KeywordIndex('tags', ITagged) self.catalog['name'] = TextIndex('display_name', IDisplayName, True) self.catalog['__all'] = TextIndex('tokens', ITokenized, True) self.ids = IntIds() def index_object(self, obj): real_obj = follow_symlinks(obj) try: self.catalog.index_doc(self.ids.register(real_obj), real_obj) except NotYet: log.msg("cannot index object %s because it's not yet committed" % obj, system='search') def _index_object(self, obj): real_obj = follow_symlinks(obj) self.catalog.index_doc(self.ids.register(real_obj), real_obj) def unindex_object(self, obj): try: self.catalog.unindex_doc(self.ids.register(obj)) except NotYet: log.msg("cannot unindex object %s because it's not yet committed" % obj, system='search') def search(self, **kwargs): # HACK, we should be able to setup a persistent utility provideUtility(self.ids, IIntIds) return list(self.catalog.searchResults(**kwargs)) def search_goog(self, query): # hack, zope catalog treats ':' specially return self.search(__all=query.replace(':', '_')) @property def _items(self): return {'by-tag': self.tag_container}