Thursday 18 July 2013

Add information about published node to search Umbraco


I needed to add information about published node to search Umbraco. You can do it as follows:


 Examine settings for my code:

Make sure that your indexer does allow

 <add name="AutoCompleteLookupIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
          analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />



in [ExamineIndex.config]

Code:



public class ExamineEvents : ApplicationBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ExamineEvents"/> class.
        /// </summary>
        public ExamineEvents()
        {
            // hookup to application
            ExamineManager.Instance.IndexProviderCollection[ExamineIndexers.AutoCompleteLookupIndexer.Name()].GatheringNodeData +=
                InternalExamineEvents_GatheringNodeData;
        }

        /// <summary>
        /// Handles the GatheringNodeData event of the InternalExamineEvents control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="IndexingNodeDataEventArgs"/> instance containing the event data.</param>
        void InternalExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.IndexType != IndexTypes.Content) return;

            var node = uQuery.GetNode(e.NodeId);
           
            e.Fields.Add("isPublished", node==null?Boolean.TrueString:Boolean.FalseString);
        }
    }


in [your file]

No comments:

Post a Comment