[Zope-Checkins] CVS: Zope2 - PathIndex.py:1.1.2.4

Andreas Jung andreas@dhcp165.digicool.com
Mon, 7 May 2001 11:21:46 -0400


Update of /cvs-repository/Zope2/lib/python/SearchIndex
In directory yetix:/work/sandboxes/ajung-pathindex/lib/python/SearchIndex

Modified Files:
      Tag: ajung-pathindex
	PathIndex.py 
Log Message:
now working with ZCatalog



--- Updated File PathIndex.py in package Zope2 --
--- PathIndex.py	2001/05/04 19:16:11	1.1.2.3
+++ PathIndex.py	2001/05/07 15:20:30	1.1.2.4
@@ -85,10 +85,12 @@
 
 from BTrees.OOBTree import OOBTree
 from BTrees.IOBTree import IOBTree
+from BTrees.IIBTree import IISet
 from Persistence import Persistent
 from Acquisition import Implicit
+from types import StringType
 
-import re
+import re,string
 
 class PathIndex(Persistent,Implicit):
 
@@ -112,13 +114,22 @@
         else:                         self._unindex[v] = [k]
 
 
-    def index_object(self, documentId, path,obj ):
+    def index_object(self, documentId, obj ,threshold):
 
+        try:
+            path = obj.getPhysicalPath()
+        except:
+            return 0
+
+        path = '/'+ '/'.join(path[1:])
+
         comps = self.splitPath(path,obj)
 
         for i in range(1,len(comps)+1):
             comp = comps[:i] 
             self.insertEntry( comp,documentId)
+
+        return 1
     
 
     def unindex_object(self,id):
@@ -162,6 +173,8 @@
     
         return dict.keys()
 
+    def __len__(self):
+        return len(self._index)
 
 
     def keys(self):   
@@ -179,4 +192,25 @@
         for k in self._index.items(): items.append(k)
         return items
 
+    def _apply_index(self, request, cid=''): 
+
+        if request.has_key(self.id):
+            keys = request[self.id]
+        else:
+            return None
+
+        if type(keys) is StringType:
+            if not keys or not string.strip(keys):
+                return None
+            keys = [keys]
+            
+
+        res = IISet()
+        for k in keys:
+            rows = self.search(k,-1)
+            for r in rows:
+                res.insert(r)
+   
+        return res, (self.id,)
+