2

I want to prevent stripping out the HTML from my one of the Rich Text Field.

I have the following field reader by field name in my index configuration file in place under the mapFieldByTypeName element.

It's still not keeping the inline HTML's for this field and it's stripping out. Is there any other settings i need to look into it?

<mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
    <fieldReader fieldName="Body Copy" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
</mapFieldByFieldName>
2
  • Why do you want html markup in your indexed field tho? That could cause potential issues when running a search query on that field.
    – Richard Seal
    Feb 10, 2023 at 17:48
  • Agree. I am planning to response to the GraphQL query. My understanding is that the GraphQL response is from the index not from the item in the DB. When i try to hit the GraphQL query, it's responding as in the Index for the Rich Text filed.
    – Jey
    Feb 10, 2023 at 18:36

3 Answers 3

1

I agree with the approach shared by Sumit and Rishiraj, add on to that as you need only one rich text field to be allowed without HTML stripping you already done mapFieldByFieldName. so I think it is something related to the configuration issue only. For better understanding and resolution, I did try with Sitecore 9.3 the following steps that will help you to investigate/fix an issue.

Patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultSolrIndexConfiguration>
           <fieldReaders>
            <mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
                <fieldReader fieldName="Body Copy" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
            </mapFieldByFieldName>           
          </fieldReaders>
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

Validate the patch applied correctly using sitecore/admin/showconfig.aspx

  1. Created 2 field Body Copy and DemoRichText2 in Sample Item template. enter image description here
  2. Index the home item only by selecting home item and then from ribbon go to Developer menu and then click on Re-index Tree.
  3. Go to solr admin page and check for the home item. enter image description here

Referance links: https://learnsitecorebasics.wordpress.com/2016/05/30/sitecore-include-html-tags-in-indexes-for-rich-text-field/

Search HTML code in Content Editor

Hope it helps!

1
  • Thanks Sumit. I am able to get what i want in the vanilla version with simple patch config file. I am facing issue with my actual site implementation. I believe something wrong with my config. I will check and fix it. Thank for your time and help.
    – Jey
    Feb 13, 2023 at 22:16
1

Rich Text Editor field only returns plain text.

For resolve your issue you have to update your Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file.

In this config file you have to replace this line from this

<fieldReader fieldTypeName=”HTML|rich text” fieldReaderType=”Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch” />

to this line

<fieldReader fieldTypeName=”html|rich text” fieldReaderType=”Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch” />

After it rebuild your indexes.

Better approach will be if you create patch config for this. For creating a patch file you can follow below link for reference.

https://doc.sitecore.com/xp/en/developers/93/platform-administration-and-architecture/use-a-patch-file-to-customize-the-sitecore-configuration.html#create-a-patch-file

Hope this helps you.

1
  • Thanks RishiRaj. After changing the default behavior and adding the patch config file for my custom index with particular filed to include the inline HTML is not working as expected. it's default taking the behavior from the "DefaultIndexCongiguration"
    – Jey
    Feb 10, 2023 at 18:39
1

Try this

Open the Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file and change the following line from

<fieldReader fieldTypeName=”HTML|rich text” fieldReaderType=”Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch” />

to

<fieldReader fieldTypeName=”html|rich text” fieldReaderType=”Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch” />

For all fields that should be indexed without stripping HTML tags add the following lines inside <fieldReaders> XML node

<mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
  <fieldReader fieldName="Body Copy" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
</mapFieldByFieldName>

And then Rebuild search indexes.

Refer to this article to set your fields.

https://bhavikmehtasite.wordpress.com/2017/06/29/not-getting-html-tags-in-rich-text-editor-field-using-solr-in-sitecore/

Hope this helps.

2
  • Hi Sumit, I followed this approach. when i change the default content search as "DefaultFieldReader", it's including the HTML for all the Rich text fields. I am having a batch config for my custom index config where i have the mapfieldbyfieldname element.
    – Jey
    Feb 10, 2023 at 18:18
  • I am not getting your comment. Can you please elaborate more? So you said it started including HTML, but do you need it for any specific one? Feb 11, 2023 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.