Lucene index field value stripped of all html tags

I have a Lucene index in which one of the fields is displayed in the Sitecore rich text box.

Since this field value contains html content for most elements sharing the template, I expected the html content to be returned when the element field value was retrieved. However, I noticed that the return value is devoid of all html tags.

I tried changing INDEXTYPE to "UNTOKENTIZED". But this did not solve the problem. I understand that Lucene is doing this to allow searches based on this area. But this is not a requirement in my case, and I want this behavior to be redefined.

+5
source share
2 answers

This is because there is a RichTextFieldReader assigned to the html and rich text fields:

 <fieldReader fieldTypeName="html|rich text" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.RichTextFieldReader, Sitecore.ContentSearch" /> 

In Sitecore 8.1, it is defined in Sitecore.ContentSearch.Lucene.DefaultIndexConfiguration.config .

It removes all tags using HtmlField.GetPlainText() .

You can try adding another section at the same level as <mapFieldByTypeName hint="raw:AddFieldReaderByFieldTypeName"> , and use something like:

 <mapFieldByFieldName hint="AddFieldReaderByFieldName"> <fieldReader fieldName="yourFieldName" fieldReaderType="Sitecore.ContentSearch.FieldReaders.DefaultFieldReader, Sitecore.ContentSearch" /> 

Mapping with fieldName takes precedence over matching by field type, so it will use the fieldRendered specified for your field, instead of using the one specified for your field type.

+4
source

You should be able to create a computed index field, and this should save the HTML correctly in the index.

 public class TileHtml : IComputedIndexField { public object ComputeFieldValue(IIndexable indexable) { Item indexedContent = indexable as SitecoreIndexableItem; if (indexedContent != null && indexedContent.Fields[ITileConstants.TileHtmlFieldName] != null && !string.IsNullOrWhiteSpace(indexedContent.Fields[ITileConstants.TileHtmlFieldName].Value)) { return indexedContent.Fields[ITileConstants.TileHtmlFieldName].Value; } return null; } public string FieldName { get; set; } public string ReturnType { get; set; } } 

You can then register the application in your Lucene index.

 <fields hint="raw:AddComputedIndexField"> <field fieldName="TileHtml" storageType="YES" indexType="TOKENIZED">Namespace.TileHtml, Assembly</field> 

0
source

All Articles