public void AddSynonym(string language, Synonym synonym) { var trimmedMap = synonym.SynonymList.Select(str => str.ToLower().Trim()).Where(str => !string.IsNullOrEmpty(str)).ToList(); var settings = new JsonSerializerSettings(); //var jsonDoc = JsonConvert.SerializeObject(trimmedMap, settings); /* * if (synonym.Bidirectional) * { * jsonDoc = JsonConvert.SerializeObject(trimmedMap, settings); * * } * else * { * var dict = new Dictionary<string, List<string>>(); * dict.Add(synonym.Term.ToLower(), trimmedMap); * jsonDoc = JsonConvert.SerializeObject(dict, settings); * } */ var dict = new Dictionary <string, List <string> >(); dict.Add(synonym.Term.ToLower(), trimmedMap); var jsonDoc = JsonConvert.SerializeObject(dict, settings); var endPointGetResources = string.Format("{0}/schema/analysis/synonyms/{1}", Client.SrchConnStr, language); HttpClient.PostJson(endPointGetResources, jsonDoc); }
public Synonym GetSynonym(string language, string term) { var endPointGetResources = string.Format("{0}/schema/analysis/synonyms/{1}/{2}", Client.SrchConnStr, language, term); var json = HttpClient.GetRequest(endPointGetResources); var synonymObj = JsonConvert.DeserializeObject <dynamic>(json, new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore, }); var synonyms = synonymObj[term]; var m = new Synonym() { Term = term, Synonyms = string.Join(",", synonyms), }; return(m); }