Commit 8eb5e8d3 authored by Chris McDonough's avatar Chris McDonough

Merging ZCatalog keyerror fixes into trunk.

parent af746749
......@@ -96,6 +96,7 @@ from MultiMapping import MultiMapping
from string import lower
import Record
from Missing import MV
from zLOG import LOG, ERROR
from Lazy import LazyMap, LazyFilter, LazyCat
......@@ -174,6 +175,9 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if brains is not None:
self._v_brains = brains
self.updateBrains()
def updateBrains(self):
self.useBrains(self._v_brains)
def __getitem__(self, index, ttype=type(())):
......@@ -200,7 +204,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
""" initialize your brains. This method is called when the
catalog is first activated (from the persistent storage) """
Persistent.__setstate__(self, state)
self.useBrains(self._v_brains)
self.updateBrains()
if not hasattr(self, 'lexicon'):
self.lexicon = Lexicon()
......@@ -262,7 +266,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self.schema = schema
# new column? update the brain
self.useBrains(self._v_brains)
self.updateBrains()
self.__changed__(1) #why?
......@@ -274,6 +278,8 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
_index = names.index(name)
if not self.schema.has_key(name):
LOG('Catalog', ERROR, ('delColumn attempted to delete '
'nonexistent column %s.' % str(name)))
return
names.remove(name)
......@@ -288,7 +294,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
self.names = tuple(names)
# update the brain
self.useBrains(self._v_brains)
self.updateBrains()
# remove the column value from each record
for key in self.data.keys():
......@@ -372,6 +378,9 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if hasattr(x, 'index_object'):
blah = x.index_object(i, object, threshold)
total = total + blah
else:
LOG('Catalog', ERROR, ('catalogObject was passed '
'bad index object %s.' % str(x)))
self.data = data
......@@ -405,9 +414,16 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
try:
del btree[rid]
except KeyError:
pass
LOG('Catalog', ERROR, ('uncatalogObject unsuccessfully '
'attempted to delete rid %s '
'from paths or data btree.' % rid))
del uids[uid]
self.data = data
else:
LOG('Catalog', ERROR, ('uncatalogObject unsuccessfully '
'attempted to uncatalog an object '
'with a uid of %s. ' % rid))
def clear(self):
""" clear catalog """
......
......@@ -84,7 +84,7 @@
##############################################################################
"""Simple column indices"""
__version__='$Revision: 1.12 $'[11:-2]
__version__='$Revision: 1.13 $'[11:-2]
from Globals import Persistent
from Acquisition import Implicit
......@@ -94,6 +94,7 @@ from intSet import intSet
import operator
from Missing import MV
import string, pdb
from zLOG import LOG, ERROR
ListType=type([])
StringType=type('s')
......@@ -193,11 +194,20 @@ class UnIndex(Persistent, Implicit):
k = unindex.get(i, None)
if k is None:
LOG('UnIndex', ERROR, ('unindex_object couldn\'t unindex '
'document %s. This should not happen.'
% str(i)))
return None
set = index.get(k, None)
if set is not None:
try: set.remove(i)
except: pass
LOG('UnIndex', ERROR, ('unindex_object tried to retrieve set %s'
'from index %s but couldn\'t. This '
'should not happen.' % (repr(set), str(k))))
try:
set.remove(i)
except:
LOG('UnIndex', ERROR, ('unindex_object could not remove '
'integer id %s from index.' % str(k)))
del unindex[i]
self._index = index
......
from UnIndex import UnIndex, MV, intSet
from types import ListType, TupleType
from zLOG import LOG, ERROR
class UnKeywordIndex(UnIndex):
......@@ -50,12 +51,16 @@ class UnKeywordIndex(UnIndex):
kws = unindex.get(i, None)
if kws is None:
return None
LOG('UnKeywordIndex', ERROR,('unindex_object was called with bad '
'integer id' % str(i)))
for kw in kws:
set = index.get(kw, None)
if set is not None: set.remove(i)
if set is not None:
set.remove(i)
else:
LOG('UnKeywordIndex', ERROR, ('unindex_object could not '
'remove %s from set'
% str(i)))
del unindex[i]
self._index = index
......
......@@ -92,7 +92,7 @@ is no longer known.
"""
__version__='$Revision: 1.24 $'[11:-2]
__version__='$Revision: 1.25 $'[11:-2]
from Globals import Persistent
import BTree, IIBTree, IOBTree, OIBTree
......@@ -106,7 +106,7 @@ import operator
from Splitter import Splitter
from string import strip
import string, regex, regsub, ts_regex
from zLOG import LOG, ERROR
from Lexicon import Lexicon, stop_word_dict
......@@ -299,7 +299,9 @@ class UnTextIndex(Persistent, Implicit):
index[word_id] = r
unindex[i].append(word_id)
else: r[i] = score
else:
r[i] = score
unindex[i].append(word_id)
else:
index[word_id] = i, score
unindex[i].append(word_id)
......@@ -314,7 +316,6 @@ class UnTextIndex(Persistent, Implicit):
## return the number of words you indexed
return times
def unindex_object(self, i, tt=type(()) ):
""" carefully unindex document with integer id 'i' from the text
index and do not fail if it does not exist """
......@@ -330,11 +331,12 @@ class UnTextIndex(Persistent, Implicit):
try:
del index[n][i]
except (KeyError, IndexError, TypeError):
pass
LOG('UnTextIndex', PROBLEM,
'unindex_object tried to unindex nonexistent'
' document %s' % str(i))
del unindex[i]
self._index = index
self._unindex = unindex
def __getitem__(self, word):
"""Return an InvertedIndex-style result "list"
......
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