[Zope-dev] More ZCatalog Stuff.

Toby Dickenson tdickenson@geminidataloggers.com
Tue, 27 Feb 2001 15:11:55 -0000


> I am assuming that the code you provided goes into a
> manage_addCustomIndex method that is part of a CustomIndex
> Python Product.

hehehehe, nothing so general-purpose as that ;-)
 
> > You will need to implement a subclass derived from one of 
> the standard
> > indexes to provide your custom indexing policy, whatever that is.
> 
> Can you provide the code for your custom KeywordIndex, so I
> have a starting point? I realize yours subclasses a
> KeywordIndex, and I probably need to subclass a TextIndex,
> but it would still probably help. I can integrate and hack
> on other peoples code better than I can write my own from
> scratch.


from SearchIndex.UnKeywordIndex import UnKeywordIndex, MV, intSet
from types import ListType, TupleType

class UnTrackingIndex(UnKeywordIndex):

    meta_type = 'Tracking Properties Index'
    
    """Like a Keyword Index, only it indexes tracking properties
    """

    def __init__(self,question):
        id = 'tracking_'+unicode(question).encode('unicode-escape')
        self.question = question
        UnKeywordIndex.__init__(self,id)

    def index_object(self, i, obj, threshold=None):
        """ index an object 'obj' with integer id 'i'"""

        index = self._index
        unindex = self._unindex

        try:
            kws = obj.tracking_answers(self.question)
            if type(kws) not in [type([]),type(())]:
                raise ValueError('Indexing a tracking property set of
inappropriate type %r' % type(kws))
        except:
            kws = (MV,)
        
        # index each item in the sequence
        for kw in kws:
            set = index.get(kw)
            if set is None:
                index[kw] = set = intSet()
            set.insert(i)

        unindex[i] = tuple(kws)

        self._index = index
        self._unindex = unindex

        return 1