[Zope] Search a Catalog in Python
Dragos Chirila
d.chirila at finsiel.ro
Wed Mar 17 04:39:02 EST 2004
I'm hiding the catalog object because I don't want to be dependent of a
Catalog object in my folderish object or the object Catalog in the ROOT or
you name it.
I need this hidden catalog object to catalog only what I want and to do
exactly what I need. In this way I am sure that I cannot have problems like:
objects cataloged but deleted from Zope and a lot others. The hidden catalog
will index only objects that I want to search with it. These objects know to
catalog, recatalog or uncatalog automatically(how? very easy, overwrite
manage_afterAdd for catalog object when is created, manage_beforeDelete for
uncatalog object when is deleted).
Using this hidden catalog object the performance is increased, because it
handles only my product objects. When the product is delivered, the catalog
is configured automatically (all the indexes and metadata are present), no
need for the user to do any additional settings.
Let's suppose you build your folderish product based on a catalog object in
the ROOT. What happens if the somebody index objects other than I need? Or
worse, deletes the catalog object? The same problem if I put the catalog
object in my folderish product.
Another thing: I need certains indexes for my catalog, not all the indexes
that could be present in a catalog object in ROOT.
Anyway, my product is totally independent of other Zope objects.
> return [brain.getObject() for brain in self.__catalog(p_criteria)]
Looks nicer indeed. I will give it a try.
Dragos
> Max M wrote:
>
> > Dragos Chirila wrote:
> >
> >> Hi
> >>
> >> I am doing something similarly.
> >>
> >> def __searchCatalog(self, p_criteria):
> >> """Search catalog"""
> >> return self.__catalog(p_criteria)
> >>
> >> This returns a list of mybrains objects.
> >>
> >> def __getFoundObjects(self, p_list):
> >> """gets objects from catalog results"""
> >> return map(self.__catalog.getobject, map(getattr, p_list,
> >> ('data_record_id_',)*len(p_list)))
> >>
> >> It gets a list of mybrains objects and returns a list of zope objects.
> >
> > Hmm! I think that is a questionable approach.
>
> Indeed, yuk! Don't really know why you're hiding your catalog away in
__catalog.
> Why not just make your code ObjectManager or Folderish and put your
catalog in
> there?
>
> As for "getting found objects":
>
> return [brain.getObject() for brain in self.__catalog(p_criteria)]
>
> ...seems a LOT nicer to me.
>
> Chris
>
> --
> Simplistix - Content Management, Zope & Python Consulting
> - http://www.simplistix.co.uk
>
>
More information about the Zope
mailing list