[Zope-CVS] CVS: Products/ZCTextIndex - Index.py:1.1.2.32
Jeremy Hylton
jeremy@zope.com
Mon, 6 May 2002 13:01:24 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv2072
Modified Files:
Tag: TextIndexDS9-branch
Index.py
Log Message:
Refactor storage of undo info; add two helper methods.
The refactoring affects a bunch of the tests, which depended on
the implementation details of _docwords.
When a particular wordinfo map gets small, switch back to a dict.
Add docstring to length() method of Index.
=== Products/ZCTextIndex/Index.py 1.1.2.31 => 1.1.2.32 ===
def length(self):
- return len(self._docweight)
+ """Return the number of documents in the index."""
+ return len(self._docwords)
# Most of the computation for computing a relevance score for the
# document occurs in the search() method. The code currently
@@ -93,11 +94,10 @@
for i in range(len(uniqwids)):
self._add_wordinfo(uniqwids[i], freqs[i], docid)
self._docweight[docid] = docweight
- self._docwords[docid] = IISet(uniqwids)
+ self._add_undoinfo(docid, uniqwids)
def unindex_doc(self, docid):
- wids = self._docwords[docid]
- for wid in wids:
+ for wid in self._get_undoinfo(docid):
self._del_wordinfo(wid, docid)
del self._docwords[docid]
del self._docweight[docid]
@@ -197,6 +197,19 @@
del map[docid]
if len(map) == 0:
del self._wordinfo[wid]
+ return
+ if len(map) == self.DICT_CUTOFF:
+ new = {}
+ for k, v in map.items():
+ new[k] = v
+ map = new
+ self._wordinfo[wid] = map
+
+ def _add_undoinfo(self, docid, wids):
+ self._docwords[docid] = wids
+
+ def _get_undoinfo(self, docid):
+ return self._docwords[docid]
# The rest are helper methods to support unit tests