public string RefreshMhcIndex() { var mhcIndexService = new MhcIndexService(); mhcIndexService.ResetIndex(); using (var db = new BiotopeDB()) { db.Configuration.LazyLoadingEnabled = true; db.Configuration.ProxyCreationEnabled = true; foreach (var biotope in db.WEB_BIOTOPE) { // Replace " with \" or the json will break var jsonSafeDescription = biotope.DESCRIPTION.Replace("\"", "\\\""); // Replacing full stops in original code with spaces because I can't figure out how to use a lettertokenizer var biotopeDoc = $@"{{ ""fields"": {{ ""originalCode"": ""{biotope.ORIGINAL_CODE.Trim().Replace('.', ' ')}"", ""fullTerm"": ""{biotope.FULL_TERM}"", ""description"": ""{jsonSafeDescription}"", ""hierarchyLevel"": ""{biotope.WEB_BIOTOPE_HIERARCHY.Count}"" }}, ""id"": ""{biotope.BIOTOPE_KEY}"", indexName: ""biotope"" }}"; mhcIndexService.AddBiotope(biotopeDoc); } return($"Indexing completed successfully, {db.WEB_BIOTOPE.Count()} biotopes indexed"); } }
public async Task <string> PopulateJnccIndex() { var env = new Env(); var jnccIndexService = new JnccIndexService(); var biotopesList = new List <string>(); using (var db = new BiotopeDB()) { foreach (var biotope in db.WEB_BIOTOPE) { var formattedTitle = Regex.Replace(biotope.FULL_TERM, htmlTagRegex, String.Empty); var formattedDescription = string.IsNullOrWhiteSpace(biotope.DESCRIPTION) ? null : Regex.Replace(biotope.DESCRIPTION, htmlTagRegex, String.Empty); var formattedSituation = string.IsNullOrWhiteSpace(biotope.SITUATION) ? null : Regex.Replace(biotope.SITUATION, htmlTagRegex, String.Empty); var message = new { verb = "upsert", index = env.SEARCH_INDEX, document = new { id = biotope.BIOTOPE_KEY, site = env.SITE, title = $"{biotope.ORIGINAL_CODE.Trim()} {formattedTitle}", content = $"{formattedDescription} {formattedSituation} {GetSpeciesString(biotope)}", url = env.BIOTOPE_BASE_URL + biotope.BIOTOPE_KEY.ToLower(), resource_type = "dataset", keywords = GetKeywords(biotope), published_date = "2015-03" } }; var jsonString = JsonConvert.SerializeObject(message, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); biotopesList.Add(jsonString); } } await jnccIndexService.AddBiotopes(biotopesList); return("JNCC indexing completed successfully"); }