[Zope3-checkins] CVS: Zope3/lib/python/Zope/TextIndex - BaseIndex.py:1.2 IIndex.py:1.3 ILexicon.py:1.2 Lexicon.py:1.3 TextIndexWrapper.py:1.4

Guido van Rossum guido@python.org
Wed, 4 Dec 2002 13:41:57 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv2196

Modified Files:
	BaseIndex.py IIndex.py ILexicon.py Lexicon.py 
	TextIndexWrapper.py 
Log Message:
Rename length() to wordCount() (both on index and on lexicon).
Add documentCount() to index.

=== Zope3/lib/python/Zope/TextIndex/BaseIndex.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/TextIndex/BaseIndex.py:1.1	Tue Dec  3 09:28:15 2002
+++ Zope3/lib/python/Zope/TextIndex/BaseIndex.py	Wed Dec  4 13:41:56 2002
@@ -83,13 +83,17 @@
         self._docwords = IOBTree()
 
         # Use a BTree length for efficient length computation w/o conflicts
-        self.length = Length.Length()
+        self.wordCount = Length.Length()
 
-    def length(self):
+    def wordCount(self):
         """Return the number of words in the index."""
         # This is overridden per instance
         return len(self._wordinfo)
 
+    def documentCount(self):
+        """Return the number of documents in the index."""
+        return len(self.index._docweight)
+
     def get_words(self, docid):
         """Return a list of the wordids for a given docid."""
         # Note this is overridden in the instance
@@ -245,7 +249,7 @@
         doc2score = self._wordinfo.get(wid)
         if doc2score is None:
             doc2score = {}
-            self.length.change(1)
+            self.wordCount.change(1)
         else:
             # _add_wordinfo() is called for each update.  If the map
             # size exceeds the DICT_CUTOFF, convert to an IIBTree.
@@ -280,7 +284,7 @@
                 doc2score = IIBTree(doc2score)
             doc2score[docid] = weight
             self._wordinfo[wid] = doc2score # not redundant:  Persistency!
-        self.length.change(new_word_count)
+        self.wordCount.change(new_word_count)
 
 
     def _del_wordinfo(self, wid, docid):
@@ -289,7 +293,7 @@
         numdocs = len(doc2score)
         if numdocs == 0:
             del self._wordinfo[wid]
-            self.length.change(-1)
+            self.wordCount.change(-1)
             return
         if numdocs == self.DICT_CUTOFF:
             new = {}


=== Zope3/lib/python/Zope/TextIndex/IIndex.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/TextIndex/IIndex.py:1.2	Wed Dec  4 03:08:38 2002
+++ Zope3/lib/python/Zope/TextIndex/IIndex.py	Wed Dec  4 13:41:56 2002
@@ -19,9 +19,11 @@
 class IIndex(Interface):
     """Interface for an Index."""
 
-    def length():
+    def wordCount():
         """Return the number of words in the index."""
-        # Why not the number of docs?
+
+    def documentCount():
+        """Return the number of documents in the index."""
 
     def get_words(docid):
         """Return a list of wordids for the given docid."""


=== Zope3/lib/python/Zope/TextIndex/ILexicon.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/TextIndex/ILexicon.py:1.1	Tue Dec  3 09:28:15 2002
+++ Zope3/lib/python/Zope/TextIndex/ILexicon.py	Wed Dec  4 13:41:56 2002
@@ -46,8 +46,8 @@
         pattern.
         """
 
-    def length():
-        """Return the number of unique term in the lexicon."""
+    def wordCount():
+        """Return the number of unique terms in the lexicon."""
 
     def get_word(wid):
         """Return the word for the given word id.


=== Zope3/lib/python/Zope/TextIndex/Lexicon.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/TextIndex/Lexicon.py:1.2	Wed Dec  4 03:10:11 2002
+++ Zope3/lib/python/Zope/TextIndex/Lexicon.py	Wed Dec  4 13:41:56 2002
@@ -44,7 +44,7 @@
         self._nbytes = 0 # Number of bytes indexed (at start of pipeline)
         self._nwords = 0 # Number of words indexed (after pipeline)
 
-    def length(self):
+    def wordCount(self):
         """Return the number of unique terms in the lexicon."""
         return self._nextwid - 1
 


=== Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py:1.3	Wed Dec  4 12:11:01 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py	Wed Dec  4 13:41:56 2002
@@ -75,8 +75,9 @@
     # Methods implementing IStatistics
 
     def documentCount(self):
-        # Use _docweight because it is (relatively) small
-        return len(self.index._docweight)
+        """Return the number of documents in the index."""
+        return self.index.documentCount()
 
     def wordCount(self):
-        return self.index.length()
+        """Return the number of words in the index."""
+        return self.index.documentCount()