Is there a way to index a field from a subform?
My aim is to have a user list their educational background, which should be indexed and searchable, in order to find the user by their school(s) when using the Plone's global search box.
I'm using collective.z3cform.datagridfield for the subform.
The snippets below works for rendering and saving the data but it's not showing up in the index.
# Subform
class IEducation(model.Schema):
dexteritytextindexer.searchable('school')
school = schema.TextLine(
title=_(u'School'),
required=True,
)
directives.widget(
'school',
AjaxSelectFieldWidget,
pattern_options={
"maximumSelectionSize": 1
},
vocabulary="my.package.vocabularies.schools"
)
from_date = schema.Date(
title=_(u'From'),
required=True
)
to_date = schema.Date(
title=_(u'To'),
required=True
)
# Parent form
class IMember(model.Schema):
education = schema.List(
title=_(u'Education'),
value_type=DictRow(title=u"education", schema=IEducation),
required=False
)
directives.widget(
'education',
BlockDataGridFieldFactory
)
Reference the index point in the `indexers.py``
@indexer(IEducation)
def school(obj):
return obj.school
Set the adapter for the school index
<adapter factory=".indexers.school" name="school" />
Create a dynamic vocabulary for the school index
@provider(IContextSourceBinder)
def available_schools(context):
catalog = api.portal.get_tool('portal_catalog')
schools = catalog.uniqueValuesFor('school')
return SimpleVocabulary([
SimpleTerm(value=school, title=school) for school in schools
])
Register the utility for the dynamic school vocabulary
<utility
provides="zope.schema.interfaces.IVocabularyFactory"
component=".vocabularies.available_schools"
name="my.package.vocabularies.schools"
/>