Skip to content

Commit

Permalink
Return values according to the definition of uniqueValues
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Apr 19, 2019
1 parent 26659f1 commit affc000
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Products/PluginIndexes/TopicIndex/TopicIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,23 @@ def query_index(self, record, resultset=None):
return IITreeSet()

def uniqueValues(self, name=None, withLength=0):
""" needed to be consistent with the interface """
return self.filteredSets.keys()
"""Return an iterable/sequence of unique values for name.
If 'withLengths' is true, returns a iterable/sequence of tuples of
(value, length).
"""

if name is None:
name = self.id
elif name != self.id:
return

if not withLength:
for key in self.filteredSets.keys():
yield key
else:
for key, value in self.filteredSets.items():
yield (key, len(value.getIds()))

def getEntryForObject(self, docid, default=_marker):
""" Takes a document ID and returns all the information we have
Expand Down
5 changes: 5 additions & 0 deletions src/Products/PluginIndexes/TopicIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ def testGetEntryForObject(self):
self.assertEqual(self.TI.getEntryForObject(0, 'foo'), 'foo')
self.assertEqual(self.TI.getEntryForObject(1), ['doc1'])
self.assertEqual(self.TI.getEntryForObject(3), ['doc2'])

def testUniqueValues(self):
self.assertEqual(list(self.TI.uniqueValues()), ['doc1', 'doc2'])
self.assertEqual(list(self.TI.uniqueValues(withLength=1)),
[('doc1', 2), ('doc2', 2)])

0 comments on commit affc000

Please sign in to comment.