Skip to content

Commit

Permalink
Restore dexteritytextindexer support
Browse files Browse the repository at this point in the history
  • Loading branch information
datakurre committed Mar 28, 2016
1 parent e61daf5 commit 96d7a5f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plone/app/blocks/configure.zcml
Expand Up @@ -211,4 +211,9 @@
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".subscribers.onLayoutEdited" />

<adapter
factory=".indexing.LayoutFieldConverter"
zcml:condition="installed collective.dexteritytextindexer"
/>

</configure>
28 changes: 28 additions & 0 deletions plone/app/blocks/indexing.py
@@ -1,10 +1,26 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.utils import safe_unicode
from lxml.html import fromstring
from lxml.html import tostring
from plone.app.blocks.layoutbehavior import ILayoutAware
from plone.dexterity.interfaces import IDexterityContent
from plone.indexer.decorator import indexer
from plone.tiles.data import ANNOTATIONS_KEY_PREFIX
from z3c.form.interfaces import IWidget
from zope.annotation.interfaces import IAnnotations
from zope.component import adapter
from zope.interface import implementer
import pkg_resources

try:
pkg_resources.get_distribution('collective.dexteritytextindexer')
except pkg_resources.DistributionNotFound:
HAS_DEXTERITYTEXTINDEXER = False
else:
from collective.dexteritytextindexer.converters import DefaultDexterityTextIndexFieldConverter # noqa
from collective.dexteritytextindexer.interfaces import IDexterityTextIndexFieldConverter # noqa
from collective.dexteritytextindexer.utils import searchable
HAS_DEXTERITYTEXTINDEXER = True

try:
from plone.app.contenttypes import indexers
Expand Down Expand Up @@ -52,3 +68,15 @@ def LayoutSearchableText(obj):
text.append(tostring(el))

return concat(*text)


if HAS_DEXTERITYTEXTINDEXER:

searchable(ILayoutAware, 'content')

@implementer(IDexterityTextIndexFieldConverter)
@adapter(IDexterityContent, ILayoutAware, IWidget)
class LayoutFieldConverter(DefaultDexterityTextIndexFieldConverter):

def convert(self):
return LayoutSearchableText(self.context)

0 comments on commit 96d7a5f

Please sign in to comment.