I added a field (MyField) to dexterity content type File and try to make it searchable following the guide here . After restarting the instance, the site refused to connect .
These are what I did:
add these code to buildout-cache/eggs/plone.app.contenttypes-1.4.9-py2.7.egg/plone/app/contenttypes/profiles/default/types/File.xml:
(with<)property name="behaviors"><element(a space)value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" /></property (with>)
Add these code to buildout-cache/eggs/plone.autoform-1.7.5-py2.7.egg/plone/autoform/directives.py
from collective import dexteritytextindexer
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel.model import Schema
from zope import schema
from zope.interface import alsoProvides
specialfield = schema.Text(title=u'My Field')
Now what should I check and how to go forward?
On the first step you are adding a behavior to File contenttype, 'IDexteirtyTextIndexer', File has already some behaviors since you are editing the original source add it here.
<!-- Enabled behaviors -->
<property name="behaviors" purge="false">
<!-- Existing behaviors -->
<element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
On the second step you define a schema the same way plone does with some behaviors that provide fields, see here: https://github.com/plone/plone.app.contenttypes/tree/master/plone/app/contenttypes/behaviors
But you are not registering it anywhere. If you want to do a behavior you need to register it and then add the behavior to the contenttype.
Any reason to put the code in plone/autoform/directives.py it does not make sense for me.
So if you want to add a field to File searchable you can either register define a behavior that provides a field searchable or add the field to File schema here plone/app/contenttypes/schema/file.xml:
<field name="specialfield" type="zope.schema.TextLine"
and aswell to the model header
As specified in the tutorial. This should work I haven't tested, past aswell the error you were getting. Also if you plan to have more Plone sites on same Zope move your code to a product so the customizations are not on every site you create and easy to do upgrades.
I modified profiles/default/types/File.xml and app/contenttypes/schema/file.xml as you said, now the site can be reached again. But search find nothing with this message: 0 items matching your search terms.
What can I do now?
I have just tested and it works for me. Some questions
- Did you add collective.dexteritytextindexer to buildout?
- When you add a new File do you see the new field?
If you had already a site created after the modifications you need to reinstall plone.app.contenttypes. Go to ZMI adding /manage to your Plone Site, i.e: localhost:8080/Plone/manage then go to portal_quickinstaller and reinstall it.
- Yes you are right. I have found this on plone.app.dexterity documentation https://github.com/plone/plone.app.dexterity/blob/76eed6b55116d45568ec605ea81e1f579cc8a9d8/docs/advanced/catalog-indexing-strategies.rst#making-content-searchable
Note that if you turn on the Dynamic SearchableText indexer behavior for a content type, then you must specify all fields that need SearchableText indexing. Dublin core fields like Title and Description are no longer automatically handled.
Once you have turned on the indexer behavior, edit the XML field model to add indexer:searchable="true" to the field tag for each field you wish to add to the SearchableText index.
See the collective.dexteritytextindexer package documentation for details and for information on how to use it via Python schema.
Aparently it says that when you add that behavior you lose title and description as searchable. I have been testing this and I have find that for most default Plone contenttypes field Title and Description comes from a behavior: plone.app.dexterity.behaviors.metadata.IDublinCore
For the contenttype file you already said title and description are directly in the schema.
So I have added a new field to contenttype Folder the same way we did with File expecting to lose Title and Description as searchable aswell but they are still searchable!
So in short if the fields come from the behavior are still searchable not if they are in the schema. You have two option mark them as searchable indexer:searchable="true" or delete them from schema and add the IDublinCore interface.
- This error is not related with searchable but wrong definition of the field. See here to see some examples of fields.
I think this field fits what you want
<field name="audience" type="zope.schema.Set">