Commit 6afaa83e authored by Ken Manheimer's avatar Ken Manheimer

Fixes from Anthony Baxter for some serious ZCatalog bugs. From

Anthony's collector submission:

Title:  current cvs zcatalog lexicon/vocab support is broken

At: http://classic.zope.org:8080/Collector/Collector/1071/sview

Submitter:  Anthony Baxter

Description:  The current CVS version of ZCatalog has a couple of
              nasty bugs in it.

First off, the standard Lexicon uses a variable 'self.counter',
without ever initialising it. Oops.

Secondly, Catalog handles the default Lexicon inconsistently. In the
case of a lexicon being provided, it stores the name as self.lexicon,
otherwise it stores a Lexicon _object_ as self.lexicon. Later on, it
tries to do a getattr with the lexicon object as the second arg.

The first bug utterly breaks non-globbing Lexicons. The second bug
breaks textindexes that don't provide a lexicon at creation time.

A patch for both follows.  [Rather, this checkin commits both.]  Note
that the patch tries to handle gracefully existing Catalogs and
Lexicons that might be broken.
parent 249c3c2b
...@@ -117,6 +117,7 @@ class Lexicon(Persistent, Implicit): ...@@ -117,6 +117,7 @@ class Lexicon(Persistent, Implicit):
def __init__(self): def __init__(self):
self._lexicon = OIBTree() self._lexicon = OIBTree()
self.counter = 0
def set(self, word): def set(self, word):
""" return the word id of 'word' """ """ return the word id of 'word' """
...@@ -125,6 +126,8 @@ class Lexicon(Persistent, Implicit): ...@@ -125,6 +126,8 @@ class Lexicon(Persistent, Implicit):
return self._lexicon[word] return self._lexicon[word]
else: else:
if not hasattr(self, 'counter'):
self.counter = 0
self._lexicon[intern(word)] = self.counter self._lexicon[intern(word)] = self.counter
self.counter = self.counter + 1 self.counter = self.counter + 1
return self.counter - 1 return self.counter - 1
......
...@@ -92,7 +92,7 @@ is no longer known. ...@@ -92,7 +92,7 @@ is no longer known.
""" """
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
from Globals import Persistent from Globals import Persistent
import BTree, IIBTree, IOBTree, OIBTree import BTree, IIBTree, IOBTree, OIBTree
...@@ -172,7 +172,10 @@ class UnTextIndex(Persistent, Implicit): ...@@ -172,7 +172,10 @@ class UnTextIndex(Persistent, Implicit):
Zope. I don't think indexes were ever intended to participate Zope. I don't think indexes were ever intended to participate
in this way, but I don't see too much of a problem with it. in this way, but I don't see too much of a problem with it.
""" """
vocab = getattr(self, vocab_id) if type(vocab_id) is not type(""):
vocab = vocab_id
else:
vocab = getattr(self, vocab_id)
return vocab.lexicon return vocab.lexicon
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment