[Zope-CVS] CVS: Products/ZCTextIndex - CosineIndex.py:1.4

Jeremy Hylton jeremy@zope.com
Thu, 16 May 2002 19:17:42 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv450

Modified Files:
	CosineIndex.py 
Log Message:
Try to handle the case where a wid has no wordinfo.

This case can arise when the last occurence of a word is removed, or
when a lexicon is shared across multiple indexes.

XXX Not sure this code is correct, but it might be and the tests pass.
If it's wrong, we need more tests.





=== Products/ZCTextIndex/CosineIndex.py 1.3 => 1.4 ===
         DictType = type({})
         for wid in wids:
-            d2w = self._wordinfo[wid] # maps docid to w(docid, wid)
+            d2w = self._wordinfo.get(wid) # maps docid to w(docid, wid)
+            if d2w is None:
+                # Need a test case to cover this
+                L.append((IIBucket(), scaled_int(1)))
+                continue
             idf = query_term_weight(len(d2w), N)  # this is an unscaled float
             #print "idf = %.3f" % idf
             if isinstance(d2w, DictType):
@@ -165,7 +169,10 @@
         for wid in wids:
             if wid == 0:
                 continue
-            wt = math.log(1.0 + N / len(self._wordinfo[wid]))
+            map = self._wordinfo.get(wid)
+            if map is None:
+                continue
+            wt = math.log(1.0 + N / len(map))
             sum += wt ** 2.0
         return scaled_int(math.sqrt(sum))