How to modify the product search to not search in images?

We would like to have the product search that’s part of the Accelerator to not match a query against images for products (and variants). It seems like if the filename of an image connected to a product matches the search query includes the product in the search result. Is this correct? And if so, how can modify this behaviour?

Litium version: 7.4

You will need to create a custom IndexingProviderPreProcessor for removing those.

Thanks! But it looks like images are already excluded?

                    case SystemFieldTypeConstants.MediaPointerImage:
                    case SystemFieldTypeConstants.MultiField:
                    case SystemFieldTypeConstants.MultirowText:
                    case SystemFieldTypeConstants.Object:
                    case SystemFieldTypeConstants.Pointer:
                        // skip adding the tag, it is data that not should be filtered on

This is for Elastic search, are you working with that or Lucene?

Lucene. Is Elastic Search available for customers on the small (shared) plan?

By the way, exaactly which fields are quried when you use the Litium.Foundation.Search.Constants.TagNames.Body tag?

I will send you a solution code by Monday morning as fast as it is approved for not affecting the performance negatively.

1 Like

Thanks to Utku he has some suggestion on this:

using Litium.FieldFramework;
using Litium.Foundation.Modules.MediaArchive;
using Litium.Framework.Search.Indexing;
using Litium.Media;
using Litium.Studio.FieldFramework;
using System;
using System.Collections.Generic;
using Litium.Foundation.Search.Constants;
using Litium.Runtime.DependencyInjection;


namespace Litium.Accelerator.Search.Indexing
    public class IndexDocumentTagImagesFieldDecorator: IIndexFieldDocumentTagsConverter
        private IIndexFieldDocumentTagsConverter _parent;
        private readonly FileService _fileService;


        public IndexDocumentTagImagesFieldDecorator(IIndexFieldDocumentTagsConverter parent, FileService fileService)
            _parent = parent; 
            _fileService = fileService;


        public ICollection<DocumentTag> ConvertToIndexDocumentTags(IndexFieldTypeConverterArgs arg, object value)
            if (arg.FieldDefinition.Id.Equals(SystemFieldDefinitionConstants.Images, StringComparison.OrdinalIgnoreCase))
                return ConvertToImagesIndexDocumentTags(arg, value);
            return _parent.ConvertToIndexDocumentTags(arg, value);


        public ICollection<DocumentTag> ConvertToImagesIndexDocumentTags(IndexFieldTypeConverterArgs arg, object item) 
            var result = new List<DocumentTag>();
            if (item == null)
                return result;


            var tagName = TagNames.GetTagNameForProperty(arg.FieldDefinition.Id);


            foreach (var value in (IList<Guid>)item)
                    ? new DocumentTag(TagNames.AppendLanguage(tagName, arg.CultureInfo), value) { TermVector = true, Readable = true }
                    : new DocumentTag(tagName, value) { TermVector = true, Readable = true });


                if (ModuleMediaArchive.ExistsInstance)
                    var file = _fileService.Get(value);
                    if (file != null && file.BlobUri != null)
                        result.Add(new DocumentTag(TagNames.FileId, file.SystemId) { Analyzed = true });


            return result;

Thank you! Can you explain how this implementation differs from the default implementation?

Yes, 2 lines of code missing.

result.Add(new DocumentTag(TagNames.Body, file.FileName) { Analyzed = true });
result.Add(new DocumentTag(TagNames.Body, Path.GetFileNameWithoutExtension(file.FileName)) { Analyzed = true });

Thank you very much!

1 Like

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