/// <summary> /// Returns all aliases known for a page (including previous names). /// </summary> private IEnumerable <string> GetPageAliases(Page page) { var aliases = page.Aliases.Select(x => x.Title).ToList(); try { if (page.Type == PageType.Person && !string.IsNullOrEmpty(page.Facts)) { var json = JObject.Parse(page.Facts); var names = json["Main.Name"]?["Values"]; if (names != null) { foreach (var name in names) { var nameStr = name["LastName"] + " " + name["FirstName"] + " " + name["MiddleName"]; if (!string.IsNullOrWhiteSpace(nameStr)) { aliases.Add(nameStr.Trim()); } } } } } catch { // skip } return(aliases.Distinct()); }
/// <summary> /// Adds a page to the index. /// </summary> public async Task AddPageAsync(Page page) { var doc = new PageDocument { Id = page.Id, Key = page.Key, Title = page.Title, Aliases = GetPageAliases(page).JoinString(", "), PageType = (int)page.Type, Description = MarkdownService.Strip(page.Description), }; await _client.IndexAsync(doc, i => i.Index(PAGE_INDEX)); }
/// <summary> /// Removes a page from the index. /// </summary> public async Task RemovePageAsync(Page page) { await _client.DeleteAsync(new DeleteRequest(PAGE_INDEX, TypeName.From <PageDocument>(), page.Id)); }