diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py
index a919e63..d45767b 100644
--- a/plone/app/discussion/catalog.py
+++ b/plone/app/discussion/catalog.py
@@ -8,12 +8,38 @@ from string import split, join
from DateTime import DateTime
+from Products.CMFCore.interfaces import IContentish
+
+from Products.ZCatalog.interfaces import IZCatalog
+
from plone.indexer import indexer
-from plone.app.discussion.interfaces import IComment
+from plone.app.discussion.interfaces import IConversation, IComment
+
MAX_DESCRIPTION=25
+# Conversation Indexers
+
+from plone.indexer.interfaces import IIndexer
+
+@indexer(IContentish, IZCatalog)
+def total_comments(object):
+ conversation = IConversation(object)
+ return conversation.total_comments
+
+@indexer(IContentish, IZCatalog)
+def last_comment_date(object):
+ conversation = IConversation(object)
+ return conversation.last_comment_date
+
+@indexer(IContentish, IZCatalog)
+def commentators(object):
+ conversation = IConversation(object)
+ return conversation.commentators
+
+# Comment Indexers
+
@indexer(IComment)
def title(object):
return object.title
diff --git a/plone/app/discussion/configure.zcml b/plone/app/discussion/configure.zcml
index 6d005cb..1b3a1fd 100644
--- a/plone/app/discussion/configure.zcml
+++ b/plone/app/discussion/configure.zcml
@@ -59,7 +59,12 @@
handler=".tool.unindex_object"
/>
-
+
+
+
+
+
+
@@ -68,5 +73,4 @@
-
diff --git a/plone/app/discussion/profiles/default/catalog.xml b/plone/app/discussion/profiles/default/catalog.xml
new file mode 100644
index 0000000..1737dda
--- /dev/null
+++ b/plone/app/discussion/profiles/default/catalog.xml
@@ -0,0 +1,16 @@
+
+
diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py
new file mode 100644
index 0000000..0b98737
--- /dev/null
+++ b/plone/app/discussion/tests/test_catalog.py
@@ -0,0 +1,124 @@
+import unittest
+
+from datetime import datetime
+
+from zope.component import createObject
+
+from zope.component import getMultiAdapter
+
+from Products.CMFCore.utils import getToolByName
+
+from Products.PloneTestCase.ptc import PloneTestCase
+
+from plone.app.discussion.tests.layer import DiscussionLayer
+
+from plone.app.discussion.interfaces import IComment, IConversation, IReplies
+
+class ConversationCatalogTest(PloneTestCase):
+
+ layer = DiscussionLayer
+
+ def afterSetUp(self):
+ # First we need to create some content.
+ self.loginAsPortalOwner()
+ typetool = self.portal.portal_types
+ typetool.constructContent('Document', self.portal, 'doc1')
+
+ self.catalog = getToolByName(self.portal, 'portal_catalog')
+
+ conversation = IConversation(self.portal.doc1)
+
+ comment1 = createObject('plone.Comment')
+ comment1.title = 'Comment 1'
+ comment1.text = 'Comment text'
+ comment1.creator = 'Jim'
+ comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
+ comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
+
+ new_comment1_id = conversation.addComment(comment1)
+ self.comment_id = new_comment1_id
+
+ comment1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
+ comment1.reindexObject()
+
+ brains = self.catalog.searchResults(
+ path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
+ portal_type = "Document"
+ )
+ self.conversation = conversation
+ self.conversation_brain = brains[0]
+ self.comment1 = comment1
+
+ def test_total_comments(self):
+ self.failUnless(self.conversation_brain.has_key('total_comments'))
+ self.assertEquals(self.conversation_brain.total_comments, 1)
+
+ comment2 = createObject('plone.Comment')
+ comment2.title = 'Comment 2'
+ comment2.text = 'Comment text'
+ comment2.creator = 'Emma'
+ new_comment2_id = self.conversation.addComment(comment2)
+
+ comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment2_id)
+ comment2.reindexObject()
+ brains = self.catalog.searchResults(
+ path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
+ portal_type = "Document"
+ )
+ conversation_brain = brains[0]
+ self.assertEquals(conversation_brain.total_comments, 2)
+
+ comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment2_id)
+ comment2.reindexObject()
+
+ def test_last_comment_date(self):
+ self.failUnless(self.conversation_brain.has_key('last_comment_date'))
+ self.assertEquals(self.conversation_brain.last_comment_date, datetime(2006, 9, 17, 14, 18, 12))
+
+ def test_commentators(self):
+ self.failUnless(self.conversation_brain.has_key('commentators'))
+
+class CommentCatalogTest(PloneTestCase):
+
+ layer = DiscussionLayer
+
+ def afterSetUp(self):
+ # First we need to create some content.
+ self.loginAsPortalOwner()
+ typetool = self.portal.portal_types
+ typetool.constructContent('Document', self.portal, 'doc1')
+
+ self.catalog = getToolByName(self.portal, 'portal_catalog')
+
+ conversation = IConversation(self.portal.doc1)
+
+ comment1 = createObject('plone.Comment')
+ comment1.title = 'Comment 1'
+ comment1.text = 'Comment text'
+ comment1.creator = 'Jim'
+
+ new_comment1_id = conversation.addComment(comment1)
+ self.comment_id = new_comment1_id
+
+ self.comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
+
+ brains = self.catalog.searchResults(
+ path = {'query' : '/'.join(self.comment.getPhysicalPath()) })
+ self.comment_brain = brains[0]
+
+ def test_title(self):
+ self.assertEquals(self.comment_brain.Title, 'Comment 1')
+
+ def test_type(self):
+ self.assertEquals(self.comment_brain.portal_type, 'Discussion Item')
+ self.assertEquals(self.comment_brain.meta_type, 'Discussion Item')
+ self.assertEquals(self.comment_brain.Type, 'Discussion Item')
+
+ def test_review_state(self):
+ self.assertEquals(self.comment_brain.review_state, 'published')
+
+ def test_creator(self):
+ self.assertEquals(self.comment_brain.Creator, 'Jim')
+
+def test_suite():
+ return unittest.defaultTestLoader.loadTestsFromName(__name__)
\ No newline at end of file
diff --git a/plone/app/discussion/tests/test_indexers.py b/plone/app/discussion/tests/test_indexers.py
index 3f98650..156f39f 100644
--- a/plone/app/discussion/tests/test_indexers.py
+++ b/plone/app/discussion/tests/test_indexers.py
@@ -17,7 +17,73 @@ from zope.component import provideAdapter
from plone.app.discussion import catalog
-class IndexersTest(PloneTestCase):
+
+class ConversationIndexersTest(PloneTestCase):
+
+ layer = DiscussionLayer
+
+ def afterSetUp(self):
+ # First we need to create some content.
+ self.loginAsPortalOwner()
+ typetool = self.portal.portal_types
+ typetool.constructContent('Document', self.portal, 'doc1')
+
+ # Create a conversation.
+ conversation = IConversation(self.portal.doc1)
+
+ comment1 = createObject('plone.Comment')
+ comment1.title = 'Comment 1'
+ comment1.text = 'Comment Text'
+ comment1.creator = "Jim"
+ comment1.author_username = "Jim"
+ comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
+ comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
+ self.new_id1 = conversation.addComment(comment1)
+
+ comment2 = createObject('plone.Comment')
+ comment2.title = 'Comment 2'
+ comment2.text = 'Comment Text'
+ comment2.creator = "Emma"
+ comment2.author_username = "Emma"
+ comment2.creation_date = datetime(2007, 12, 13, 4, 18, 12)
+ comment2.modification_date = datetime(2007, 12, 13, 4, 18, 12)
+ self.new_id2 = conversation.addComment(comment2)
+
+ comment3 = createObject('plone.Comment')
+ comment3.title = 'Comment 3'
+ comment3.text = 'Comment Text'
+ comment3.creator = "Lukas"
+ comment3.author_username = "Lukas"
+ comment3.creation_date = datetime(2009, 4, 12, 11, 12, 12)
+ comment3.modification_date = datetime(2009, 4, 12, 11, 12, 12)
+ self.new_id3 = conversation.addComment(comment3)
+
+ self.conversation = conversation
+
+ def test_conversation_total_comments(self):
+ self.assert_(isinstance(catalog.total_comments, DelegatingIndexerFactory))
+ self.assertEquals(catalog.total_comments(self.portal.doc1)(), 3)
+ del self.conversation[self.new_id1]
+ self.assertEquals(catalog.total_comments(self.portal.doc1)(), 2)
+ del self.conversation[self.new_id2]
+ del self.conversation[self.new_id3]
+ self.assertEquals(catalog.total_comments(self.portal.doc1)(), 0)
+
+ def test_conversation_last_comment_date(self):
+ self.assert_(isinstance(catalog.last_comment_date, DelegatingIndexerFactory))
+ self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), datetime(2009, 4, 12, 11, 12, 12))
+ del self.conversation[self.new_id3]
+ self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), datetime(2007, 12, 13, 4, 18, 12))
+ del self.conversation[self.new_id2]
+ del self.conversation[self.new_id1]
+ self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), None)
+
+ def test_conversation_commentators(self):
+ pass
+ #self.assertEquals(catalog.commentators(self.portal.doc1)(), ('Jim', 'Emma', 'Lukas'))
+ #self.assert_(isinstance(catalog.commentators, DelegatingIndexerFactory))
+
+class CommentIndexersTest(PloneTestCase):
layer = DiscussionLayer