예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="indexerName">Name of the indexer for which this DocumentWriting event is being executed on</param>
        private static void DocumentWriting(object sender, DocumentWritingEventArgs e, string indexerName)
        {
            IPublishedContent publishedContent = null;

            var indexerConfiguration = LookService.GetIndexerConfiguration(indexerName);

            if (indexerConfiguration.ShouldIndexContent) // attempt to get content
            {
                publishedContent = LookService.Instance._umbracoHelper.TypedContent(e.NodeId);
            }

            if (publishedContent == null && indexerConfiguration.ShouldIndexMedia) // attempt to get as media
            {
                publishedContent = LookService.Instance._umbracoHelper.TypedMedia(e.NodeId);
            }

            if (publishedContent == null && indexerConfiguration.ShouldIndexMembers) // attempt to get as member
            {
                publishedContent = LookService.Instance._umbracoHelper.SafeTypedMember(e.NodeId);
            }

            if (publishedContent != null)
            {
                var indexingContext = new IndexingContext(null, publishedContent, indexerName);

                LookService.EnsureContext();

                LookService.Index(indexingContext, e.Document);
            }
        }
예제 #2
0
 /// <summary>
 /// Get the BeforeIndexing method for a specifed index
 /// </summary>
 /// <param name="indexerName"></param>
 /// <returns></returns>
 internal static Action <IndexingContext> GetBeforeIndexing(string indexerName)
 {
     return(LookService.GetIndexerConfiguration(indexerName).BeforeIndexing  // indexer specific
            ?? new Action <IndexingContext>(x => { }));                      // not set
 }
 internal static Func <IndexingContext, DateTime?> GetDateIndexer(string indexerName)
 {
     return(LookService.GetIndexerConfiguration(indexerName).DateIndexer
            ?? LookService.Instance._defaultDateIndexer);
 }
 internal static Func <IndexingContext, string> GetTextIndexer(string indexerName)
 {
     return(LookService.GetIndexerConfiguration(indexerName).TextIndexer
            ?? LookService.Instance._defaultTextIndexer);
 }
        /// <summary>
        ///  Do the indexing and set the field values onto the Lucene document
        /// </summary>
        /// <param name="indexingContext"></param>
        /// <param name="document"></param>
        internal static void Index(IndexingContext indexingContext, Document document)
        {
            var indexerConfiguration = LookService.GetIndexerConfiguration(indexingContext.IndexerName);

            if (!indexerConfiguration.ShouldIndexAlias(indexingContext.Item?.DocumentTypeAlias))
            {
                indexingContext.Cancel();
                return;
            }

            var stopwatch = Stopwatch.StartNew();

            try
            {
                LookService.GetBeforeIndexing()(indexingContext);
            }
            catch (Exception exception)
            {
                LogHelper.WarnWithException(typeof(LookService), "Error in global BeforeIndexing", exception);
            }

            try
            {
                LookService.GetBeforeIndexing(indexingContext.IndexerName)(indexingContext);
            }
            catch (Exception exception)
            {
                LogHelper.WarnWithException(typeof(LookService), "Error in indexer BeforeIndexing", exception);
            }

            LookService.IndexNode(indexingContext, document);

            LookService.IndexName(indexingContext, document);

            LookService.IndexDate(indexingContext, document);

            LookService.IndexText(indexingContext, document);

            LookService.IndexTags(indexingContext, document);

            LookService.IndexLocation(indexingContext, document);

            try
            {
                LookService.GetAfterIndexing(indexingContext.IndexerName)(indexingContext);
            }
            catch (Exception exception)
            {
                LogHelper.WarnWithException(typeof(LookService), "Error in indexer AfterIndexing", exception);
            }

            try
            {
                LookService.GetAfterIndexing()(indexingContext);
            }
            catch (Exception exception)
            {
                LogHelper.WarnWithException(typeof(LookService), "Error in global AfterIndexing", exception);
            }

            stopwatch.Stop();

            if (!indexingContext.Cancelled)
            {
                LogHelper.Debug(typeof(LookService), () => $"Building Lucene Document for Id='{indexingContext.Item.Id}', Key='{indexingContext.Item.GetGuidKey()}', Name='{indexingContext.Item.Name}' in Index '{ indexingContext.IndexerName }' Took { stopwatch.ElapsedMilliseconds }ms");
            }
        }
 /// <summary>
 /// Get indexer specific AfterIndexing
 /// </summary>
 /// <param name="indexerName"></param>
 /// <returns></returns>
 internal static Action <IndexingContext> GetAfterIndexing(string indexerName)
 {
     return(LookService.GetIndexerConfiguration(indexerName).AfterIndexing
            ?? new Action <IndexingContext>(x => { }));
 }