Skip to content

Commit

Permalink
Index comments
Browse files Browse the repository at this point in the history
Make sure that comments are also added on the list of objects to be indexed.

Fixes:
#96
  • Loading branch information
gforcada committed Mar 14, 2016
1 parent 6157d3a commit 850dfb1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/collective/solr/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from collective.solr.utils import prepareData
from collective.solr.utils import setupTranslationMap
from collective.solr.utils import splitSimpleSearch
from plone.app.discussion.interfaces import IConversation
from unittest import TestCase
from zope.component import createObject


class UtilsTests(TestCase):
Expand All @@ -37,6 +39,16 @@ def setUp(self):
def ids(self, results):
return tuple(sorted([r[0] for r in results]))

def _add_comment(self, text):
"""Do not use self.portal as OFS objects can not be adapted to
IConversation
"""
news = self.layer['portal'].news
conversation = IConversation(news)
comment = createObject('plone.Comment')
comment.text = text
return conversation.addComment(comment)

def testZopeFindAndApply(self):
found = self.app.ZopeFindAndApply(self.portal, search_sub=True)
self.assertEqual(self.ids(found), self.good)
Expand All @@ -48,6 +60,15 @@ def testFindObjects(self):
# but the rest should be the same...
self.assertEqual(self.ids(found[1:]), self.good)

def testFindCommentObjects(self):
"""Check that comments are also found"""
comment_id = self._add_comment('lala')
found = list(findObjects(self.layer['portal'].news))
self.assertIn(
'++conversation++default/{0}'.format(comment_id),
self.ids(found)
)

def testSimpleTerm(self):
self.assertTrue(isSimpleTerm('foo'))
self.assertTrue(isSimpleTerm('foo '))
Expand Down
10 changes: 10 additions & 0 deletions src/collective/solr/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from string import maketrans
from re import compile, UNICODE
from plone.app.discussion.interfaces import IConversation

from Acquisition import aq_base
from unidecode import unidecode
Expand Down Expand Up @@ -168,6 +169,15 @@ def findObjects(origin):
for id in obj.objectIds():
paths.insert(idx + 1, path + '/' + id)

try:
conversation = IConversation(obj)
except TypeError:
continue

for comment in conversation.getComments():
comment_path = '/'.join(comment.getPhysicalPath()[-2:])
paths.insert(idx + 1, path + '/' + comment_path)


def padResults(results, start=0, **kw):
if start:
Expand Down

0 comments on commit 850dfb1

Please sign in to comment.