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
class IMyBehavior(Schema):
dexteritytextindexer.searchable('MyField')
specialfield = schema.Text(title=u'My Field')
alsoProvides(IMyBehavior, IFormFieldProvider)
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.
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:
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.
Thanks, csanahuja
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.
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.
After reinstalling plone.app.contenttypes, the field I added can be searched. But except the field, other fields became unsearchable
Need to add indexer:searchhttps://community.plone.org/t/how-to-make-a-added-field-searchable-using-collective-dexteritytextindexer/6397/5able="true" to every field in app/contenttypes/schema/file.xml?
If I set the field type as multi choice and use type="zope.schema.Choice" in schema/file.xml, reinstalling plone.app.contenttypes failed with message:
SupermodelParseError: You must specify either values or vocabulary.
File "/opt/plone/buildout-cache/eggs/plone.app.contenttypes-1.4.9-py2.7.egg/plone/app/contenttypes/schema/file.xml", line 26
indexer:searchable="true">
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.