[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/PathIndex - PathIndex.py:1.28.14.2
Andreas Jung
andreas@andreas-jung.com
Thu, 23 Jan 2003 12:33:32 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/PathIndex
In directory cvs.zope.org:/tmp/cvs-serv17553/PathIndex
Modified Files:
Tag: ajung-oneindex-multipleattributes-branch
PathIndex.py
Log Message:
merge from HEAD
=== Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py 1.28.14.1 => 1.28.14.2 ===
--- Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py:1.28.14.1 Sun Nov 17 06:08:49 2002
+++ Zope/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py Thu Jan 23 12:33:00 2003
@@ -23,6 +23,7 @@
from BTrees.OOBTree import OOBTree
from BTrees.IIBTree import IISet, intersection, union
from OFS.SimpleItem import SimpleItem
+from zLOG import LOG, ERROR
from types import StringType, ListType, TupleType
import re, warnings
@@ -43,7 +44,7 @@
"""
- __implements__ = (PluggableIndex.PluggableIndexInterface,)
+ __implements__ = (PluggableIndex.UniqueValueIndex,)
meta_type="PathIndex"
@@ -141,21 +142,30 @@
""" hook for (Z)Catalog """
if not self._unindex.has_key(documentId):
+ LOG(self.__class__.__name__, ERROR,
+ 'Attempt to unindex nonexistent document'
+ ' with id %s' % documentId)
return
-
+
path = self._unindex[documentId]
comps = path.split('/')
for level in range(len(comps[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:
- del self._index[comp][level]
+ if len(self._index[comp])==0:
+ 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]
@@ -209,14 +219,13 @@
results = []
for i in range(len(comps)):
-
comp = comps[i]
if not self._index.has_key(comp): return IISet()
if not self._index[comp].has_key(level+i): return IISet()
results.append( self._index[comp][level+i] )
-
+
res = results[0]
for i in range(1,len(results)):
@@ -319,6 +328,12 @@
else:
return IISet(), (self.id,)
+ def hasUniqueValuesFor(self, name):
+ """has unique values for column name"""
+ if name == self.id:
+ return 1
+ else:
+ return 0
def uniqueValues(self,name=None,withLength=0):
""" needed to be consistent with the interface """