public static string[] MakeRequest(string search) { List <string> res = new List <string>(); // This is the query expression. string query = search; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The market to use. string market = "en-us"; // Get news for business string newsCat = "rt_Business"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var newsQuery = bingContainer.News(query, null, market, null, null, null, null, newsCat, null); newsQuery = newsQuery.AddQueryOption("$top", 10); // Run the query and display the results. var newsResults = newsQuery.Execute(); int daysThreshold = 40; DateTime currentDate = new DateTime(); currentDate = DateTime.Now; DateTime thresholdDate = new DateTime(); thresholdDate = currentDate.Subtract(TimeSpan.FromDays(daysThreshold)); DateTime sixteen = new DateTime(2015, 10, 9, 12, 12, 12); foreach (var result in newsResults) { if (result.Date > thresholdDate) { //if (TestRelevance(search, result.Title, result.Description)) //{ res.Add(result.Title); res.Add(result.Url); //} } } return(res.ToArray()); }
static void MakeNewsRequest(string question) { // This is the query expression. string query = question; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The market to use. string market = "en-us"; // Get news for science and technology. string newsCat = "rt_ScienceAndTechnology"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var newsQuery = bingContainer.News(query, null, market, null, null, null, null, newsCat, null); newsQuery = newsQuery.AddQueryOption("$top", 10); // Run the query and display the results. var newsResults = newsQuery.Execute(); foreach (var result in newsResults) { Console.WriteLine("{0}-{1}\n\t{2}", result.Source, result.Title, result.Description); } }
/// <summary> /// Search for news only. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnNewsSearch_Click(object sender, EventArgs e) { Repeater rptResult = new Repeater(); string query = tbQueryString.Text; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Get news for science and technology. string newsCat = "rt_ScienceAndTechnology"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var newsQuery = bingContainer.News(query, null, market, null, null, null, null, newsCat, null); newsQuery = newsQuery.AddQueryOption("$top", 10); // Run the query and display the results. var newsResults = newsQuery.Execute(); StringBuilder searchResult = new StringBuilder(); Label lblResults = new Label(); foreach (Bing.NewsResult nResult in newsResults) { searchResult.Append(string.Format("<a href={0}>{1}</a><br /> {2}<br /> {3} {4}<br /><br />", nResult.Url, nResult.Title, nResult.Description, nResult.Source, nResult.Date)); } lblResults.Text = searchResult.ToString(); Panel1.Controls.Add(lblResults); }
static void MakeNewsRequest(string question) { // This is the query expression. string query = question; // Create a Bing container. string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The market to use. string market = "en-us"; // Get news for science and technology. string newsCat = "rt_ScienceAndTechnology"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var newsQuery = bingContainer.News(query, null, market, null, null, null, null, newsCat, null); newsQuery = newsQuery.AddQueryOption("$top", 10); // Run the query and display the results. var newsResults = newsQuery.Execute(); foreach (var result in newsResults) { Console.WriteLine("{0}-{1}\n\t{2}", result.Source, result.Title, result.Description); } }