[Zope3-checkins] CVS: Zope3/src/zope/index/field - index.py:1.3
Andreas Jung
andreas@andreas-jung.com
Tue, 15 Jul 2003 13:56:05 -0400
Update of /cvs-repository/Zope3/src/zope/index/field
In directory cvs.zope.org:/tmp/cvs-serv31123
Modified Files:
index.py
Log Message:
added new attr _num_docs for efficient document counting
=== Zope3/src/zope/index/field/index.py 1.2 => 1.3 ===
--- Zope3/src/zope/index/field/index.py:1.2 Mon Jul 14 04:31:24 2003
+++ Zope3/src/zope/index/field/index.py Tue Jul 15 13:56:00 2003
@@ -19,6 +19,7 @@
from zodb.btrees.IOBTree import IOBTree
from zodb.btrees.OOBTree import OOBTree
from zodb.btrees.IIBTree import IITreeSet, IISet, union
+from zodb.btrees.Length import Length
from types import ListType, TupleType
from zope.interface import implements
@@ -40,10 +41,11 @@
self._fwd_index = OOBTree()
# The reverse index maps a docid to its index value
self._rev_index = IOBTree()
+ self._num_docs = Length(0)
def documentCount(self):
"""See interface IStatistics"""
- return len(self._rev_index)
+ return self._num_docs()
def wordCount(self):
"""See interface IStatistics"""
@@ -74,6 +76,7 @@
del self._fwd_index[value]
except KeyError:
pass
+ self._num_docs.change(-1)
def search(self, values):
"See interface ISimpleQuerying"
@@ -111,6 +114,7 @@
if not self._fwd_index.has_key(value):
self._fwd_index[value] = IITreeSet()
self._fwd_index[value].insert(docid)
+ self._num_docs.change(1)
def _insert_reverse(self, docid, value):
"""Insert into reverse index."""