[Zope3-checkins] CVS: Zope3/lib/python/Zope/TextIndex - TextIndexInterfaces.py:1.3 TextIndexWrapper.py:1.3
Guido van Rossum
guido@python.org
Wed, 4 Dec 2002 12:11:01 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv16321
Modified Files:
TextIndexInterfaces.py TextIndexWrapper.py
Log Message:
Add IStatistics interface, to get document count and word count.
(The implementations need to be fixed; the BaseIndex class really needs to
provide these, and length() needs to be renamed. Later.)
=== Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py:1.2 Wed Dec 4 05:25:41 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py Wed Dec 4 12:11:01 2002
@@ -58,3 +58,11 @@
The matches list represents the requested batch. The ranks
are floats between 0 and 1 (inclusive).
"""
+
+class IStatistics(Interface):
+
+ def documentCount():
+ """Return the number of documents currently indexed."""
+
+ def wordCount():
+ """Return the number of words currently indexed."""
=== Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py:1.2 Wed Dec 4 05:25:41 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py Wed Dec 4 12:11:01 2002
@@ -20,17 +20,18 @@
from Persistence import Persistent
-from TextIndexInterfaces import IInjection, IQuerying
-
from Zope.TextIndex.OkapiIndex import OkapiIndex
from Zope.TextIndex.Lexicon import Lexicon
from Zope.TextIndex.Lexicon import Splitter, CaseNormalizer, StopWordRemover
from Zope.TextIndex.QueryParser import QueryParser
from Zope.TextIndex.NBest import NBest
+from Zope.TextIndex.TextIndexInterfaces import \
+ IInjection, IQuerying, IStatistics
+
class TextIndexWrapper(Persistent):
- __implements__ = (IInjection, IQuerying)
+ __implements__ = (IInjection, IQuerying, IStatistics)
def __init__(self, lexicon=None, index=None):
"""Provisional constructor.
@@ -70,3 +71,12 @@
qw = 1.0 * self.index.query_weight(tree.terms())
batch = [(docid, score/qw) for docid, score in batch]
return batch, len(results)
+
+ # Methods implementing IStatistics
+
+ def documentCount(self):
+ # Use _docweight because it is (relatively) small
+ return len(self.index._docweight)
+
+ def wordCount(self):
+ return self.index.length()