[Zope-Checkins] CVS: Zope2 - PathIndex.py:1.1.2.6
andreas@serenade.digicool.com
andreas@serenade.digicool.com
Tue, 8 May 2001 10:34:39 -0400
Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory serenade.digicool.com:/tmp/cvs-serv7730/lib/python/SearchIndex
Modified Files:
Tag: ajung-pathindex
PathIndex.py
Log Message:
internal code rework
--- Updated File PathIndex.py in package Zope2 --
--- PathIndex.py 2001/05/08 12:34:17 1.1.2.5
+++ PathIndex.py 2001/05/08 14:34:38 1.1.2.6
@@ -96,10 +96,6 @@
""" A path index stores all path components of the physical
path of an object:
- - we split the physical path at "/"
-
- - all slices [0:n] of the result list will be stored in the index
- as key and the documentId as value
"""
meta_type = 'Path Index'
@@ -111,22 +107,31 @@
def clear(self):
""" clear everything """
- self._index = OOBTree()
+
+ self._index = OOBTree()
self._unindex = IOBTree()
- def insertEntry(self,k,v):
+ def insertEntry(self,comp,id,level):
"""
- k is list of path components (generated by splitPath() )
+ k is a path component (generated by splitPath() )
v is the documentId
+ level is the level of the component inside the path
"""
+
+ if self._index.has_key(comp)==0:
+ self._index[comp] = {}
- if self._index.has_key(k): self._index[k].append(v)
- else: self._index[k] = [v]
+ if self._index[comp].has_key(level)==0:
+ self._index[comp][level] = []
- if self._unindex.has_key(v): self._unindex[v].append(k)
- else: self._unindex[v] = [k]
+ self._index[comp][level].append(id)
+ # reverse index
+ if not self._unindex.has_key(id):
+ self._unindex[id] = {}
+ self._unindex[id][comp] = level
+
def index_object(self, documentId, obj ,threshold):
""" hook for (Z)Catalog """
@@ -137,26 +142,26 @@
return 0
path = '/'+ '/'.join(path[1:])
-
comps = self.splitPath(path,obj)
if obj.meta_type != 'Folder':
comps = comps[:-1]
- for i in range(1,len(comps)+1):
- comp = comps[:i]
- self.insertEntry( comp,documentId)
+ for i in range(len(comps)):
+ self.insertEntry( comps[i],documentId,i)
return 1
def unindex_object(self,id):
""" hook for (Z)Catalog """
+
+ for path,level in self._unindex[id].items():
+ self._index[path][level].remove(id)
- for k in self._unindex[id]:
- self._index[k].remove(id)
- if len(self._index[k])==0:
- del self._index[k]
+ if len(self._index[path][level])==0:
+ del self._index[path][level]
+
del self._unindex[id]
@@ -179,28 +184,35 @@
"""
path is a list of path components to be searched
level>=0 starts searching at the given level
- level==-1 searches over all levels
+ level<0 not defined yet
"""
- dict = {}
comps = self.splitPath(path)
-
+ res = []
if level >=0:
- for k in self._index.keys():
- s = k[level:len(comps)+1]
- if s==comps:
- for item in self._index[k]:
- dict[item]=1
+ for i in range(len(comps)):
+
+ comp = comps[i]
+
+ if not self._index.has_key(comp): return []
+ if not self._index[comp].has_key(level+i): return []
+
+ if len(res)>0:
+ for k in res:
+ if not k in self._index[comp][level+i]:
+ res.remove(k)
+
+ else:
+ res.extend(self._index[comp][level+i])
+
+
+ return res
+
else:
- for k in self._index.keys():
- for i in range(len(k)-len(comps)+1):
- s = k[i:i+len(comps)]
- if s==comps:
- for item in self._index[k]:
- dict[item]=1
-
- return dict.keys()
+ pass
+
+ return res
def __len__(self):