Commit 8e881bab authored by Tres Seaver's avatar Tres Seaver

Document PathIndex.insertEntry as an API for subclasses; test accordingly.

parent 8ee48fd8
...@@ -226,18 +226,11 @@ class PathIndex(Persistent, SimpleItem): ...@@ -226,18 +226,11 @@ class PathIndex(Persistent, SimpleItem):
""" """
return self._unindex return self._unindex
# Helper methods # IPathIndex implementation.
def insertEntry(self, comp, id, level): def insertEntry(self, comp, id, level):
""" Insert an entry. """ See IPathIndex
'comp' is an individual path component
'id' is the docid
.level'is the level of the component inside the path
""" """
if not self._index.has_key(comp): if not self._index.has_key(comp):
self._index[comp] = IOBTree() self._index[comp] = IOBTree()
...@@ -248,6 +241,8 @@ class PathIndex(Persistent, SimpleItem): ...@@ -248,6 +241,8 @@ class PathIndex(Persistent, SimpleItem):
if level > self._depth: if level > self._depth:
self._depth = level self._depth = level
# Helper methods
def _search(self, path, default_level=0): def _search(self, path, default_level=0):
""" Perform the actual search. """ Perform the actual search.
......
...@@ -456,6 +456,42 @@ class PathIndexTests(unittest.TestCase): ...@@ -456,6 +456,42 @@ class PathIndexTests(unittest.TestCase):
self.assertEqual(dict(index.documentToKeyMap()), self.assertEqual(dict(index.documentToKeyMap()),
dict([(k, v.path) for k, v in DUMMIES.items()])) dict([(k, v.path) for k, v in DUMMIES.items()]))
def test_insertEntry_empty_depth_0(self):
index = self._makeOne()
index.insertEntry('xx', 123, level=0)
self.assertEqual(index._depth, 0)
self.assertEqual(len(index._index), 1)
self.assertEqual(list(index._index['xx'][0]), [123])
# insertEntry oesn't update the length or the reverse index.
self.assertEqual(len(index), 0)
self.assertEqual(len(index._unindex), 0)
self.assertEqual(index._length(), 0)
def test_insertEntry_empty_depth_1(self):
index = self._makeOne()
index.insertEntry('xx', 123, level=0)
index.insertEntry('yy', 123, level=1)
self.assertEqual(index._depth, 1)
self.assertEqual(len(index._index), 2)
self.assertEqual(list(index._index['xx'][0]), [123])
self.assertEqual(list(index._index['yy'][1]), [123])
def test_insertEntry_multiple(self):
index = self._makeOne()
index.insertEntry('xx', 123, level=0)
index.insertEntry('yy', 123, level=1)
index.insertEntry('aa', 456, level=0)
index.insertEntry('bb', 456, level=1)
index.insertEntry('cc', 456, level=2)
self.assertEqual(index._depth, 2)
self.assertEqual(len(index._index), 5)
self.assertEqual(list(index._index['xx'][0]), [123])
self.assertEqual(list(index._index['yy'][1]), [123])
self.assertEqual(list(index._index['aa'][0]), [456])
self.assertEqual(list(index._index['bb'][1]), [456])
self.assertEqual(list(index._index['cc'][2]), [456])
def test__search_empty_index_string_query(self): def test__search_empty_index_string_query(self):
index = self._makeOne() index = self._makeOne()
self.assertEqual(list(index._search('/xxx')), []) self.assertEqual(list(index._search('/xxx')), [])
......
...@@ -157,6 +157,18 @@ class IPathIndex(Interface): ...@@ -157,6 +157,18 @@ class IPathIndex(Interface):
- the value is a mapping 'level of the path component' to - the value is a mapping 'level of the path component' to
'all docids with this path component on this level' 'all docids with this path component on this level'
""" """
def insertEntry(comp, id, level):
""" Insert an entry.
This method is intended for use by subclasses: it is not
a normal API for the index.
'comp' is an individual path component
'id' is the docid
.level'is the level of the component inside the path
"""
class IFilteredSet(Interface): class IFilteredSet(Interface):
......
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