From 9e94afc072e28776479b060c97d4e27377d5136c Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Wed, 1 Jul 2009 10:01:37 +0000 Subject: [PATCH] fix description index for short comments. svn path=/plone.app.discussion/trunk/; revision=27764 --- plone/app/discussion/catalog.py | 7 +++++-- plone/app/discussion/tests/test_indexers.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py index f78af84..a919e63 100644 --- a/plone/app/discussion/catalog.py +++ b/plone/app/discussion/catalog.py @@ -24,8 +24,11 @@ def creator(object): @indexer(IComment) def description(object): - # Return the first 25 words of the comment text and append '...' - return '%s...' % join(object.text.split()[:MAX_DESCRIPTION]) + # Return the first 25 words of the comment text and append ' [...]' + text = join(object.text.split()[:MAX_DESCRIPTION]) + if len(object.text.split()) > 25: + text += " [...]" + return text @indexer(IComment) def searchable_text(object): diff --git a/plone/app/discussion/tests/test_indexers.py b/plone/app/discussion/tests/test_indexers.py index 52d8002..3f98650 100644 --- a/plone/app/discussion/tests/test_indexers.py +++ b/plone/app/discussion/tests/test_indexers.py @@ -36,7 +36,7 @@ class IndexersTest(PloneTestCase): comment = createObject('plone.Comment') comment.title = 'Comment 1' - 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.' + comment.text = 'Lorem ipsum dolor sit amet.' comment.creator = "Jim" comment.creation_date = datetime(2006, 9, 17, 14, 18, 12) comment.modification_date = datetime(2008, 3, 12, 7, 32, 52) @@ -45,16 +45,25 @@ class IndexersTest(PloneTestCase): self.comment_id = new_id self.comment = comment + self.conversation = conversation def test_title(self): self.assertEquals(catalog.title(self.comment)(), 'Comment 1') self.assert_(isinstance(catalog.title, DelegatingIndexerFactory)) def test_description(self): + self.assertEquals(catalog.description(self.comment)(), 'Lorem ipsum dolor sit amet.') + self.assert_(isinstance(catalog.description, DelegatingIndexerFactory)) + + def test_description_long(self): # Create a 50 word comment and make sure the description returns # only the first 25 words - self.assertEquals(catalog.description(self.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(catalog.description, DelegatingIndexerFactory)) + comment_long = createObject('plone.Comment') + comment_long.title = 'Long Comment' + comment_long.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 = self.conversation.addComment(comment_long) + self.assertEquals(catalog.description(comment_long)(), '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 [...]') def test_dates(self): # Test if created, modified, effective etc. are set correctly @@ -63,7 +72,7 @@ class IndexersTest(PloneTestCase): def test_searchable_text(self): # Test if searchable text is a concatenation of title and comment text - self.assertEquals(catalog.searchable_text(self.comment)(), ('Comment 1', '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.')) + self.assertEquals(catalog.searchable_text(self.comment)(), ('Comment 1', 'Lorem ipsum dolor sit amet.')) self.assert_(isinstance(catalog.searchable_text, DelegatingIndexerFactory)) def test_creator(self):