[Zope-CVS] CVS: Products/ZCTextIndex - Index.py:1.1.2.6
Fred L. Drake, Jr.
fdrake@acm.org
Wed, 1 May 2002 11:27:21 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv29786/lib/python/Products/ZCTextIndex
Modified Files:
Tag: TextIndexDS9-branch
Index.py
Log Message:
Refacter query_weight() to re-use the algorithm in _get_frequencies().
Add a comment explaining frequency().
=== Products/ZCTextIndex/Index.py 1.1.2.5 => 1.1.2.6 ===
def query_weight(self, terms):
- d = {}
+ wids = []
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))
+ wids += self._lexicon.termToWordIds(term)
+ return self._get_frequencies(wids)[1]
def _get_object_text(self, obj):
x = getattr(obj, self._fieldname)
@@ -121,6 +116,7 @@
self._wordinfo[wid] = oldwordfreq - 1, map
def frequency(count):
+ # XXX the logarithm calculations need to be added here
return count
def invfreq(N, ft):