[Zope-dev] Q: Specialists, Racks, and ZCatalogs?
Steve Alexander
steve@cat-box.net
Sat, 03 Feb 2001 16:53:04 +0000
Michael Bernstein wrote:
>
> 'BookProduct' product
> *'BookClass' ZClass (inherits from
> _ZClass_for_CatalogAware, _ZClass_for_DataSkin)
Don't derive from CatalogAware when you're also deriving from DataSkin.
Rather than use the CatalogAwareness mechanism to
manually call reindex() when your object changes, you
should use some SkinScript in your Specialist or in your
Customizer to catalog, uncatalog and recatalog on changes.
WHEN OBJECT ADDED CALL
Catalog.catalog_object(self, _.string.join(self.getPhysicalPath(),'/'))
WHEN OBJECT DELETED CALL Catalog.uncatalog_object(_.string.join(self.getPhysicalPath(),'/'))
WHEN OBJECT CHANGED CALL Catalog.uncatalog_object(_.string.join(self.getPhysicalPath(),'/')),
Catalog.catalog_object(self, _.string.join(self.getPhysicalPath(),'/'))
> I'm also not sure it's
> a good or bad idea to place the ZCatalog directly into the
> Specialist.
That's a good idea. The catalog is what the specialist uses to
answer questions from other parts of your application such as
"what instances have baz for the foo property".
So, it should live inside the Specialist, and you should
provide a set of methods in the Specialist that answer
the questions the rest of you application need answered.
> Also, I would like to replace the three indexes I'm
> maintaining on the books with a single text index on a
> computed attribute. I understand that this involves adding a
> SkinScript to the Rack containing something like 'WITH SELF
> COMPUTE AllText=AllTextMethod', but I'm unsure of the
> details. I have a method (AllTextMethod) on the ZClass that
> returns several fields concatenated as a single string,
> which I would like to use as a text index.
You don't need a method for this; do it all with SkinScript like this:
WITH SELF COMPUTE
all_text='%s %s %s' % (title, headline, content)
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net