/// <summary> /// Rebuilds the index /// </summary> /// <param name="indexName"></param> /// <returns></returns> public HttpResponseMessage PostRebuildIndex(string indexName) { var validate = ValidateIndex(indexName, out var index); if (!validate.IsSuccessStatusCode) { return(validate); } validate = ValidatePopulator(index); if (!validate.IsSuccessStatusCode) { return(validate); } _logger.Info <ExamineManagementController>("Rebuilding index '{IndexName}'", indexName); //remove it in case there's a handler there already index.IndexOperationComplete -= Indexer_IndexOperationComplete; //now add a single handler index.IndexOperationComplete += Indexer_IndexOperationComplete; try { //clear and replace index.CreateIndex(); var cacheKey = "temp_indexing_op_" + index.Name; //put temp val in cache which is used as a rudimentary way to know when the indexing is done AppCaches.RuntimeCache.Insert(cacheKey, () => "tempValue", TimeSpan.FromMinutes(5)); _indexRebuilder.RebuildIndex(indexName); ////populate it //foreach (var populator in _populators.Where(x => x.IsRegistered(indexName))) // populator.Populate(index); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { //ensure it's not listening index.IndexOperationComplete -= Indexer_IndexOperationComplete; Logger.Error <ExamineManagementController>(ex, "An error occurred rebuilding index"); var response = Request.CreateResponse(HttpStatusCode.Conflict); response.Content = new StringContent($"The index could not be rebuilt at this time, most likely there is another thread currently writing to the index. Error: {ex}"); response.ReasonPhrase = "Could Not Rebuild"; return(response); } }
public bool ReindexNode(string nodeIds) { if (!_fullTextConfig.IsFullTextIndexingEnabled()) { _logger.Debug <IndexController>("FullTextIndexing is not enabled"); return(false); } if (!_examineManager.TryGetIndex("ExternalIndex", out IIndex index)) { _logger.Error <IndexController>(new InvalidOperationException("No index found by name ExternalIndex")); return(false); } if (nodeIds == "*") { foreach (var content in Umbraco.ContentAtRoot()) { _cacheService.AddToCache(content.Id); foreach (var descendant in content.Descendants()) { _cacheService.AddToCache(descendant.Id); } } index.CreateIndex(); _indexRebuilder.RebuildIndex("ExternalIndex"); } else { var ids = nodeIds.Split(',').Select(x => int.Parse(x)); foreach (var id in ids) { _cacheService.AddToCache(id); } index.IndexItems(_valueSetBuilder.GetValueSets(_contentService.GetByIds(ids).ToArray())); } return(true); }