[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - TextIndexNG.py:1.2.2.28

Andreas Jung andreas@digicool.com
Tue, 12 Feb 2002 15:30:31 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv11580

Modified Files:
      Tag: ajung-textindexng-branch
	TextIndexNG.py 
Log Message:
first working near search !


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/TextIndexNG.py 1.2.2.27 => 1.2.2.28 ===
 
             debug("Position Map for NEAR:")
-            for k,v in posMap.items(): debug("\t'%s'" % k,":","'%s'" % v)
+            for item in posMap: debug("\t%s" % str(item))
 
-            if self.checkPositionMap( posMap):
+            if len(self.checkPositionMap(posMap,self.nearDistance)) > 0:
                 res_docIds.insert(docId)
 
-        r = ResultSet( docIds,  words)       
+        r = ResultSet( res_docIds,  words)       
         debug("\treturn: ",r)
 
         return r
+
         
-    def checkPositionMap(self, posMap):
+    def checkPositionMap(self, posMap, nearDistance):
         """ check if a PositionMap represents a valid match for
             a near search
         """
 
-        # a posMap is a mapping for word to an IISet() to posititions
-        # of that word inside one document
+        debug('checkPositionMap')
+
+        # a posMap is a list of tuples (word, IISet() ), where
+        # the IISet is a list of posititions of that word inside 
+        # one document
+
+        valid_positions = []
+
+        # determine position list with minimal length
+        min_posLst = None 
+
+        for word,posLst in posMap:
 
-        # to be written
+            if min_posLst:
+                if len(posLst) < len(min_posLst):
+                    min_posLst = posLst
+            else:
+                min_posLst = posLst
 
-        return 1
+        for pos in min_posLst:
+
+            # perform a range search over all position lists
+
+            num = 0        
+            for word,posLst in posMap:
+                keys = posLst.keys( pos-nearDistance, pos+nearDistance)
+
+                if len(keys)>0: num+=1
+
+            if num==len(posMap):
+                valid_positions.append(pos) 
+        
+        return valid_positions
 
 
     # THIS IS A BAD BAD HACK !
@@ -761,7 +789,7 @@
 
         debug('searching positions docid: %s, word: %s' % (docId,words))
 
-        res = OOBTree()
+        res = []
 
         # obtain object from ZCatalog
         # THis is a bad hack !
@@ -774,9 +802,9 @@
         for word in words:
             
             posLst = SP.indexes(word)        
-            res[word] = IISet(posLst)
+            res.append( (word, IISet(posLst)) )
       
-        for k,v in  res.items(): debug(k,':',v)
+        for item in res: debug(item)
 
         return res