Copied to clipboard

Flag this post as spam?

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


  • Remko 92 posts 243 karma points
    Mar 11, 2019 @ 14:10
    Remko
    0

    v8 - ExamineManager - GatheringNodeData how to, with latest Examine

    We used to do this (to add some extra data to Examine index for certain nodes)

      ExamineManager.Instance..IndexProviderCollection[defaultIndexIndexer].GatheringNodeData += IndexHandler_GatheringNodeData;
    

    Now this doesn't seem to work anymore. IndexProviderCollection isn't available.. Is there any other way to init this event ?

  • Marc Goodson 1174 posts 7866 karma points MVP 5x c-trib
    Mar 11, 2019 @ 22:34
    Marc Goodson
    0

    Hi Remko

    GatheringNodeData has been removed/consolidated in the version of Examine shipped with V8

    The event you want to handle instead is 'TransformingIndexValues' event

    you can see this in the source code:

       /// <summary>
            /// Raised before the item is indexed allowing developers to customize the data that get's stored in the index
            /// </summary>
            public event EventHandler<IndexingItemEventArgs> TransformingIndexValues;
      /// <summary>
            /// Raises the <see cref="E:TransformingIndexValues"/> event.
            /// </summary>
            /// <param name="e">The <see cref="IndexingItemEventArgs"/> instance containing the event data.</param>
            protected virtual void OnTransformingIndexValues(IndexingItemEventArgs e)
            {
                TransformingIndexValues?.Invoke(this, e);
            }
    

    which is available here:

    https://github.com/Shazwazza/Examine/blob/864168c7f019908242dd56197e075edea5ee77cf/src/Examine/Providers/BaseIndexProvider.cs

    Not seen any examples yet, but hopefully that's a good steer.

    regards

    Marc

  • Remko 92 posts 243 karma points
    Mar 12, 2019 @ 08:58
    Remko
    0

    Ok, that makes sense, thank you.

    Now I only need to know how to get the instance of the IndexProvider (for ExternalIndex) to attach the event... Since there isn't an IndexProviderCollection in ExamineManager.Instance, can you tell me where I can find it nowadays?

  • Marc Goodson 1174 posts 7866 karma points MVP 5x c-trib
    Mar 12, 2019 @ 11:54
    Marc Goodson
    1

    Hi Remko

    It's a bit of a guess, but essentially everything is injected via DI in Umbraco V8...

    So to get a reference to the Examine Manager you need to add it to the constructor for your Component, and it will be magically injected in, the Examine Manager has a list of indexes, if you pull the one you want to handle the event for and cast it to a BaseIndexProvider then that should expose the TransformingIndexValues event...

    but I'm only guessing from the source and intellisense!

    namespace Umbraco8.Components
    {
        [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
        public class RegisterExamineEventComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                // Append our component to the collection of Components
                // It will be the last one to be run
                composition.Components().Append<RegisterExamineEventsComponent>();
            }
        }
        public class RegisterExamineEventsComponent : IComponent
        {
            private readonly IExamineManager _examineManager;
            public RegisterExamineEventsComponent(IExamineManager examineManager)
            {
                _examineManager = examineManager;
    
            }
            public void Initialize()
            {
    
                var externalIndex = _examineManager.Indexes.Where(f => f.Name == "ExternalIndex");
                ((BaseIndexProvider)externalIndex).TransformingIndexValues += TreeNodesRenderingComponent_TransformingIndexValues;
            }
    
            private void UmbracoExamineIndex_TransformingIndexValues(IndexingItemEventArgs e)
            {
    // do stuff here with the index values like gathering nodedata did
            }
    }
    

    regards

    Marc

  • Remko 92 posts 243 karma points
    Mar 12, 2019 @ 14:51
    Remko
    0

    Great! Still don't really understand how objects are magically injected in IComponents, but it seems to work :-)

    Thank you.

  • Marc Goodson 1174 posts 7866 karma points MVP 5x c-trib
    Mar 12, 2019 @ 19:21
    Marc Goodson
    0

    Hi Remko

    it is dark magic I think...

    regards

    Marc

  • Laurent Lequenne 120 posts 245 karma points
    Nov 14, 2019 @ 17:15
    Laurent Lequenne
    0

    It's a mess... As we can not change how your field will be indexed (Analyzed, not, stored, not stored ?) ... So now I index tags... and there is nothing I can do with it... I don't want half tags to be found !

  • Simon steed 357 posts 665 karma points
    May 27, 2020 @ 12:37
    Simon steed
    0

    Any updates on how to achieve this now? Looking at migrating a V7 site over that uses GatheringNodeData and came across this post.

  • Simon steed 357 posts 665 karma points
    May 27, 2020 @ 12:39
    Simon steed
    0

    Appears Nik has already answered this one so adding here for completeness :)

    https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/98612-examine-events

Please Sign in or register to post replies

Write your reply to:

Draft