public async Task ExecuteAsync(RecipeExecutionContext context) { if (!String.Equals(context.Name, "lucene-index", StringComparison.OrdinalIgnoreCase)) { return; } var indices = context.Step["Indices"]; if (indices != null) { foreach (var index in indices) { var luceneIndexSettings = index.ToObject <Dictionary <string, LuceneIndexSettings> >().FirstOrDefault(); if (!_luceneIndexManager.Exists(luceneIndexSettings.Key)) { luceneIndexSettings.Value.IndexName = luceneIndexSettings.Key; await _luceneIndexingService.CreateIndexAsync(luceneIndexSettings.Value); } } } }
public async Task <ActionResult> EditPost(LuceneIndexSettingsViewModel model, string[] indexedContentTypes) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageIndexes)) { return(Forbid()); } ValidateModel(model); if (model.IsCreate) { if (_luceneIndexManager.Exists(model.IndexName)) { ModelState.AddModelError(nameof(LuceneIndexSettingsViewModel.IndexName), S["An index named {0} already exists.", model.IndexName]); } } else { if (!_luceneIndexManager.Exists(model.IndexName)) { ModelState.AddModelError(nameof(LuceneIndexSettingsViewModel.IndexName), S["An index named {0} doesn't exist.", model.IndexName]); } } if (!ModelState.IsValid) { model.Cultures = CultureInfo.GetCultures(CultureTypes.AllCultures) .Select(x => new SelectListItem { Text = x.Name + " (" + x.DisplayName + ")", Value = x.Name }).Prepend(new SelectListItem { Text = S["Any culture"], Value = "any" }); model.Analyzers = _luceneAnalyzerManager.GetAnalyzers() .Select(x => new SelectListItem { Text = x.Name, Value = x.Name }); return(View(model)); } if (model.IsCreate) { try { var settings = new LuceneIndexSettings { IndexName = model.IndexName, AnalyzerName = model.AnalyzerName, IndexLatest = model.IndexLatest, IndexedContentTypes = indexedContentTypes, Culture = model.Culture ?? "" }; // We call Rebuild in order to reset the index state cursor too in case the same index // name was also used previously. await _luceneIndexingService.CreateIndexAsync(settings); } catch (Exception e) { _notifier.Error(H["An error occurred while creating the index."]); _logger.LogError(e, "An error occurred while creating an index."); return(View(model)); } _notifier.Success(H["Index <em>{0}</em> created successfully.", model.IndexName]); } else { try { var settings = new LuceneIndexSettings { IndexName = model.IndexName, AnalyzerName = model.AnalyzerName, IndexLatest = model.IndexLatest, IndexedContentTypes = indexedContentTypes, Culture = model.Culture ?? "" }; await _luceneIndexingService.UpdateIndexAsync(settings); } catch (Exception e) { _notifier.Error(H["An error occurred while editing the index."]); _logger.LogError(e, "An error occurred while editing an index."); return(View(model)); } _notifier.Success(H["Index <em>{0}</em> modified successfully, <strong>please consider doing a rebuild on the index.</strong>", model.IndexName]); } return(RedirectToAction("Index")); }