Multifields in searchindex?

Hi,
Is multifields on products included in the search index?

Litium version: 7.3

Hi,
Multifields are not included in the search index but you can include them by implementing the IIndexFieldDocumentTagsConverter.
Here comes a sample implementation that index only one text field of the multifield.

{
    [Service(Name = "Multifield")]
    public class IndexDocumentTagMultiFieldField :  IIndexFieldDocumentTagsConverter
    {
        private readonly LanguageService _languageService;

        public IndexDocumentTagMultiFieldField(LanguageService languageService)
        {
            _languageService = languageService;
        }
        public ICollection<DocumentTag> ConvertToIndexDocumentTags(IndexFieldTypeConverterArgs arg, object item)
        {
            var result = new List<DocumentTag>();
            
            // If the item is null do not index anything
            if (item == null)
            {
                return result;
            }

            var values = (IEnumerable<MultiFieldItem>) item;
            if (values != null && values.Count() > 0)
            {
                var languages = _languageService.GetAll();
                foreach (var language in languages)
                {
                    // We assume that the Multifield text item is always language dependent
                    var tagName = TagNames.AppendLanguage(TagNames.GetTagNameForProperty(arg.FieldDefinition.Id), language.CultureInfo);
                    var bodyTagName = TagNames.AppendLanguage(TagNames.Body, language.CultureInfo);
                    foreach (var value in values)
                    {
                        if (value.Fields.TryGetValue("Id of the multifield item", language.CultureInfo, out var valueInCurrentCulture))
                        {
                            var currentValue = (string)valueInCurrentCulture;
                            if (!string.IsNullOrWhiteSpace(currentValue))
                            {
                                result.Add(new DocumentTag(tagName, currentValue) { TermVector = true, Readable = true });
                                result.Add(new DocumentTag(bodyTagName, currentValue) { Analyzed = true });
                            }
                        }
                    }
                }
            }
            return result;
        }
    }
}
5 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.