[Zope-CVS] CVS: Products/ZCTextIndex - Index.py:1.1.2.3

Jeremy Hylton jeremy@zope.com
Tue, 30 Apr 2002 19:00:23 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	Index.py 
Log Message:
An untested implemented of query_weight().


=== Products/ZCTextIndex/Index.py 1.1.2.2 => 1.1.2.3 ===
         return result
 
+    def query_weight(self, terms):
+        d = {}
+        for term in terms:
+            wids = self._lexicon.termToWordIds(term)
+            for wid in wids:
+                d[wid] = d.get(wid, 0) + 1
+        Wsquares = 0
+        for wid, count in d.items():
+            Wsquares += frequency(count) ** 2
+        return int(math.sqrt(Wsquares))
+
     def _get_object_text(self, obj):
         x = getattr(obj, self._fieldname)
         if callable(x):