Skip to content

Commit

Permalink
Complete the implementation of IUniqueValueIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Apr 20, 2019
1 parent affc000 commit 71176da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Products/PluginIndexes/TopicIndex/TopicIndex.py
Expand Up @@ -26,6 +26,7 @@
from Products.PluginIndexes.interfaces import (
IQueryIndex,
ITopicIndex,
IUniqueValueIndex,
)
from Products.PluginIndexes.TopicIndex.FilteredSet import factory
from Products.ZCatalog.query import IndexQuery
Expand All @@ -34,7 +35,7 @@
LOG = getLogger('Zope.TopicIndex')


@implementer(ITopicIndex, IQueryIndex)
@implementer(ITopicIndex, IQueryIndex, IUniqueValueIndex)
class TopicIndex(Persistent, SimpleItem):
"""A TopicIndex maintains a set of FilteredSet objects.
Expand Down Expand Up @@ -121,6 +122,12 @@ def query_index(self, record, resultset=None):
return res
return IITreeSet()

def hasUniqueValuesFor(self, name):
"""has unique values for column name"""
if name == self.id:
return 1
return 0

def uniqueValues(self, name=None, withLength=0):
"""Return an iterable/sequence of unique values for name.
Expand Down
6 changes: 6 additions & 0 deletions src/Products/PluginIndexes/TopicIndex/tests.py
Expand Up @@ -69,10 +69,12 @@ def setUp(self):
def test_interfaces(self):
from Products.PluginIndexes.interfaces import ITopicIndex
from Products.PluginIndexes.interfaces import IPluggableIndex
from Products.PluginIndexes.interfaces import IUniqueValueIndex
from zope.interface.verify import verifyClass

verifyClass(ITopicIndex, TopicIndex)
verifyClass(IPluggableIndex, TopicIndex)
verifyClass(IUniqueValueIndex, TopicIndex)

def testOr(self):
self._searchOr('doc1', [1, 2])
Expand Down Expand Up @@ -109,3 +111,7 @@ def testUniqueValues(self):
self.assertEqual(list(self.TI.uniqueValues()), ['doc1', 'doc2'])
self.assertEqual(list(self.TI.uniqueValues(withLength=1)),
[('doc1', 2), ('doc2', 2)])

def testHasUniqueValuesFor(self):
self.assertFalse(self.TI.hasUniqueValuesFor('miss'))
self.assertTrue(self.TI.hasUniqueValuesFor('topic'))

0 comments on commit 71176da

Please sign in to comment.