How to make a added field searchable using collective.dexteritytextindexer?

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:

  1. add these code to buildout-cache/eggs/
    (with<)property name="behaviors"><element(a space)value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" /></property (with>)

  2. Add these code to buildout-cache/eggs/plone.autoform-1.7.5-py2.7.egg/plone/autoform/

     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):
         specialfield = schema.Text(title=u'My Field')
     alsoProvides(IMyBehavior, IFormFieldProvider)

Now what should I check and how to go forward?


Hey Hugo,

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:

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/ 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"
        <title>Special field</title>

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.

Thanks, csanahuja :slight_smile:
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

  1. Did you add collective.dexteritytextindexer to buildout?
  2. 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 Go to ZMI adding /manage to your Plone Site, i.e: localhost:8080/Plone/manage then go to portal_quickinstaller and reinstall it.

  1. After reinstalling, the field I added can be searched. But except the field, other fields became unsearchable :frowning:
    Need to add indexer:search"true" to every field in app/contenttypes/schema/file.xml?

  2. If I set the field type as multi choice and use type="zope.schema.Choice" in schema/file.xml, reinstalling failed with message:

    SupermodelParseError: You must specify either values or vocabulary.
    File "/opt/plone/buildout-cache/eggs/", line 26

  1. Yes you are right. I have found this on documentation

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:

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.

  1. 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">
        <value_type type="zope.schema.Choice">
1 Like