Commit 297bdd33 authored by seb's avatar seb

- fix for #703 merged from 2.6 branch

parent 9154b5a5
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
############################################################################## ##############################################################################
__version__ = '$Id: PathIndex.py,v 1.28 2002/10/03 13:42:22 andreasjung Exp $' __version__ = '$Id: PathIndex.py,v 1.29 2002/11/28 13:03:11 beacon Exp $'
from Products.PluginIndexes import PluggableIndex from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.util import parseIndexRequest from Products.PluginIndexes.common.util import parseIndexRequest
...@@ -23,6 +23,7 @@ from BTrees.IOBTree import IOBTree ...@@ -23,6 +23,7 @@ from BTrees.IOBTree import IOBTree
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
from BTrees.IIBTree import IISet, intersection, union from BTrees.IIBTree import IISet, intersection, union
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from zLOG import LOG, ERROR
from types import StringType, ListType, TupleType from types import StringType, ListType, TupleType
import re, warnings import re, warnings
...@@ -141,21 +142,30 @@ class PathIndex(Persistent, Implicit, SimpleItem): ...@@ -141,21 +142,30 @@ class PathIndex(Persistent, Implicit, SimpleItem):
""" hook for (Z)Catalog """ """ hook for (Z)Catalog """
if not self._unindex.has_key(documentId): if not self._unindex.has_key(documentId):
LOG(self.__class__.__name__, ERROR,
'Attempt to unindex nonexistent document'
' with id %s' % documentId)
return return
path = self._unindex[documentId] path = self._unindex[documentId]
comps = path.split('/') comps = path.split('/')
for level in range(len(comps[1:])): for level in range(len(comps[1:])):
comp = comps[level+1] comp = comps[level+1]
self._index[comp][level].remove(documentId) try:
self._index[comp][level].remove(documentId)
if len(self._index[comp][level])==0:
del self._index[comp][level]
if len(self._index[comp][level])==0: if len(self._index[comp])==0:
del self._index[comp][level] del self._index[comp]
except KeyError:
LOG(self.__class__.__name__, ERROR,
'Attempt to unindex document'
' with id %s failed' % documentId)
if len(self._index[comp])==0:
del self._index[comp]
del self._unindex[documentId] del self._unindex[documentId]
...@@ -209,14 +219,13 @@ class PathIndex(Persistent, Implicit, SimpleItem): ...@@ -209,14 +219,13 @@ class PathIndex(Persistent, Implicit, SimpleItem):
results = [] results = []
for i in range(len(comps)): for i in range(len(comps)):
comp = comps[i] comp = comps[i]
if not self._index.has_key(comp): return IISet() if not self._index.has_key(comp): return IISet()
if not self._index[comp].has_key(level+i): return IISet() if not self._index[comp].has_key(level+i): return IISet()
results.append( self._index[comp][level+i] ) results.append( self._index[comp][level+i] )
res = results[0] res = results[0]
for i in range(1,len(results)): for i in range(1,len(results)):
......
...@@ -78,6 +78,38 @@ class TestCase( unittest.TestCase ): ...@@ -78,6 +78,38 @@ class TestCase( unittest.TestCase ):
assert len(self._index._index)==0 assert len(self._index._index)==0
assert len(self._index._unindex)==0 assert len(self._index._unindex)==0
def testUnIndexError(self):
self._populateIndex()
# this should not raise an error
self._index.unindex_object(-1)
# nor should this
self._index._unindex[1] = "/broken/thing"
self._index.unindex_object(1)
def testRoot(self):
self._populateIndex()
tests = [
("/",0, range(1,19)),
]
for comp,level,results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]:
res = self._index._apply_index(
{"path":{'query':path,"level":level}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
for comp,level,results in tests:
for path in [comp,"/"+comp,"/"+comp+"/"]:
res = self._index._apply_index(
{"path":{'query':( (path,level),)}})
lst = list(res[0].keys())
self.assertEqual(lst,results)
def testRoot(self): def testRoot(self):
......
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