[Zope-CVS] CVS: Products/ZCTextIndex - Index.py:1.1.2.7
Fred L. Drake, Jr.
fdrake@acm.org
Wed, 1 May 2002 12:00:32 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv16797
Modified Files:
Tag: TextIndexDS9-branch
Index.py
Log Message:
Simplify data structures: the values in _wordinfo can just be the map; the
number-of-docs-with-word-in-corpus will always be the same as the length
of the map.
=== Products/ZCTextIndex/Index.py 1.1.2.6 => 1.1.2.7 ===
Plugin text index for ZCatalog, with relevance ranking.
-
-Revision information:
-$Id$
"""
import math
@@ -34,7 +31,7 @@
self._lexicon = lexicon
self._fieldname = fieldname
- # wid -> ( word-frequency, { docid -> frequency } )
+ # wid -> { docid -> frequency }
self._wordinfo = IOBTree()
# docid -> W
@@ -66,10 +63,10 @@
result = IIBucket()
N = len(self._docweight)
for wid in wids:
- wordfreq, map = self._wordinfo[wid]
- ft = len(map)
+ map = self._wordinfo[wid]
+ wordfreq = len(map)
for docid, f in map.items():
- w = f * invfreq(N, ft) / self._docweight[docid]
+ w = f * invfreq(N, wordfreq) / self._docweight[docid]
result[docid] = result.get(docid, 0) + w
return result
@@ -100,20 +97,20 @@
def _add_wordinfo(self, wid, f, docid):
try:
- oldwordfreq, map = self._wordinfo[wid]
+ map = self._wordinfo[wid]
except KeyError:
- oldwordfreq = 0
map = IIBTree()
map[docid] = f
- self._wordinfo[wid] = oldwordfreq + 1, map
+ self._wordinfo[wid] = map
def _del_wordinfo(self, wid, docid):
- oldwordfreq, map = self._wordinfo[wid]
- if oldwordfreq == 1:
+ map = self._wordinfo[wid]
+ if len(map) == 1:
+ assert map.has_key(docid)
del self._wordinfo[wid]
return
del map[docid]
- self._wordinfo[wid] = oldwordfreq - 1, map
+ self._wordinfo[wid] = map
def frequency(count):
# XXX the logarithm calculations need to be added here