On Mon, 26 Feb 2001 19:00:58 -0800, "Michael R. Bernstein"
<[EMAIL PROTECTED]> wrote:

>Toby Dickenson wrote:
>> 
>> 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 = unicode(question)
        cat = self.storage.timeseries_catalog
        index = 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] = index
            cat._catalog._p_changed = 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
[EMAIL PROTECTED]

_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to