Copied to clipboard

Flag this post as spam?

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


  • Jan Kees Velthoven 25 posts 46 karma points
    Oct 26, 2010 @ 10:35
    Jan Kees Velthoven
    0

    Extending Examine by canceling the GatheringNodeData event

    I'm working on a project that is using Umbraco containing two websites. I want to make a search for one of the sites that is not indexing the other website. I've created the extension showed below.

    1. On the GatherNodeData event my extension comes in
    2. I check if I'm dealing with Content and if the path attibute is present
    3. With my custom Helper I only check if the NodeTypeAlias name mathes "CorporateHome" in the path
    4. If it isn't I cancel the event

    Here comes the big question:

    When I cancel the GatherNodeData event is this only for the current node or the whole proces of indexing?

        public class CancelIndexerOnNonCorporateContent : ApplicationBase
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="CancelIndexerOnWoningWebsite"/> class.
            /// </summary>
            public CancelIndexerOnNonCorporateContent()
            {
                ExamineManager.Instance.IndexProviderCollection["CorporateContentIndexer"].GatheringNodeData +=
                    CancelIndexerOnNonCorporateContent_GatheringNodeData;
            }

            /// <summary>
            /// Handles the GatheringNodeData event of the CancelIndexerOnNonCorporateContent control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="Examine.IndexingNodeDataEventArgs"/> instance containing the event data.</param>
            private void CancelIndexerOnNonCorporateContent_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
                if (e.IndexType == "Content" && e.Node.Attribute("path") != null)
                {
                    string[] pathIds = e.Node.Attribute("path").Value.Split(',');
                    bool isInCorporatePath =
                        pathIds.Where(i => UmbracoHelper.GetNodeTypeAlias(Convert.ToInt32(i)) == "CorporateHome").Any();

                    if (!isInCorporatePath)
                    {
                        e.Cancel = true;
                    }
                }
            }
        }

     

Please Sign in or register to post replies

Write your reply to:

Draft