Ejemplo n.º 1
0
        public void IndexProviderShouldDeleteExistingIndex()
        {
            Assert.That(Indexes().Count(), Is.EqualTo(0));

            _provider.CreateIndex("default");
            Assert.That(Indexes().Count(), Is.EqualTo(1));

            _provider.DeleteIndex("default");
            Assert.That(Indexes().Count(), Is.EqualTo(0));
        }
        public async Task ProcessResource(Uri baseUri, SiteResource siteResource)
        {
            if (!ContinueProcessing(siteResource.SearchCategory))
            {
                return;
            }

            try
            {
                var newIndexName = _indexNameCreator.CreateNewIndexName(_searchSettings.IndexName, siteResource.SearchCategory);
                CreateIndex(newIndexName);

                try
                {
                    await IndexDocument(baseUri, siteResource, newIndexName);
                }
                catch (Exception)
                {
                    _logger.Info($"Deleting New Index {newIndexName} due to exception");
                    _indexProvider.DeleteIndex(newIndexName);
                    throw;
                }

                _logger.Info($"Creating Index Alias and Swapping from old to new index for type {typeof(T).Name}...");
                var indexAlias = _indexNameCreator.CreateIndexesAliasName(_searchSettings.IndexName, siteResource.SearchCategory);
                _indexProvider.CreateIndexAlias(newIndexName, indexAlias);

                _logger.Info($"Deleting Old Indexes for type {typeof(T).Name}...");
                _indexProvider.DeleteIndexes(_indexToRetain, indexAlias);
                _logger.Info($"Deleting Old Indexes Completed for type {typeof(T).Name}...");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Exception while Indexing {typeof(T).Name}");
            }
        }
 public async Task DisposeAsync()
 {
     await _indexProvider.DeleteIndex(nameof(BlogPost));
 }