[Zope-dev] Wildcards in TextIndex query. Do they work?

Erik Enge erik@thingamy.net
Wed, 30 May 2001 11:00:29 +0200 (CEST)


On Wed, 30 May 2001, Erik Enge wrote:

> I'm going bug hunting...

I'm back :)

I think I found the bug.  In lib/python/SearchIndex/GlobbingLexicon.py in
the query_hook() method.  It seems to say that: "if I can't find a '*' or
a '?' in the word, then go to else-clause", where the else-clause says
sodd off.

Since it iterates over the query, 'word' is actually a list if you use
parens in your query, and you won't find any wildcards there.  I think.

Add a dash of recursiveness, and it seems to be solved (for me):

    def erik_hook(self, q):
        "doc string"
        words = []
        for w in q:
            if ( (self.multi_wc in w) or
                 (self.single_wc in w) ):
                wids = self.get(w)
                for wid in wids:
                    if words:
                        words.append(Or)
                    words.append(wid)
            else:
                words.append(self.erik_hook(w))
        return words or ['']

    def query_hook(self, q):
        """expand wildcards"""
        words = []
        for w in q:
            if ( (self.multi_wc in w) or
                 (self.single_wc in w) ):
                wids = self.get(w)
                for wid in wids:
                    if words:
                        words.append(Or)
                    words.append(wid)
            else:
                words.append(self.erik_hook(w))

Not really tested, but it seems to work.  This might have been resolved in
CVS, I don't know, should I post it as a bug?