Copied to clipboard

Flag this post as spam?

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


  • Louis Jackson-Rees 89 posts 313 karma points c-trib
    24 days ago
    Louis Jackson-Rees
    0

    Umbraco 8 Examine Indexes

    Anyone got any examples or code i can take a look at for implementing a custom index set / searcher

  • Seb Smith 1 post 20 karma points
    24 days ago
    Seb Smith
    0

    I was just about to ask this as well. In the previous version I added custom indexers using ExamineSettings.config. Is there a different way now?

    Thanks in advance

    Seb

  • Ole Martin Bakke 107 posts 615 karma points
    18 days ago
    Ole Martin Bakke
    0

    Did you find any examples? Need to create a custom index set without all doc.types.

  • Louis Jackson-Rees 89 posts 313 karma points c-trib
    18 days ago
    Louis Jackson-Rees
    0

    Unfortunately not, no

  • Ole Martin Bakke 107 posts 615 karma points
    18 days ago
    Ole Martin Bakke
    102

    By looking at det core-code, I managed to get something working, but I do not know if I am on the right track here. I seems a bit like killing mosquitos with a canon, comparet to the old config-files.

    I created my own "CustomIndexCreator"-class, registered it as a composer and the created a component adding the index to the Examine-manager.

    public class CustomIndexCreator : LuceneIndexCreator, IUmbracoIndexesCreator
    {
    
        public CustomIndexCreator(IProfilingLogger profilingLogger,
            ILocalizationService languageService)
        {
            ProfilingLogger = profilingLogger ?? throw new System.ArgumentNullException(nameof(profilingLogger));
            LanguageService = languageService ?? throw new System.ArgumentNullException(nameof(languageService));
        }
    
        protected IProfilingLogger ProfilingLogger { get; }
        protected ILocalizationService LanguageService { get; }
    
        public override IEnumerable<IIndex> Create()
        {
            return new[]
            {
                CreateCustomIndex()
            };
    
        }
    
        private IIndex CreateCustomIndex()
        {
            var index = new UmbracoContentIndex(
                "CustomIndex",
                CreateFileSystemLuceneDirectory("Custom"),
                new UmbracoFieldDefinitionCollection(),
                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
                ProfilingLogger,
                LanguageService,
                new ContentValueSetValidator(true, excludeItemTypes: new string[] { "DocTypeAliasToExclude",}));
            return index;
        }
    
    }
    

    The composer

     [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class CustomExamineComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Register(typeof(CustomIndexCreator));
            composition.Components().Append<CustomExamineComponent>();
        }
    }
    

    And the component

    public class CustomExamineComponent : IComponent
    {
        private readonly IExamineManager _examineManager;
        private readonly CustomIndexCreator _indexCreator;
    
        public CustomExamineComponent(IExamineManager examineManager, CustomIndexCreator indexCreator)
        {
            _examineManager = examineManager;
            _indexCreator = indexCreator;
        }
    
    
        public void Initialize()
        {
    
            foreach (var index in _indexCreator.Create())
                _examineManager.AddIndex(index);
    
        }
    
    
        public void Terminate()
        {
    
        }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft