[Zope] ZCatalog in a ZClass
michel@digicool.com
michel@digicool.com
11 Jul 1999 23:54:11 -0400
Kevin Dangoor <kid@kendermedia.com> writes:
> I'm starting work on my first ZClasses. I have news story code that
> I am using at http://www.byproducts.com. I am changing it from a system
> using DTML Methods in various Folders, TinyTables and such into
> something that is designed with ZClasses and ZCatalog.
>
> I want to make sure I understand this correctly:
>
> - I am creating an ArticleStorage Product & ZClass that is designed to
> contain and manage Article(s) (another ZClass)
>
> - If I were to put a ZCatalog inside the ArticleStorage ZClass, that
> catalog would contain the information from *all* ArticleStorage
> instances
Nope. It would define that all instances of that ZClass would
instanciate a ZCatalog. Until the ZClass is instanciated, no
ZCatalogs are intanciated.
>
> - Or, if I have the add method of ArticleStorage create the ZCatalog,
> then the catalog would index only that given instance's Articles.
Yep. Note that it is possible for ArticleStorage to also subclass
ZCatalog.
>
> From a design standpoint, does it make more sense to have the catalog
> acquired from somewhere outside the ArticleStorage? That way, if there
> is information in the ArticleStorage and information in other places,
> they can all be conveniently searched via one catalog.
>
This is a good design decision, and is how we are currently using
ZCatalog. It is entirely valid however that your requirements may
lean toward the other architecture.
> The reason I was thinking of putting the catalog inside of the
> ArticleStorage is because there are specific things that need to be
> indexed within the articles for this to work (eg "Category")
>
Note that in your ZCatalog, you can define a whole bunch of attributes
for the Catalog to index, including 'Catagory'. If the Catalog finds
an object (or is told to index an object) that does not have that
attribute, it will politely ignore that fact, continuing to index any
attributes that the object does have that it's looking for. This way,
only objects that have a 'Catagory' attribute are subject to a search
based on that attribute. It is also handy to index meta_type for
these reasons (which ZCatalog does by default) so that you can
hardwire a particular search to just return objects of a certain
type, meaning that if you had to different object types that defined
Catagory, you could pick between them in your results.
Also, a tip to *all* ZClass developers... try to make sure your
metatypes are unique. It would be very tempting in your case to give
your Article objects the meta_type 'Article' but it might be a good
idea to uniqufy them with some sort of prefix, such as the application
name. For example, if you had a Product named 'ABook' which contain a
ZClass named 'ABook' whose instances could in turn contain instances
of the class 'ZBookChapter' instead of 'Chapter'. This is because
meta_types are global.
-Michel
> Opinions?
>
> Thanks,
> Kevin
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )