[Zope-dev] More ZCatalog Stuff.

Toby Dickenson tdickenson@geminidataloggers.com
Tue, 27 Feb 2001 07:49:36 +0000


On Mon, 26 Feb 2001 19:00:58 -0800, "Michael R. Bernstein"
<webmaven@lvcm.com> wrote:

>Toby Dickenson wrote:
>>=20
>> If you are interested in a short-term hack, it is possible implement
>> your own type of index and add it to an existing catalog, without
>> having to modify any of the ZCatalog product.
>
>Ok, how? Please keep in mind that I'm more of a designer and
>integrator than a coder.

Today it requires some development effort....


ZCatalogs are a zopeish wrapper around a zope-neutral catalog object,
which is stored in the _catalog attribute. That leading underscore is
a clue that you shouldnt be using it directly, however you need to in
order to create a custom index. Liek I said, this is a hack.

The main problem is that catalog (and hence ZCatalog) implements a
factory interface where you specify the name of the index type (for
example "TextIndex", and it creates the indexing objects.

I use the function below to:
1. Use a catalogs factory interface to create a KeywordIndex, to
   allow it a chance to raise an exception if anything is wrong.
2. If nothing goes wrong then I assume it is safe to replace
   the standard KeywordIndex with my custom subclass of a
   KeywordIndex.

    def ensure_question_is_indexed(self,question):
        question =3D unicode(question)
        cat =3D self.storage.timeseries_catalog
        index =3D UnTrackingIndex(question)
        if index.id not in cat.indexes():
            # Add and remove a keyword index using
            # the published interface,
            # to allow the catalog a chance to complain.
            cat._catalog.addIndex(index.id,'KeywordIndex')
            cat._catalog.delIndex(index.id)
            # Use the private interface to do the real work
            cat._catalog.indexes[index.id] =3D index
            cat._catalog._p_changed =3D 1

You will need to implement a subclass derived from one of the standard
indexes to provide your custom indexing policy, whatever that is.



Toby Dickenson
tdickenson@geminidataloggers.com