Commit 73e063c3 authored by Casey Duncan's avatar Casey Duncan

Added has_doc method to Index API.

Allows clean implementation of ZCTextIndex's unindex_object method so that it plays better with ZCatalog's unindex behavior.
parent 169047b5
......@@ -150,6 +150,9 @@ class BaseIndex(Persistent):
# becomes the value of _docweight[docid].
raise NotImplementedError
def has_doc(self, docid):
return self._docwords.has_key(docid)
# A subclass may wish to extend or override this.
def unindex_doc(self, docid):
for wid in unique(self.get_words(docid)):
......
......@@ -66,3 +66,6 @@ class IIndex(Interface.Base):
def unindex_doc(docid):
"XXX"
def has_doc(docid):
"""Returns true if docid is an id of a document in the index"""
......@@ -118,6 +118,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
return count
def unindex_object(self, docid):
if self.index.has_doc(docid):
self.index.unindex_doc(docid)
self._p_changed = 1 # XXX
......
......@@ -29,7 +29,9 @@ class IndexTest(TestCase):
def test_index_document(self, DOCID=1):
doc = "simple document contains five words"
self.assert_(not self.index.has_doc(DOCID))
self.index.index_doc(DOCID, doc)
self.assert_(self.index.has_doc(DOCID))
self.assert_(self.index._docweight[DOCID])
self.assertEqual(len(self.index._docweight), 1)
self.assertEqual(len(self.index._wordinfo), 5)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment