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
......@@ -149,6 +149,9 @@ class BaseIndex(Persistent):
# The wid->weight mappings are fed into _add_wordinfo, and docweight
# 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):
......
......@@ -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,8 +118,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
return count
def unindex_object(self, docid):
self.index.unindex_doc(docid)
self._p_changed = 1 # XXX
if self.index.has_doc(docid):
self.index.unindex_doc(docid)
self._p_changed = 1 # XXX
def _apply_index(self, request, cid=''):
"""Apply query specified by request, a mapping containing the query.
......
......@@ -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