diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py index 29b4c8c..1f46ddb 100644 --- a/plone/app/discussion/catalog.py +++ b/plone/app/discussion/catalog.py @@ -4,18 +4,22 @@ indexes with values based on the IComment interface. Also provide event handlers to actually catalog the comments. """ +from string import split, join + from plone.indexer import indexer from plone.app.discussion.interfaces import IComment +MAX_DESCRIPTION=25 + @indexer(IComment) def comment_title(object): return object.title @indexer(IComment) def comment_description(object): - # Todo: this is wrong!!! - return object.title + # Return the first 25 words of the comment text and append '...' + return '%s...' % join(object.text.split()[:MAX_DESCRIPTION]) @indexer(IComment) def comment_searchable_text(object): diff --git a/plone/app/discussion/tests/test_indexers.py b/plone/app/discussion/tests/test_indexers.py index ac6a2a3..5bfef8f 100644 --- a/plone/app/discussion/tests/test_indexers.py +++ b/plone/app/discussion/tests/test_indexers.py @@ -47,6 +47,8 @@ class IndexersTest(PloneTestCase): self.assert_(isinstance(comment_title, DelegatingIndexerFactory)) def test_comment_description(self): + # Create a 50 word comment and make sure the description returns + # only the first 25 words # Create a conversation. In this case we doesn't assign it to an # object, as we just want to check the Conversation object API. @@ -60,11 +62,11 @@ class IndexersTest(PloneTestCase): comment = createObject('plone.Comment') comment.title = 'Comment 1' - comment.text = 'Comment text' + comment.text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.' new_id = conversation.addComment(comment) - self.assertEquals(comment_description(comment)(), 'Comment 1') + self.assertEquals(comment_description(comment)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At...') self.assert_(isinstance(comment_description, DelegatingIndexerFactory)) def test_dates(self):