private void RemoveMediaCore(IEnumerable <IMedia> media, EventMessages messages)
        {
            if (UmbracoSearchFactory.HasActiveIndex)
            {
                foreach (var item in media)
                {
                    try
                    {
                        var indexService = UmbracoSearchFactory.GetMediaIndexService(item);
                        var indexName    = UmbracoSearchFactory.ActiveIndexName;
                        if (indexService != null && indexService.ShouldIndex(item))
                        {
                            RemoveMedia(indexService, item, indexName);
                            if (item.IndexError())
                            {
                                throw new InvalidOperationException(item.GetIndexingStatus().Message);
                            }

                            messages?.Add(new EventMessage("Search", "Removed media from search index", EventMessageType.Success));
                            LogHelper.Debug(GetType(), () => $"Media ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been removed from search index");
                        }
                    }
                    catch (Exception ex)
                    {
                        messages?.Add(new EventMessage("Search", $"Unable to index media : '{item.Name}' => {ex.Message}", EventMessageType.Error));
                        LogHelper.WarnWithException(GetType(), $"Unable to index media ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}'", ex);
                    }
                }
            }
            else
            {
                messages?.Add(new EventMessage("Search", "No active index available for indexing", EventMessageType.Error));
                LogHelper.Warn(GetType(), "No active index available for indexing");
            }
        }
示例#2
0
        public void Build(string indexName)
        {
            var indexExists = UmbracoSearchFactory.Client.IndexExists(indexName)?.Exists ?? false;

            if (!indexExists)
            {
                throw new InvalidOperationException($"'{indexName}' not available, please ensure you have created an index with this name");
            }
            using (BusyStateManager.Start($"Building media for {indexName}", indexName))
            {
                LogHelper.Info <MediaIndexer>($"Started building index [{indexName}]");
                foreach (var indexService in UmbracoSearchFactory.GetMediaIndexServices())
                {
                    try
                    {
                        LogHelper.Info <MediaIndexer>($"Started to index media for {indexService.DocumentTypeName}");
                        BusyStateManager.UpdateMessage($"Indexing {indexService.DocumentTypeName}");
                        indexService.Build(indexName);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error <MediaIndexer>($"Failed to index media for {indexService.DocumentTypeName}", ex);
                    }
                }
                LogHelper.Info <MediaIndexer>(
                    $"Finished building index [{indexName}] : elapsed {BusyStateManager.Elapsed:g}");
            }
        }
        public IHttpActionResult ContentIndexServicesList()
        {
            var content = UmbracoSearchFactory.GetContentIndexServices();

            return(Ok(content.Select(x => new
            {
                x.DocumentTypeName,
                x.GetType().Name,
                Count = x.CountOfDocumentsForIndex(indexName)
            })));
        }
示例#4
0
        public async Task CreateAsync()
        {
            var newindexName = indexNameResolver.ResolveUniqueIndexName(UmbracoSearchFactory.ActiveIndexName);

            var result = await client.CreateIndexAsync(newindexName, WithCreateIndexDescriptorCore).ConfigureAwait(false);

            if (result.IsValid)
            {
                Parallel.ForEach(UmbracoSearchFactory.GetContentIndexServices(), c => c.UpdateIndexTypeMapping(newindexName));
                Parallel.ForEach(UmbracoSearchFactory.GetMediaIndexServices(), c => c.UpdateIndexTypeMapping(newindexName));
            }
        }
示例#5
0
        public void Create()
        {
            var newindexName = indexNameResolver.ResolveUniqueIndexName(UmbracoSearchFactory.ActiveIndexName);

            var result = client.CreateIndex(newindexName, WithCreateIndexDescriptorCore);

            if (result.IsValid)
            {
                Parallel.ForEach(UmbracoSearchFactory.GetContentIndexServices(), c => c.UpdateIndexTypeMapping(newindexName));
                Parallel.ForEach(UmbracoSearchFactory.GetMediaIndexServices(), c => c.UpdateIndexTypeMapping(newindexName));
            }
        }
        public async Task <IHttpActionResult> Ping()
        {
            try
            {
                var result = await UmbracoSearchFactory.IsActiveAsync();

                return(Ok(new { active = result }));
            }
            catch
            {
                return(Ok(new { active = false }));
            }
        }
        private void IndexContentCore(IEnumerable <IContent> entities, EventMessages messages, [CallerMemberName] string eventCaller = null)
        {
            if (UmbracoSearchFactory.HasActiveIndex)
            {
                LogHelper.Debug(GetType(), () => $"Content indexing triggered ({eventCaller})");
                foreach (var item in entities)
                {
                    item.SetIndexingStatus(IndexingStatusOption.InProgress, "Content indexing triggered");
                    var indexService = UmbracoSearchFactory.GetContentIndexService(item);
                    var indexName    = UmbracoSearchFactory.ActiveIndexName;
                    if (indexService != null)
                    {
                        try
                        {
                            if (indexService.IsExcludedFromIndex(item))
                            {
                                RemoveContent(indexService, item, indexName);
                                if (item.IndexError())
                                {
                                    throw new InvalidOperationException(item.GetIndexingStatus().Message);
                                }

                                messages?.Add(new EventMessage("Search", "Content removed from search index", EventMessageType.Success));
                                LogHelper.Debug(GetType(), () => $"Content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been removed from search index");
                            }
                            else
                            {
                                IndexContent(indexService, item, indexName);
                                if (item.IndexError())
                                {
                                    throw new InvalidOperationException(item.GetIndexingStatus().Message);
                                }

                                messages?.Add(new EventMessage("Search", "Content added to search index", EventMessageType.Success));
                                LogHelper.Debug(GetType(), () => $"Content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}' has been indexed");
                            }
                        }
                        catch (Exception ex)
                        {
                            messages?.Add(new EventMessage("Search", $"Unable to index content : '{item.Name}' => {ex.Message}", EventMessageType.Error));
                            LogHelper.WarnWithException(GetType(), $"Unable to index content ({item.ContentType.Alias}) '{item.Name}' with Id '{item.Id}'", ex);
                        }
                    }
                }
            }
            else
            {
                messages?.Add(new EventMessage("Search", "No active index available for indexing", EventMessageType.Error));
                LogHelper.Warn(GetType(), "No active index available for indexing");
            }
        }
        private bool ReindexContentNode(int nodeId)
        {
            var contentNode = ApplicationContext.Services.ContentService.GetById(nodeId);

            if (contentNode != null)
            {
                var contentIndexService = UmbracoSearchFactory.GetContentIndexService(contentNode);
                if (contentIndexService != null)
                {
                    contentIndexService.Index(contentNode, UmbracoSearchFactory.ActiveIndexName);
                    return(true);
                }
            }
            return(false);
        }
        private bool ReindexMediaNode(int nodeId)
        {
            var mediaNode = ApplicationContext.Services.MediaService.GetById(nodeId);

            if (mediaNode != null)
            {
                var mediaIndexService = UmbracoSearchFactory.GetMediaIndexService(mediaNode);
                if (mediaIndexService != null)
                {
                    mediaIndexService.Index(mediaNode, UmbracoSearchFactory.ActiveIndexName);
                    return(true);
                }
            }
            return(false);
        }
        private void Initialise(TSearchSettings searchSettings)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(searchSettings.IndexName))
                {
                    throw new ArgumentNullException(nameof(searchSettings.IndexName), "No indexName configured.  Ensure you have set am index name via ISearchSettings");
                }
                var indexNameResolver = GetIndexNameResolver(searchSettings);
                var client            = ConfigureElasticClient(searchSettings, indexNameResolver);
                var indexStrategy     = GetIndexCreationStrategy(client, indexNameResolver);

                UmbracoSearchFactory.SetDefaultClient(client);
                UmbracoSearchFactory.RegisterIndexStrategy(indexStrategy);

                UmbracoSearchFactory.HasActiveIndex = HasActiveIndex();
            }
            catch (Exception ex)
            {
                LogHelper.Error <SearchApplicationEventHandler <TSearchSettings> >("Unable to initialise elasticsearch integration", ex);
            }
        }
 public IHttpActionResult PluginVersionInfo()
 {
     return(Ok(UmbracoSearchFactory.GetVersion()));
 }
 public IndexManager() : this(UmbracoSearchFactory.Client, UmbracoSearchFactory.GetIndexStrategy())
 {
 }