Dexterity IRichText Behavior field is not searchable

When I choose the IRichText behavior:text, it creates a field called "text" automatically. I noticed that when I use this field, the content inside this field is not searchable. I know I am to use collective.dexteritytextindexer but for this field that is automatically produced by Dexterity, I don't know where I can add indexer:searchable="true".

Seems like for the Page content type, the "text" field is searchable. Should this field that is added automatically when one checks the IRichText behavior be also a part of Searchable Text in portal_catalog?

Any advise would be most appreciated. Thank you.

Hi Angela - can you post your code or schema? You mentioned in chat you'd already looked at docs.plone.org for adding fields to SearchableText index.

Dont know if it is 'easy to do', but from a 'users point of view', the rich text behaviour should be searchable by default.

Does this work in your case? https://github.com/collective/collective.dexteritytextindexer

Here is my code:
http://dpaste.com/15TM7N9

Noticed for the IRichText behavior:text field, it does not even show up in the code, hence, I cannot add indexer:searchable="true".

Espen, I agree with you. It should be searchable by default but it is not. I wonder whether there is a bug with the IRichText behavior field.

I guess I don't know enough about Dexterity... but why do you need the IRichText behavior?

I was able to create on a test site a similar Policy with just two fields, Policy Content (Rich Text field) and Policy File (uploaded file), and it displays fine in my folder_contents view.

<model xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema">
  <schema>
    <field name="policy_content" type="plone.app.textfield.RichText">
      <description/>
      <required>False</required>
      <title>Policy Content</title>
    </field>
    <field name="policy_file" type="plone.namedfile.field.NamedBlobFile">
      <description/>
      <required>False</required>
      <title>Policy File</title>
    </field>
  </schema>
</model>


<?xml version="1.0"?>
<object name="policy" meta_type="Dexterity FTI" i18n:domain="plone"
   xmlns:i18n="http://xml.zope.org/namespaces/i18n">
 <property name="title" i18n:translate="">Policy</property>
 <property name="description" i18n:translate="">None</property>
 <property name="icon_expr">string:${portal_url}/document_icon.png</property>
 <property name="factory">policy</property>
 <property name="add_view_expr">string:${folder_url}/++add++policy</property>
 <property name="link_target"></property>
 <property name="immediate_view">view</property>
 <property name="global_allow">True</property>
 <property name="filter_content_types">True</property>
 <property name="allowed_content_types"/>
 <property name="allow_discussion">False</property>
 <property name="default_view">view</property>
 <property name="view_methods">
  <element value="view"/>
 </property>
 <property name="default_view_fallback">False</property>
 <property name="add_permission">cmf.AddPortalContent</property>
 <property name="klass">plone.dexterity.content.Container</property>
 <property name="behaviors">
  <element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/>
  <element value="plone.app.content.interfaces.INameFromTitle"/>
 </property>
 <property name="schema"></property>
 <property
    name="model_source">&lt;model xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema"&gt;
    &lt;schema&gt;
      &lt;field name="policy_content" type="plone.app.textfield.RichText"&gt;
        &lt;description/&gt;
        &lt;required&gt;False&lt;/required&gt;
        &lt;title&gt;Policy Content&lt;/title&gt;
      &lt;/field&gt;
      &lt;field name="policy_file" type="plone.namedfile.field.NamedBlobFile"&gt;
        &lt;description/&gt;
        &lt;required&gt;False&lt;/required&gt;
        &lt;title&gt;Policy File&lt;/title&gt;
      &lt;/field&gt;
    &lt;/schema&gt;
  &lt;/model&gt;</property>
 <property name="model_file"></property>
 <property name="schema_policy">dexterity</property>
 <alias from="(Default)" to="(dynamic view)"/>
 <alias from="edit" to="@@edit"/>
 <alias from="sharing" to="@@sharing"/>
 <alias from="view" to="(selected layout)"/>
 <action title="View" action_id="view" category="object" condition_expr=""
    description="" icon_expr="" link_target="" url_expr="string:${object_url}"
    visible="True">
  <permission value="View"/>
 </action>
 <action title="Edit" action_id="edit" category="object" condition_expr=""
    description="" icon_expr="" link_target=""
    url_expr="string:${object_url}/edit" visible="True">
  <permission value="Modify portal content"/>
 </action>
</object>

I was able to get collective.dexteritytextindexer working with my content type.

Specifically you have to do this for Dexterity CTs created TTW: https://github.com/collective/collective.dexteritytextindexer/blame/master/README.rst#L63

I changed two lines of the above XML (line 1 and line 4):

<?xml version='1.0' encoding='utf8'?>
<model xmlns:indexer="http://namespaces.plone.org/supermodel/indexer" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns="http://namespaces.plone.org/supermodel/schema">
  <schema>
    <field name="policy_content" type="plone.app.textfield.RichText" indexer:searchable="true">
      <description/>
      <required>False</required>
      <title>Policy Content</title>
    </field>
    <field name="policy_file" type="plone.namedfile.field.NamedBlobFile">
      <description/>
      <required>False</required>
      <title>Policy File</title>
    </field>
  </schema>
</model>

I also enabled the behavior "Dynamic SearchableText indexer behavior".

Then when I searched for text that appeared only in my one Policy item's Policy Content field, it worked (you might have to edit and save your policy items to force them to be reindexed).

Yes, when the field has indexer:searchable="true" in it, it is searchable. However for the RichText behavior:text there is no place whereby I can put indexer:searchable="true". The RichText behavior:text field is not searchable. It really should have been pulled into Searchable Text in portal_catalog by default but it is not functioning as it should. I believe there may be a bug between Dexterity RichText behavior:text and portal_catalog. They are not not talking to each other.

In my form, the RichText behavior:text behavior is not necessary. I thought it would help in the folder_contents listing issue. I have since remove it from my form. There really is no point using the RichText behavior:text since it is not searchable nor would it help with the folder_contents listing issue. As long as there is a value in this field, it will bomb the folder_contents listing feature. Could there be a bug affecting the interaction between Dexterity and Plone?

I'd remove that field (I really do not understand I guess.. is it a field? or a behaviour?).

It is a behavior that comes with a rich text field.

See my answer here https://github.com/plone/plone.app.dexterity/issues/237#issuecomment-284426391

1 Like

Thanks @jensens

@angelawong I must be missing something. I've tested locally and my tests work, probably because I did not start by enabling the behavior. This seems to me a way for you to proceed without having to code anything nor having to wait for Jens to get that feature into core. I think I've reached the end of my ability to help you, without having access to your site. If you'd like to hire someone to help you, you know where to look :wink:

Kim, thank you so much for testing the issue with me. I really appreciate your time and effort on this. Yes, if I need to hire someone, I know where to look :slight_smile: .

Jens, thank you for looking at my codes and for coming up with a solution. I look forward to the feature getting into the core. Thank you for working your magic. You are awesome.

Cheers,
Angela

'To my logic', there would be no point in having a Richtext behavior if it is not searchable, since one can always add a rich text field anyway (?)

1 Like

By following @jensens solution I successfully make my custom type searchable for the text field. For the record, in Plone5, you might want to import _unicode_save_string_concat from plone.app.contenttypes.indexers.

according to Python's naming styles, any name starting with an underscore is supposed to be private (weak "internal use" indicator); so, you should not depend on anything like that for your own code:

if this piece of code is intended to be reused, it should be renamed:

Plone Foundation Code of Conduct