예제 #1
0
 public void Process(RelatedContentTagArgs args)
 {
     foreach (IRelatedItemsTagger <Item> tagger in args.Configuration.Taggers)
     {
         tagger.TagContent(args.ContentItem, args.RelatedItems);
     }
 }
예제 #2
0
        public void Process(RelatedContentTagArgs args)
        {
            var taggableContentList = new List <RelatedTaggableContent>();

            if (args.Content != null && args.Content.Any())
            {
                taggableContentList.AddRange(args.Content);
            }
            foreach (IContentProvider <Item> contentProvider in args.Configuration.ContentProviders)
            {
                var dataSoutceItems = args.ContentItem.GetDataSourceItems();
                foreach (var item in dataSoutceItems)
                {
                    var content = (StringContent)contentProvider.GetContent(item);

                    if (!string.IsNullOrEmpty(content.Content) && !string.IsNullOrEmpty(content.Content.Trim()))
                    {
                        taggableContentList.Add(new RelatedTaggableContent
                        {
                            Content = content.Content
                        });
                    }
                }
            }

            if (taggableContentList.Count == 0)
            {
                MessageBus messageBus = args.MessageBus;
                if (messageBus != null)
                {
                    messageBus.SendMessage(new Message
                    {
                        Body  = $"Item {args.ContentItem.Name} contains no content.",
                        Level = MessageLevel.Info
                    });
                }
                args.AbortPipeline();
            }
            else
            {
                args.Content = taggableContentList;
            }
        }
예제 #3
0
        public void Process(RelatedContentTagArgs args)
        {
            var relatedItemsList = new List <Guid>();
            IRelatedItemsDiscoveryProvider discoveryProvider = args.Configuration.DiscoveryProvider;

            try
            {
                Sitecore.Data.Fields.MultilistField relatedTemplates = args.ContentItem.Fields[Constants.Fields.RetatedTemplates];
                var relatedTemplatesIds = relatedTemplates.TargetIDs.Select(x => x.Guid);
                int.TryParse(args.ContentItem.Fields[Constants.Fields.Similarity].Value, out var similarity);
                IEnumerable <Guid> items = discoveryProvider.GetRelatedItems(args.ContentItem.ID.Guid, relatedTemplatesIds, similarity);

                if (items == null || !items.Any())
                {
                    var        message    = $"No related items find for {args.ContentItem.Name}";
                    MessageBus messageBus = args.MessageBus;
                    messageBus?.SendMessage(new Message
                    {
                        Body  = message,
                        Level = MessageLevel.Info
                    });
                    Log.Warn(message, this);
                    args.AbortPipeline();
                }
                else
                {
                    relatedItemsList.AddRange(items);
                }
            }
            catch (Exception ex)
            {
                string     message    = "An error occured in " + discoveryProvider.GetType().Name + " provider";
                MessageBus messageBus = args.MessageBus;
                messageBus?.SendMessage(new Message
                {
                    Body  = message,
                    Level = MessageLevel.Error
                });
                Log.Error(message, ex, this);
            }
            args.RelatedItems = relatedItemsList;
        }
예제 #4
0
        public void Process(RelatedContentTagArgs args)
        {
            IRelatedItemsDiscoveryProvider discoveryProvider = args.Configuration.DiscoveryProvider;

            try
            {
                var content = string.Join(" ", args.Content.Select(x => x.Content));

                if (string.IsNullOrEmpty(content) || string.IsNullOrWhiteSpace(content))
                {
                    MessageBus messageBus = args.MessageBus;
                    if (messageBus != null)
                    {
                        messageBus.SendMessage(new Message
                        {
                            Body  = $"Item {args.ContentItem.Name} contains no content.",
                            Level = MessageLevel.Warning
                        });
                    }
                    args.AbortPipeline();
                }

                args.Vector = discoveryProvider.GetVector(content);
            }
            catch (Exception ex)
            {
                string     message    = "An error occured in " + discoveryProvider.GetType().Name + " provider";
                MessageBus messageBus = args.MessageBus;
                if (messageBus != null)
                {
                    messageBus.SendMessage(new Message
                    {
                        Body  = message,
                        Level = MessageLevel.Error
                    });
                }
                Log.Error(message, ex, (object)this);
            }
        }
예제 #5
0
        public void Process(RelatedContentTagArgs args)
        {
            NormalizeContentArgs normalizeContentArgs = new NormalizeContentArgs
            {
                Content    = args.Content,
                MessageBus = args.MessageBus
            };

            this.PipelineManager.Run("normalizeContent", normalizeContentArgs, "RealtedContentTagging");

            var list = new List <RelatedTaggableContent>();

            foreach (RelatedTaggableContent content in normalizeContentArgs.Content)
            {
                list.Add(new RelatedTaggableContent {
                    Content = content.Content
                });
            }

            if (list.Count == 0)
            {
                MessageBus messageBus = args.MessageBus;
                if (messageBus != null)
                {
                    messageBus.SendMessage(new Message
                    {
                        Body  = $"Item {args.ContentItem.Name} contains no content.",
                        Level = MessageLevel.Info
                    });
                }
                args.AbortPipeline();
            }
            else
            {
                args.Content = list;
            }
        }