0

I am sorry if this is a stupid question, I am just starting to explore Sitecore.

When I use the search function in the Content Editor, it will return the items that contain my search query. But it will never return anything if I search for HTML code. For example, I know there are many items that contain a link (<a href...>) in their rich text fields, but if I do a search for href, nothing will be returned.

Is this behaviour inherent of Sitecore, or is this configurable somewhere?

1 Answer 1

3

HTML tags are stripped out while indexing Rich Text field content OOTB in Sitecore and this is a good practice in general as well. But Yes you can configure this, there are two ways to index any RTE field with html tags, first for a single field and, second for all the RTE fields.

Single Field- Create a patch config for SITECORE FIELDTYPE MAP section, this map a field type by name to a Strongly Typed Implementation of the field type e.g. html maps to HTMLField. Will add below section under <fieldReaders section. It will have the fieldReaderType = Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch

<mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
<fieldReaderfieldName="RTEFieldName"fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
</mapFieldByFieldName> 

Final output in your showconfig would be like -

<fieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
<param desc="id">defaultFieldReaderMap</param>
<mapFieldByFieldName hint="raw:AddFieldReaderByFieldName">
<fieldReaderfieldName="RTEFieldName"fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" />
</mapFieldByFieldName>
<mapFieldByTypeName hint="raw:AddFieldReaderByFieldTypeName">
<fieldReader fieldTypeName="checkbox" fieldReaderType="Sitecore.ContentSearch.FieldReaders.CheckboxFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="date|datetime" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DateFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="image" fieldReaderType="Sitecore.ContentSearch.FieldReaders.ImageFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="single-line text|multi-line text|text|memo" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="integer" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NumericFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="number" fieldReaderType="Sitecore.ContentSearch.FieldReaders.PrecisionNumericFieldReader, Sitecore.ContentSearch"/>
fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch" />
<fieldReader fieldTypeName="multilist with search|treelist with search" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DelimitedListFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="checklist|multilist|treelist|treelistex|tree list" fieldReaderType="Sitecore.ContentSearch.FieldReaders.MultiListFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="icon|droplist|grouped droplist" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="name lookup value list|name value list" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NameValueListFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="droplink|droptree|grouped droplink|tree|reference" fieldReaderType="Sitecore.ContentSearch.FieldReaders.LookupFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="attachment|frame|rules|tracking|thumbnail" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NullFieldReader, Sitecore.ContentSearch"/>
<fieldReader fieldTypeName="file|security|server file|template field source|link" fieldReaderType="Sitecore.ContentSearch.FieldReaders.NullFieldReader, Sitecore.ContentSearch"/>
</mapFieldByTypeName>
</fieldReaders>

RTE Field Type - For all the RTE field type you just need to change the fieldReaderType of “html|rich text” fieldReader to Sitecore.ContentSearch.FieldReaders.DefaultFieldReader. recommanded practice to create patch for config update.

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

After updating these config chagnes you need to do reindexing.

1
  • Thank you for a very clear explanation!
    – Peter
    Commented Oct 21, 2021 at 15:24

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.