fix description index for short comments.

svn path=/plone.app.discussion/trunk/; revision=27764
This commit is contained in:
Timo Stollenwerk 2009-07-01 10:01:37 +00:00
parent e2ab90641f
commit 9e94afc072
2 changed files with 18 additions and 6 deletions

View File

@ -24,8 +24,11 @@ def creator(object):
@indexer(IComment) @indexer(IComment)
def description(object): def description(object):
# Return the first 25 words of the comment text and append '...' # Return the first 25 words of the comment text and append ' [...]'
return '%s...' % join(object.text.split()[:MAX_DESCRIPTION]) text = join(object.text.split()[:MAX_DESCRIPTION])
if len(object.text.split()) > 25:
text += " [...]"
return text
@indexer(IComment) @indexer(IComment)
def searchable_text(object): def searchable_text(object):

View File

@ -36,7 +36,7 @@ class IndexersTest(PloneTestCase):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' 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.creator = "Jim"
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12) comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52) comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
@ -45,16 +45,25 @@ class IndexersTest(PloneTestCase):
self.comment_id = new_id self.comment_id = new_id
self.comment = comment self.comment = comment
self.conversation = conversation
def test_title(self): def test_title(self):
self.assertEquals(catalog.title(self.comment)(), 'Comment 1') self.assertEquals(catalog.title(self.comment)(), 'Comment 1')
self.assert_(isinstance(catalog.title, DelegatingIndexerFactory)) self.assert_(isinstance(catalog.title, DelegatingIndexerFactory))
def test_description(self): 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 # Create a 50 word comment and make sure the description returns
# only the first 25 words # 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...') comment_long = createObject('plone.Comment')
self.assert_(isinstance(catalog.description, DelegatingIndexerFactory)) 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): def test_dates(self):
# Test if created, modified, effective etc. are set correctly # Test if created, modified, effective etc. are set correctly
@ -63,7 +72,7 @@ class IndexersTest(PloneTestCase):
def test_searchable_text(self): def test_searchable_text(self):
# Test if searchable text is a concatenation of title and comment text # 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)) self.assert_(isinstance(catalog.searchable_text, DelegatingIndexerFactory))
def test_creator(self): def test_creator(self):