Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Laurent Lequenne 122 posts 247 karma points
    Aug 10, 2021 @ 15:37
    Laurent Lequenne
    0

    Custom indexers failing at boot

    for version 8.13.1

    We have a custom table that we would like to index through Examine. There for I created a composition and a specific component.

    Which contains registration of an IndexCreator, an IndexPopulator and a IValueSetBuilder. The IndexPopulator registration throws an error at boot time.

    {"Unresolved dependency [Target Type: Umbraco.Web.Search.ExamineComponent], [Parameter: backgroundIndexRebuilder(Umbraco.Web.Search.BackgroundIndexRebuilder)], [Requested dependency: ServiceType:Umbraco.Web.Search.BackgroundIndexRebuilder, ServiceName:]"}

    Specifics The registration of StenopeIndexPopulator generates the boot failure. The registation of StenopeIndexCreators works, and my Index is effectively created.

    Steps to reproduce Create a component for custom table indexing

    using Examine;
    using Umbraco.Core;
    using Umbraco.Core.Composing;
    
    namespace Newsroom.Core.Startup.Composers.Stenope
    {
        public class StenopeIndexComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.RegisterUnique<StenopeIndexValueSetBuilder>();
                composition.Register<StenopeIndexPopulator>(Lifetime.Singleton);
                composition.RegisterUnique<StenopeIndexCreator>();
            }
        }
    
        public class StenopeIndexComponent : IComponent
        {
            private readonly IExamineManager _examineManager;
            private readonly StenopeIndexCreator _indexCreator;
    
            public StenopeIndexComponent(IExamineManager examineManager, StenopeIndexCreator indexCreator)
            {
                _examineManager = examineManager;
                _indexCreator = indexCreator;
            }
    
            public StenopeIndexCreator IndexCreator => _indexCreator;
    
            public void Initialize()
            {
                foreach (var index in IndexCreator.Create())
                    _examineManager.AddIndex(index);
            }
    
            public void Terminate()
            {
                _indexCreator.Dispose();
            }
        }
    }
    
    using Examine;
    using Examine.LuceneEngine.Providers;
    using Lucene.Net.Analysis.Standard;
    using Newsroom.Core.Interfaces.Services.Stenope;
    using Newsroom.Core.Models.Database;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Examine;
    using Umbraco.Web.Search;
    
    namespace Newsroom.Core.Startup.Composers.Stenope
    {
        public class StenopeIndexPopulator : IndexPopulator
        {
            private readonly StenopeIndexValueSetBuilder mediaBuilder;
            private readonly IStenopeMediaService mediaService;
    
            public StenopeIndexPopulator(StenopeIndexValueSetBuilder mediaBuilder, IStenopeMediaService mediaService)
            {
                this.mediaBuilder = mediaBuilder;
                this.mediaService = mediaService;
    
                RegisterIndex("StenopeIndex");
            }
    
            protected override void PopulateIndexes(IReadOnlyList<IIndex> indexes)
            {
                var medias = mediaService.GetAll();
                if (medias != null && medias.Any())
                {
                    foreach (var index in indexes)
                    {
                        index.IndexItems(mediaBuilder.GetValueSets(medias.ToArray()));
                    }
                }
            }
        }
    
        public class StenopeIndexCreator : LuceneIndexCreator, IUmbracoIndexesCreator, IDisposable
        {
            protected Lucene.Net.Store.Directory Directory { get; set; }
    
            public override IEnumerable<IIndex> Create()
            {
                Directory = CreateFileSystemLuceneDirectory("StenopeIndex");
                var index = new LuceneIndex("StenopeIndex",
                    Directory,
                    new FieldDefinitionCollection(
                        new FieldDefinition("caption", FieldDefinitionTypes.FullTextSortable),
                        new FieldDefinition("copyright", FieldDefinitionTypes.FullText)
                    ),
                    new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
    
                return new[] { index };
            }
    
            public void Dispose()
            {
                if (Directory != null)
                {
                    Directory.Dispose();
                }
            }
        }
    
        public class StenopeIndexValueSetBuilder : IValueSetBuilder<StenopeMedia>
        {
            public IEnumerable<ValueSet> GetValueSets(params StenopeMedia[] medias)
            {
                foreach (var media in medias)
                {
                    var indexValues = new Dictionary<string, object>
                    {
                        ["caption"] = media.Caption,
                        ["copyright"] = media.Copyright
                    };
    
                    var valueSet = new ValueSet(media.UniqueId.ToString(), "media", indexValues);
    
                    yield return valueSet;
                }
            }
        }
    
    }
    

    Expected result / actual result Looking into the Umbraco Code ExamineComposer, is registering all dependencies of the ExamineComponent. So that's how it should be, but I don'tknow what could interfere with the registration of my component, or I'm probably missing somehting that is not documented.

    To Sebastian Janssen : My IStenopeMediaService is registered... In another composer... So before closing tickets, maybe you can wait for an answer !

Please Sign in or register to post replies

Write your reply to:

Draft