public override IEnumerable <(CultureInfo, IDocument)> BuildIndexDocuments(IndexQueueItem item)
        {
            var page = _pageService.Get(item.SystemId);

            if (page == null)
            {
                yield break;
            }

            var cultureContentCache = new ConcurrentDictionary <CultureInfo, ISet <string> >();
            var permissions         = _searchPermissionService.GetPermissions(page);
            var blocks  = page.Blocks.Items.SelectMany(x => x.Items).Select(y => _blockService.Get(((BlockItemLink)y).BlockSystemId)).ToList();
            var isBrand = false;
            var isNews  = false;

            if (_keyLookupService.TryGetId <PageFieldTemplate>(page.FieldTemplateSystemId, out var templateId))
            {
                isBrand = PageTemplateNameConstants.Brand.Equals(templateId, StringComparison.OrdinalIgnoreCase);
                isNews  = PageTemplateNameConstants.News.Equals(templateId, StringComparison.OrdinalIgnoreCase);
            }

            foreach (var channelLink in page.ChannelLinks)
            {
                var channel = _channelService.Get(channelLink.ChannelSystemId);
                if (channel is null)
                {
                    // Orphaned category link exists, skip to create new index document.
                    continue;
                }

                var cultureInfo = _languageService.Get(channel.WebsiteLanguageSystemId.GetValueOrDefault())?.CultureInfo;
                if (cultureInfo is null)
                {
                    // Channel does not have a culture.
                    continue;
                }

                var localization = page.Localizations[cultureInfo];
                yield return(cultureInfo, new PageDocument
                {
                    PageSystemId = page.SystemId,
                    Content = cultureContentCache.GetOrAdd(cultureInfo, _ => _contentBuilderService.BuildContent <PageFieldTemplate, WebsiteArea>(page.FieldTemplateSystemId, cultureInfo, page.Fields)),
                    PublishDateTime = page.PublishedAtUtc ?? DateTimeOffset.MinValue,
                    Name = localization.Name,
                    ChannelSystemId = channel.SystemId,
                    WebsiteSystemId = page.WebsiteSystemId,
                    ChannelStartDateTime = channelLink.StartDateTimeUtc ?? DateTimeOffset.MinValue,
                    ChannelEndDateTime = channelLink.EndDateTimeUtc ?? DateTimeOffset.MaxValue,
                    Permissions = permissions,
                    Blocks = GetBlocks(blocks, cultureInfo, channel.SystemId),
                    IsBrand = isBrand,
                    IsNews = isNews,
                    NewsDate = isNews ? page.Fields.GetValue <DateTimeOffset>(PageFieldNameConstants.NewsDate) : DateTimeOffset.MinValue,
                    ParentPages = GetParenPages(page)
                });
            }
        }
Example #2
0
        public override IEnumerable <(CultureInfo, IDocument)> BuildIndexDocuments(IndexQueueItem item)
        {
            var category = _categoryService.Get(item.SystemId);

            if (category == null)
            {
                yield break;
            }

            var cultureContentCache = new ConcurrentDictionary <CultureInfo, ISet <string> >();
            var permissions         = _searchPermissionService.GetPermissions(category);

            foreach (var channelLink in category.ChannelLinks)
            {
                var channel = _channelService.Get(channelLink.ChannelSystemId);
                if (channel is null)
                {
                    // Orphaned category link exists, skip to create new index document.
                    continue;
                }

                var cultureInfo = _languageService.Get(channel.WebsiteLanguageSystemId.GetValueOrDefault())?.CultureInfo;
                if (cultureInfo is null)
                {
                    // Channel does not have a culture.
                    continue;
                }

                var localization = category.Localizations[cultureInfo];
                yield return(cultureInfo, new CategoryDocument
                {
                    CategorySystemId = category.SystemId,
                    Content = cultureContentCache.GetOrAdd(cultureInfo, _ => _contentBuilderService.BuildContent <CategoryFieldTemplate, ProductArea>(category.FieldTemplateSystemId, cultureInfo, category.Fields)),
                    Name = localization.Name,
                    ChannelSystemId = channel.SystemId,
                    Permissions = permissions,
                    Assortment = category.AssortmentSystemId,
                    Organizations = category.Fields.GetValue <IList <PointerItem> >(ProductFieldNameConstants.OrganizationsPointer)?.Select(x => x.EntitySystemId).ToHashSet()
                                    ?? new HashSet <Guid> {
                        Guid.Empty
                    }
                });
            }
        }