static async Task Search(string index, string query, double threatIntent, bool identityhate, bool search_links, int top) { var client = new SearchIndexClient("socialnews", index, new SearchCredentials("0FD303356E9F04596A433B00CCE37F1E")); client.SetUserAgent("NewsAlphaCLI"); string field = "text", filterMsg = "none", limit = "all"; SearchParameters parameters = new SearchParameters() { Select = new[] { "id", "user", "text", "date_published", "no", "links", "identity_hate", "entities", "threat_intent" }, OrderBy = new [] { "date_published desc" } }; if (threatIntent > 0.0) { parameters.Filter = "threat_intent gt " + threatIntent; parameters.OrderBy = new[] { "threat_intent desc, date_published desc" }; filterMsg = "threat_intent"; } if (identityhate && threatIntent > 0.0) { parameters.Filter = "and identity_hate eq true"; filterMsg = "threat_intent and identity_hate"; } else if (identityhate) { parameters.Filter = "identity_hate eq true"; filterMsg = "identity_hate"; } if (search_links) { parameters.SearchFields = new[] { "links/uri" }; field = "links"; } if (top > 0) { parameters.Top = top; limit = top.ToString(); } DocumentSearchResult <Document> docResults = null; List <SocialNewsSearchResult> results = new List <SocialNewsSearchResult>(); using (var op = Begin("Search {0} for {1} containing {2} filtered on {3} limited to {4} results", index, field, query, filterMsg, limit)) { docResults = await client.Documents.SearchAsync(query, parameters); op.Complete(); } Info("Got {0} results.", docResults.Results.Count); foreach (var dr in docResults.Results) { var r = new SocialNewsSearchResult() { Id = (string)dr.Document["id"], User = (string)dr.Document["user"], DatePublished = ((DateTimeOffset)dr.Document["date_published"]).UtcDateTime, Text = (string)dr.Document["text"], HasIdentityHate = dr.Document["identity_hate"] != null ? (bool)dr.Document["identity_hate"] : false, No = (long)dr.Document["no"], ThreatIntent = dr.Document["threat_intent"] != null ? (double)dr.Document["threat_intent"] : 0.0, }; try { var links = (IEnumerable <Document>)dr.Document["links"]; r.Links = links.Select(l => (string)l["uri"]).ToArray(); var entities = (object[])dr.Document["entities"]; r.Entities = entities.Cast <string>().ToArray(); } catch { r.Links = Array.Empty <string>(); } results.Add(r); } if (results.Count == 0) { Info("0 social news posts in index {0} matching query {1}.\n", index.Replace("-index", ""), query); Exit(ExitResult.SUCCESS); } Info("Showing social news posts in index {0} matching query {1}.\n", index.Replace("-index", ""), query); CO.WriteLine("----"); foreach (var r in results) { CO.WriteLineFormatted("Id: {0}\nDate: {1} (UTC) \nUser: {2}\nNo.: {3}\nText: {4}\nLinks: \n{5}\nEntities: \n{6}", Color.LightGoldenrodYellow, Color.Gray, r.Id, r.DatePublished.ToString(), r.User, r.No, r.Text, "\t" + string.Join(Environment.NewLine + "\t", r.Links), r.Entities == null ? "" : "\t" + string.Join(Environment.NewLine + "\t", r.Entities)); if (r.ThreatIntent > 0.91) { CO.WriteLineFormatted("Threat Intent: {0}", Color.Red, Color.Gray, r.ThreatIntent); } else { CO.WriteLineFormatted("Threat Intent: {0}", Color.LightGoldenrodYellow, Color.Gray, r.ThreatIntent); } CO.WriteLine("----"); } }