Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 459 posts 1602 karma points
    May 13, 2021 @ 10:35
    Adriano Fabri
    0

    How to rebuild custom examine index programmatically (Umbraco 8)

    Hi to all, I created a custom examine members index and it works fine...but I realized that when I create a new member (programmatically) it doesn't update automatically.

    There is a way to force the rebuild each time a new member is created (or updated) programmatically?

    Thanks

    Adriano

  • Adriano Fabri 459 posts 1602 karma points
    May 31, 2021 @ 13:46
    Adriano Fabri
    0

    A little update...after some tests, I saw that new member Exist in the examin index, because if I try to search him in Examine Management (backoffice), I found him. So the problem is only in frontend. I have a page to search colleagues and I don't find any of the new members. I can find them only after a rebuild of my custom index.

    Any idea?

  • Adriano Fabri 459 posts 1602 karma points
    Jun 01, 2021 @ 11:19
    Adriano Fabri
    100

    SOLVED

    I had to modify my Custom Index Creator as follows.

    Now I have my custom index always updated.

    Adriano

    using Examine;
    using Lucene.Net.Analysis.Standard;
    using Lucene.Net.Util;
    using System.Collections.Generic;
    using Umbraco.Core.Logging;
    using Umbraco.Core.Services;
    using Umbraco.Examine;
    using Umbraco.Web.Search;
    
    namespace AF.Examine.Index.Tools.For.UmbracoV8.Creators
    {
        public class AFMembersIndexCreator : UmbracoIndexesCreator
        {
            private readonly IProfilingLogger _profilingLogger;
            private readonly ILocalizationService _languageService;
            private readonly IPublicAccessService _publicAccessService;
            private readonly IMemberService _memberService;
            private readonly IUmbracoIndexConfig _iUmbracoIndexConfig;
    
            // Since Umbraco 8 has dependency injection out of the box, we can use it to inject
            // the different services that we need.
            public AFMembersIndexCreator(IProfilingLogger profilingLogger, 
                                            ILocalizationService languageService, 
                                            IPublicAccessService publicAccessService, 
                                            IMemberService memberService, 
                                            IUmbracoIndexConfig umbracoIndexConfig) : base(profilingLogger, languageService, publicAccessService, memberService, umbracoIndexConfig)
            {
                _profilingLogger = profilingLogger;
                _languageService = languageService;
                _publicAccessService = publicAccessService;
                _memberService = memberService;
                _iUmbracoIndexConfig = umbracoIndexConfig;
            }
    
            // Noticed that we return a collection of indexes? Technically you
            // can create multiple indexes in an indexCreator :) You can have a look at
            // UmbracoIndexesCreator.cs in the CMS core and see how the CMS does that.
            public override IEnumerable<IIndex> Create()
            {
                // create my AFMembersIndex definitions
                return new[] { CreateAFMembersIndex() };
            }
    
            private IIndex CreateAFMembersIndex()
            {
                var AFMembersIndex = new UmbracoMemberIndex(
                                                        "AFMembersIndex",
                                                        new FieldDefinitionCollection(
                                                            new FieldDefinition("memberId", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberNodeName", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberLoginName", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberEmail", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberName", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberSurname", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberIntTel", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberFax", FieldDefinitionTypes.FullText),
                                                            new FieldDefinition("memberCel", FieldDefinitionTypes.FullText)
                                                        ),
                                                        CreateFileSystemLuceneDirectory("AFMembersIndex"),
                                                        new StandardAnalyzer(Version.LUCENE_30),
                                                        ProfilingLogger,
                                                        UmbracoIndexConfig.GetMemberValueSetValidator());
    
                return AFMembersIndex;
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft