Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Jan 09, 2014 @ 14:48
    Dan
    0

    Examine event not firing to implement GatheringNodeData in 6.1

    Hi,

    I've hit a snag when debugging some custom Lucene searches on a site.

    There are some multi-node tree picker ids which need to be written out as node names and included as a custom Examine field, called 'relationData'. Having installed Examine Inspector I see this field in the index but it's currently not containing any data, so it would appear that the examine event is not firing.

    The class I have been using to do this I notice is marked as obsolete, so instead I've updated the code to the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    using System.Text;
    using System.Xml.Linq;
    using Examine;
    using umbraco.BusinessLogic;
    using UmbracoExamine;
    using umbraco.NodeFactory;
    using umbraco.interfaces;
    using Umbraco.Core;
    
    
    namespace Client.Utilities
    {
        public class ExamineEvents : IApplicationEventHandler
        {
            public ExamineEvents()
            {
                ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += this.IndexLocations_GatheringNodeData;
            }
    
            private void IndexLocations_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
                if (e.IndexType == IndexTypes.Content)
                {
                    var fields = e.Fields;
                    var combinedFields = new StringBuilder();
                    foreach (var keyValuePair in fields)
                    {
                        string propertyAlias = keyValuePair.Key;
                        switch (propertyAlias)
                        {
                            case "category":
                                var categories = keyValuePair.Value.Split(',');
                                foreach (string categoryId in categories)
                                {
                                    var node = new Node(Convert.ToInt32(categoryId));
                                    combinedFields.AppendLine(node.Name);
                                };
                                break;
                            case "tags":
                                var tags = keyValuePair.Value.Split(',');
                                foreach (string tag in tags)
                                {
                                    combinedFields.AppendLine(tag);
                                };
                                break;
                        }
                    }
                    e.Fields.Add("relationData", combinedFields.ToString());
                }
            }
        }
    }
    

    ...however I now get build errors:

    "Client.Utilities.ExamineEvents does not implement interface member umbraco.core.iapplicationeventhandler.onapplicationstarted"
    
    "Client.Utilities.ExamineEvents does not implement interface member umbraco.core.iapplicationeventhandler.onapplicationstarting"
    
    "Client.Utilities.ExamineEvents does not implement interface member umbraco.core.iapplicationeventhandler.onapplicationinitialized"
    

    This is all a bit over my head, so I wondered if anyone could shed any light on how to resolve this?

    Many thanks folks.

    EDIT:

    I've seen a note in the documentation which suggests that some other methods need to be implemented as it's an interface, so I've added:

    public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
    }
    
    public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
    }
    
    public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
    }
    

    ... but this doesn't seem to make any difference.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jan 09, 2014 @ 20:43
    Andy Butland
    0

    Hi Dan

    Because you are implementing an interface - IApplicationEventHandler - you need to implement all methods, so that's why you need to add those 3 methods to your class in order to get the project to build.

    Having done that I think if you move this line of code...

    ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData+=this.IndexLocations_GatheringNodeData;

    ... to the method OnApplicationStarted then it should start to fire.

    Hope that helps.

    Andy

  • Dan 1288 posts 3921 karma points c-trib
    Jan 09, 2014 @ 23:24
    Dan
    0

    Thanks Andy, but it gives the same 3 build errors. Incidentally, there's a blue line on the word 'ExamineEvents' on this line: public class ExamineEvents : IApplicationEventHandler, with the message:

    'Client.Utilities.ExamineEvents' does not implement interface member 'Umbraco.Core.IApplicationEventHandler.OnApplicationInitialized(Umbraco.Core.UmbracoApplicationBase, Umbraco.Core.ApplicationContext)'
    

    Any ideas?

    (Incidentally, this is Umbraco 6.1.6.)

    Thanks

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jan 10, 2014 @ 09:40
    Andy Butland
    0

    Doesn't look to me that you can have added those three methods to the class if you are still getting that build error.  If you want to post the whole code you have for your ExamineEvents class I can have another look if you like?

  • Rick 92 posts 278 karma points
    Apr 02, 2014 @ 10:16
    Rick
    0

    Hi,

    I had the exact same issues as the OP however, I changed the following:

    publicvoidOnApplicationInitialized(UmbracoApplication httpApplication,ApplicationContext applicationContext)
    {
    }

    publicvoidOnApplicationStarting(UmbracoApplication httpApplication,ApplicationContext applicationContext)
    {
    }

    publicvoidOnApplicationStarted(UmbracoApplication httpApplication,ApplicationContext applicationContext)
    {
    }

    to 

    publicvoidOnApplicationInitialized(UmbracoApplicationBase httpApplication,ApplicationContext applicationContext)
    {
    }

    publicvoidOnApplicationStarting(UmbracoApplicationBase httpApplication,ApplicationContext applicationContext)
    {
    }

    publicvoidOnApplicationStarted(UmbracoApplicationBase httpApplication,ApplicationContext applicationContext)
    {
    }

    I then registered the following:
    ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData+=this.IndexLocations_GatheringNodeData; 

    inside the OnApplicationStarted method and kept the rest of the code exactly the same!

    Hope this helps you out Mr. OP as your post helped me!

    Thanks,
    Rick

Please Sign in or register to post replies

Write your reply to:

Draft