Added indexer for keyword searchable text

This commit is contained in:
David Convent 2013-01-29 13:42:13 +01:00
parent f73b528e3f
commit 76f54b5242
3 changed files with 44 additions and 8 deletions

View File

@ -2,6 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
i18n_domain="collective.dms.thesaurus">
@ -24,13 +25,10 @@
<adapter factory=".broaderkeywords.BroaderThesaurusKeywordsFieldWidget" />
<adapter factory=".equivalences.ThesaurusKeywordEquivalencesFieldWidget" />
<genericsetup:registerProfile
name="default"
title="collective.dms.thesaurus"
directory="profiles/default"
description="Installs the collective.dms.thesaurus package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<adapter
name="SearchableText"
factory=".indexers.dmskeyword_searchable_text"
/>
<utility
factory=".dmskeyword.DmsKeywordSchemaPolicy"
@ -49,4 +47,19 @@
permission="cmf.ManagePortal"
/>
<plone:behavior
title="Thesaurus Keyword SearchableText indexer behavior"
description="Enables the dynamic SearchableText indexer for Thesaurus Keyword"
provides=".indexers.IDmsKeywordIndexer"
for="plone.dexterity.interfaces.IDexterityContent"
/>
<genericsetup:registerProfile
name="default"
title="collective.dms.thesaurus"
directory="profiles/default"
description="Installs the collective.dms.thesaurus package"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
</configure>

View File

@ -0,0 +1,23 @@
from zope.interface import Interface
from plone.indexer import indexer
#from collective.dms.thesaurus.dmskeyword import IDmsKeyword
class IDmsKeywordIndexer(Interface):
"""Dexterity behavior interface for enabling the dynamic SearchableText
indexer on Document objecgs."""
@indexer(IDmsKeywordIndexer)
def dmskeyword_searchable_text(obj):
indexed_fields = []
title = obj.Title()
if isinstance(title, unicode):
title = title.encode('utf-8')
indexed_fields.append(title)
# equivs = obj.get_equivs()
# for equiv in equivs:
# if isinstance(title, unicode):
# equiv = title.encode('utf-8')
# indexed_fields.append(equiv)
return u' '.join(indexed_fields)

View File

@ -23,7 +23,7 @@
<property name="behaviors">
<element value="plone.app.content.interfaces.INameFromTitle"/>
<element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
<element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
<element value="collective.dms.thesaurus.indexers.IDmsKeywordIndexer" />
</property>
<!-- DO NOT use a model_source or it removes manually added fields while reapplying the profile -->
<!--property name="model_source" /-->