private async Task IndexLanguageVersions(ContentReference contentReference, IndexContentRequest indexContentRequest) { foreach (var languageVersion in _contentLoader.GetAllLanguageVersions(contentReference).Where(c => c.ShouldIndexPage())) { indexContentRequest.OnStatusChanged($"Indexing content: Name: {languageVersion.Name}, ContentLinkId: {languageVersion.ContentLink.ID}"); var contentDocument = _documentBuilder.Build(languageVersion); await _azureSearchService.IndexAsync(contentDocument); } }
public override string Execute() { var stopWatch = Stopwatch.StartNew(); var jobStartTime = DateTimeOffset.UtcNow; OnStatusChanged("Ensuring valid index definition"); var(updateOrRecreateResult, recreationReason) = _indexDefinitionHandler.UpdateOrRecreateIndex().GetAwaiter().GetResult(); var message = $"UpdateOrRecreateIndexResult: {updateOrRecreateResult}{NewLine}"; if (updateOrRecreateResult == UpdateOrRecreateResult.Recreated) { message += $"Recreation reason: {recreationReason}{NewLine}"; } var indexContentRequest = new IndexContentRequest { CancellationToken = _cancellationToken, OnStatusChanged = OnStatusChanged, IgnoreContent = new HashSet <ContentReference> { ContentReference.WasteBasket }, VisitedContent = new HashSet <ContentReference>(), Statistics = new IndexStatistics(), }; OnStatusChanged("Indexing content start..."); _contentIndexer.Index(ContentReference.RootPage, indexContentRequest).GetAwaiter().GetResult(); var exceptionsThresholdReached = indexContentRequest.Statistics.Exceptions.Count >= indexContentRequest.ExceptionThreshold; if (exceptionsThresholdReached) { message += "Exceptions threshold reached. " + $"Exceptions: {string.Join(NewLine + NewLine, indexContentRequest.Statistics.Exceptions)}{NewLine}{NewLine}" + $"Failed for content references: {string.Join(",", indexContentRequest.Statistics.FailedContentReferences)}"; throw new ScheduledJobFailedException(message); } if (!_cancellationToken.IsCancellationRequested) { OnStatusChanged("Clearing outdated items..."); _indexGarbageCollector.RemoveOutdatedContent(jobStartTime, indexContentRequest.Statistics.FailedContentReferences).GetAwaiter().GetResult(); } stopWatch.Stop(); message += $"Content has been indexed. Visited content count: {indexContentRequest.VisitedContent.Count}, Time taken: {stopWatch.Elapsed}"; return(message); }
public async Task Index(ContentReference rootContentLink, IndexContentRequest indexContentRequest) { if (indexContentRequest.CancellationToken.IsCancellationRequested) { return; } if (indexContentRequest.IgnoreContent.Contains(rootContentLink)) { return; } if (indexContentRequest.VisitedContent.Contains(rootContentLink)) { return; } if (indexContentRequest.Statistics.Exceptions.Count >= indexContentRequest.ExceptionThreshold) { return; } try { await IndexLanguageVersions(rootContentLink, indexContentRequest); indexContentRequest.VisitedContent.Add(rootContentLink); } catch (Exception e) { indexContentRequest.Statistics.FailedContentReferences.Add(rootContentLink); indexContentRequest.Statistics.Exceptions.Add(e); } var children = _contentLoader.GetChildren <PageData>(rootContentLink); foreach (var child in children) { await Index(child.ContentLink, indexContentRequest); } }