//Bing Search static void MakeRequest(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"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var webQuery = bingContainer.Web(query, null, null, market, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 10); // Run the query and display the results. var webResults = webQuery.Execute(); foreach (var result in webResults) { Console.WriteLine("{0}\n\t{1}", result.Title, result.Url); } }
public static BingSearchViewModel ImageSearch(string query, string callback) { string accountKey = WebConfigurationManager.AppSettings["BingKey"]; string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 12); var imageResults = imageQuery.Execute(); var model = new BingSearchViewModel(); if (callback != null && callback.Length > 0) { model.Callback = callback; } foreach (var result in imageResults) { model.Results.Add(new BingSearchImageResult() { ImageURL = result.MediaUrl, ThumbnailURL = result.Thumbnail.MediaUrl, ThumbnailWidth = result.Thumbnail.Width, ThumbnailHeight = result.Thumbnail.Height, }); } return model; }
/// <summary> /// Related search. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRelatedSearch_Click(object sender, EventArgs e) { 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)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var relatedQuery = bingContainer.RelatedSearch(query, null, market, null, null, null); relatedQuery = relatedQuery.AddQueryOption("$top", 10); // Run the query and display the results. var relatedResults = relatedQuery.Execute(); List <Bing.RelatedSearchResult> relatedSearchResultList = new List <Bing.RelatedSearchResult>(); Label lblResults = new Label(); StringBuilder searchResults = new StringBuilder(); foreach (Bing.RelatedSearchResult rResult in relatedResults) { searchResults.Append(string.Format("<a href={1}>{0}</a><br /> {1}<br />", rResult.Title, rResult.BingUrl)); } lblResults.Text = searchResults.ToString(); Panel1.Controls.Add(lblResults); }
private string[] GetImages(string year, string make, string model, string trim) { string query = year + " " + make + " " + model + " " + trim; //Create a Bing container string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountkey = "deKmywQL9zTT0DV30aJYSxVGmLCQj279OtHw0QcYDyU"; //Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountkey, accountkey); //Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); //extract the properties needed for the images List <string> images = new List <string>(); foreach (var result in imageResults) { images.Add(result.MediaUrl); } return(images.ToArray()); }
/// <summary> /// Search for image only. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnImageSearch_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)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var imageQuery = bingContainer.Image(query, null, market, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 50); // Run the query and display the results. var imageResults = imageQuery.Execute(); StringBuilder searchResult = new StringBuilder(); Label lblResults = new Label(); foreach (Bing.ImageResult iResult in imageResults) { searchResult.Append(string.Format("Image Title: <a href={1}>{0}</a><br />Image Url: {1}<br /><br />", iResult.Title, iResult.MediaUrl)); } lblResults.Text = searchResult.ToString(); Panel1.Controls.Add(lblResults); }
public static List<KeyValuePair<string, string>> Search(string key) { List<KeyValuePair<string, string>> op = new List<KeyValuePair<string, string>>(); // Create a Bing container string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "mzyAdEQ7iPEwvJ0XWUHhYt5ypb9wmCpenCfvE7sfDsI"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); // Build the query. var imageQuery = bingContainer.Image(key, null, null, null, null, null, null); var imageResults = imageQuery.Execute(); foreach (var result in imageResults) { op.Add(new KeyValuePair<string, string>(result.Title, result.MediaUrl)); } return op; }
/// <summary> /// Search for web only. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnWebSearch_Click(object sender, EventArgs e) { Repeater rptResult = new Repeater(); // This is the query expression. string query = tbQueryString.Text; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results. var webQuery = bingContainer.Web(query, null, null, market, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 10); // Run the query and display the results. var webResults = webQuery.Execute(); Label lblResults = new Label(); StringBuilder searchResult = new StringBuilder(); foreach (Bing.WebResult wResult in webResults) { searchResult.Append(string.Format("<a href={2}>{0}</a><br /> {1}<br /> {2}<br /><br />", wResult.Title, wResult.Url, wResult.Description)); } lblResults.Text = searchResult.ToString(); Panel1.Controls.Add(lblResults); }
/// <summary> /// This section searches for the top 5 photos of the selected car from Bing using year, make, model and trim as the parameters /// We create a Bing container and pass the assigned key for credentials /// </summary> /// <param name="year"></param> /// <param name="make"></param> /// <param name="model"></param> /// <param name="trim"></param> /// <returns></returns> private string[] GetImages(string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "i52CgTJWkEZb7wR4q0/XNKItRAQrkaUAFZuijkBao+k="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null).AddQueryOption("$top", 5); //imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); //extract the properties needed for the images List <string> images = new List <string>(); foreach (var result in imageResults) { images.Add(result.MediaUrl); } return(images.ToArray()); }
public async Task <IHttpActionResult> GetCarData(string model_year = "", string make = "", string model_name = "", string model_trim = "") { HttpResponseMessage response; var content = ""; var singleCar = await db.GetCar(model_year, make, model_name, model_trim); var car = new carViewModel { Car = singleCar, //Car = db.GetCars(year, make, model, trim), Recalls = content, Images = "" }; //Get recall Data using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://www.nhtsa.gov/"); try { response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + model_year + "/make/" + make + "/model/" + model_name + "?format=json"); content = await response.Content.ReadAsStringAsync(); } catch (Exception e) { return(InternalServerError(e)); } } car.Recalls = content; ////////////////////////////// My Bing Search ////////////////////////////////////////////////////////// string query = model_year + " " + make + " " + model_name + " " + model_trim; string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountKey = ConfigurationManager.AppSettings["BingAPIKey"];; bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); var imageResults = imageQuery.Execute().ToList(); car.Images = imageResults.First().MediaUrl; //////////////////////////////////////////////////////////////////////////////////////////////////////////// return(Ok(car)); }
public List <Article> MakeList(params string[] searchCriteria) { List <Article> articles = new List <Article>(); var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(AccountKey, AccountKey) }; foreach (string s in searchCriteria) { var searchQuery = bingContainer.Web(string.Format("{0}({1})", s, Variables.URL), null, null, null, null, null, null, null); var searchResults = searchQuery.Execute(); if (searchResults == null) { continue; } foreach (var result in searchResults) { articles.Add(new Article(result.Title)); Console.WriteLine(result.Title); } } return(articles); }
private MessageHandlerResult GetImage(string query, IPluginContext context) { try { var bingContainer = new Bing.BingSearchContainer(new Uri(BingApiUri)) { Credentials = new NetworkCredential(BingApi, BingApi) }; var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); var imageResults = imageQuery.Execute(); if (imageResults != null) { var imageList = imageResults.ToList(); if (imageList.Count > 0) { var index = context.RandomProvider.Next(imageList.Count); var url = imageList[index].MediaUrl; return this.Handled(this.Message(url)); } } var response = context.TextProcessor.FormatPluginResponse("Really? Do you kiss ${SOMEONE}'s mum with that mouth?", context); return this.Handled(this.Message(response)); } catch (Exception ex) { Log.ErrorException("Unable to search for images on bing.", ex); return this.Handled(this.Message("Uh Oh...")); } }
public static List <KeyValuePair <string, string> > Search(string key) { List <KeyValuePair <string, string> > op = new List <KeyValuePair <string, string> >(); // Create a Bing container string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "mzyAdEQ7iPEwvJ0XWUHhYt5ypb9wmCpenCfvE7sfDsI"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); // Build the query. var imageQuery = bingContainer.Image(key, null, null, null, null, null, null); var imageResults = imageQuery.Execute(); foreach (var result in imageResults) { op.Add(new KeyValuePair <string, string>(result.Title, result.MediaUrl)); } return(op); }
private void getBingResults(string query, int results, int skipResults) { // 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"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(BING_API_KEY_NAME, BING_API_KEY_VALUE); // Build the query, limiting to 10 results. var webQuery = bingContainer.Web(query, null, null, market, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", results); webQuery = webQuery.AddQueryOption("$skip", skipResults); // Run the query and display the results. var webResults = webQuery.Execute(); foreach (var result in webResults) { Application.DoEvents(); Invoke(new Action(() => this.resultBox.AppendText(result.Url.ToString() + Environment.NewLine))); } }
/// <summary> /// 検索ボタンクリック /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSearch_Click(object sender, EventArgs e) { // This is the query - or you could get it from args. string query = txtSearch.Text.Trim(); // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "SOKyLs1uETTMXQzh+mnSmFLXzRFrGYZTFaaN2UzPkQs"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); // Build the query. if (rdbWeb.Checked) { var webQuery = bingContainer.Web(query, null, null, null, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 10); var webResults = webQuery.Execute(); grdResult.DataSource = webResults; grdResult.DataBind(); } else { var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); var imageResults = imageQuery.Execute(); grdResult.DataSource = imageResults; grdResult.DataBind(); } }
static CarsController() { client.BaseAddress = new System.Uri(System.Configuration.ConfigurationManager.ConnectionStrings["NHTSAConnection"].ConnectionString); string bingRootUri = System.Configuration.ConfigurationManager.ConnectionStrings["BingConnection"].ConnectionString; bingContainer = new Bing.BingSearchContainer(new Uri(bingRootUri)); string accountKey = System.Configuration.ConfigurationManager.AppSettings["BingAccountKey"]; bingContainer.Credentials = new System.Net.NetworkCredential(accountKey, accountKey); }
/// <summary> /// Bing 画像検索を行い、取得した画像URLのシーケンスをIObservableとして返却します /// </summary> /// <param name="searchWord">検索文字列</param> /// <param name="accountKey">Bing Search アカウントキー</param> /// <param name="skip">スキップする検索結果の件数</param> /// <param name="top">取得する検索結果の件数</param> /// <returns>画像検索結果</returns> public static IObservable<Bing.ImageResult> SearchImageAsObservable(string searchWord, string accountKey, int skip, int top,IScheduler scheduler) { return Observable.Start(() => { var bing = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/")); bing.Credentials = new NetworkCredential("accountKey", accountKey); var query = bing.Image(searchWord, null, null, null, null, null, null); query = query.AddQueryOption("$skip", skip); query = query.AddQueryOption("$top", top); return query.Execute(); },scheduler).SelectMany(ie => ie); }
/// <summary> /// Composite search. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCompositeSearch_Click(object sender, EventArgs e) { 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)); // The composite operations to use. string operations = "web+news"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 5 results (per service operation). var compositeQuery = bingContainer.Composite(operations, query, null, null, market, null, null, null, null, null, null, null, null, null, null); compositeQuery = compositeQuery.AddQueryOption("$top", 5); // Run the query and display the results. var compositeResults = compositeQuery.Execute(); StringBuilder searchResults = new StringBuilder(); foreach (var cResult in compositeResults) { searchResults.Append("<h3>Web Result</h3>"); // Display web results. foreach (var result in cResult.Web) { searchResults.Append(string.Format("<a href={2}>{0}</a><br /> {1}<br /> {2}<br /><br />", result.Title, result.Url, result.Description)); } searchResults.Append("<h3>News Result</h3>"); // Display news results. foreach (var result in cResult.News) { searchResults.Append(string.Format("<a href={0}>{1}</a><br /> {2}<br /> {3} {4}<br /><br />", result.Url, result.Title, result.Description, result.Source, result.Date)); } } Label lblResults = new Label(); lblResults.Text = searchResults.ToString(); Panel1.Controls.Add(lblResults); }
/// <summary> /// Documentation under IChronozoomSVC /// </summary> BaseJsonResult <IEnumerable <Bing.ImageResult> > IBingSearchAPI.GetImages(string query, string top, string skip) { return(ApiOperation <BaseJsonResult <IEnumerable <Bing.ImageResult> > >(delegate(User user, Storage storage) { var searchResults = new List <Bing.ImageResult>(); if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"])) { BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]; } #if RELEASE if (user == null) { // Setting status code to 403 to prevent redirection to authentication resource if status code is 401. SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser); return new BaseJsonResult <IEnumerable <Bing.ImageResult> >(searchResults); } #endif int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit; int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset; try { var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl)); bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey); var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", resultsCount); imageQuery = imageQuery.AddQueryOption("$skip", offset); var imageResults = imageQuery.Execute(); foreach (var result in imageResults) { searchResults.Add(result); } } catch (ArgumentNullException) { SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery); } catch (Exception ex) { SetStatusCode(HttpStatusCode.InternalServerError, ex.Message); } return new BaseJsonResult <IEnumerable <Bing.ImageResult> >(searchResults); })); }
public decimal SearchOnBing(string keyword) { const string accountKey = "ls2YxwQCBAdTP/NprBJj7+4c1Ys+dFuenRDODWh/Q6s="; const string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)) { Credentials = new NetworkCredential(accountKey, accountKey) }; var webQuery = bingContainer.Web(keyword, Options: null, WebSearchOptions: null, Market: null, Adult: null, Latitude: null, Longitude: null, WebFileType: null); var webResults = webQuery.Execute(); return(webResults.Count()); }
public void BingKeywordGetter(string query) { // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. string market = "en-us"; string accountKey = "3OL0xieASOtqcyusoHZ447oH2wCJd/Mkz7gM/+ZjQF0"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var webquery = bingContainer.Web(query, null, null,market, null, null, null, null); webquery = webquery.AddQueryOption("$top", 10); var webresults = webquery.Execute(); }
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); }
/// <summary> /// Image Search /// </summary> /// <param name="query">Query String</param> /// <param name="longitude">Longitude</param> /// <param name="latitude">Latitude</param> /// <returns>Results</returns> public IEnumerable <ImageResult> Search(string query, double?longitude = null, double?latitude = null) { var results = this.QueryLocal(query); if (null == results || 0 == results.Count()) { results = results ?? new List <ImageResult>(); var bingContainer = new Bing.BingSearchContainer(new Uri(RootUri)) { Credentials = new NetworkCredential(AccountKey, AccountKey), }; var imageQuery = bingContainer.Image(query, null, null, "Strict", latitude, longitude, "Size:Large+Style:Photo"); var entries = new List <BingQueryEntry>(); var images = imageQuery.Execute(); foreach (var image in images) { if (null != image) { var result = new ImageResult(image); results.Add(result); var entry = new BingQueryEntry() { PartitionKey = query.ToLowerInvariant(), RowKey = Guid.NewGuid().ToString(), Url = result.Url, ThumbnailUrl = result.ThumbnailUrl, }; entries.Add(entry); } } this.SaveLocal(entries); } return(results); }
static void MakeRequest() { string query = "Chairs"; string res_img_dir = SaveDir + query + "/"; // create directory Directory.CreateDirectory(res_img_dir); string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); string market = "en-us"; bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // build query var imageQuery = bingContainer.Image(query, null, market, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 50); imageQuery = imageQuery.AddQueryOption("$skip", 50); // run query: MUST ADD TOLIST()! var imageResults = imageQuery.Execute().ToList(); Console.WriteLine("{0} results for query " + query + ":", imageResults.Count()); // download searched images System.Net.WebClient _WebClient = new System.Net.WebClient(); int cnt = 0; foreach (var result in imageResults) { cnt++; Console.WriteLine("{0}: {1}\n{2}\n", cnt, result.Title, result.MediaUrl); int filenamestart = result.MediaUrl.LastIndexOf('/') + 1; int filenameend = result.MediaUrl.LastIndexOf('.') - 1; string filename = result.MediaUrl.Substring(filenamestart, filenameend - filenamestart + 1); _WebClient.DownloadFile(result.MediaUrl, res_img_dir + filename + ".jpg"); } }
/// <summary> /// Search with spelling suggestion. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSpellingSuggestionSearch_Click(object sender, EventArgs e) { 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)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query. var spellQuery = bingContainer.SpellingSuggestions(query, null, market, null, null, null); // Run the query and display the results. var spellResults = spellQuery.Execute(); List <Bing.SpellResult> spellResultList = new List <Bing.SpellResult>(); foreach (var result in spellResults) { spellResultList.Add(result); } Label lblResults = new Label(); if (spellResultList.Count > 0) { lblResults.Text = string.Format( "Spelling suggestion is <strong>{0}</strong>", spellResultList[0].Value); } else { lblResults.Text = "No spelling suggestion. Type some typo key words for suggestion for example \"xbx gamess\""; } Panel1.Controls.Add(lblResults); }
private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); var accountKey = "EMdPzpSl/qTbvz6/ScfE5sFLzuxNfU/crNSmIYjQDes="; var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search")); bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var webQuery = bingContainer.Web(txtSearch.Text.ToString(), null, null, null, null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 30); var webResults = webQuery.Execute(); foreach (var result in webQuery) { listBox1.Items.Add(ConvertUrlsToLinks(result.Url)); textBox6.Text += result.Url + Environment.NewLine; //listBox5.Items.Add(result.Url); } }
static void MakeRequest() { string query = "Chairs"; string res_img_dir = SaveDir + query + "/"; // create directory Directory.CreateDirectory(res_img_dir); string rootUrl = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); string market = "en-us"; bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // build query var imageQuery = bingContainer.Image(query, null, market, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 50); imageQuery = imageQuery.AddQueryOption("$skip", 50); // run query: MUST ADD TOLIST()! var imageResults = imageQuery.Execute().ToList(); Console.WriteLine("{0} results for query " + query + ":", imageResults.Count()); // download searched images System.Net.WebClient _WebClient = new System.Net.WebClient(); int cnt = 0; foreach(var result in imageResults) { cnt++; Console.WriteLine("{0}: {1}\n{2}\n", cnt, result.Title, result.MediaUrl); int filenamestart = result.MediaUrl.LastIndexOf('/') + 1; int filenameend = result.MediaUrl.LastIndexOf('.') - 1; string filename = result.MediaUrl.Substring(filenamestart, filenameend - filenamestart + 1); _WebClient.DownloadFile(result.MediaUrl, res_img_dir + filename + ".jpg"); } }
/// <summary> /// Search the web. /// </summary> /// <param name="PlayerId">Supplies the requesting player ID.</param> /// <param name="CharacterServerId">Supplies the server ID to send the /// response information to.</param> /// <param name="Command">Supplies the command text.</param> private void IngameCommand_Search(int PlayerId, int CharacterServerId, string Text) { Text = Text.Trim(); try { Bing.BingSearchContainer SearchService = new Bing.BingSearchContainer(new Uri(BingAzureBaseURL)); SearchService.Credentials = new NetworkCredential(BingApplicationKey, BingApplicationKey); DataServiceQuery<Bing.WebResult> ServiceQuery = SearchService.Web(Text, "en-US", "Moderate", null, null, null); Bing.WebResult Result = ServiceQuery.Execute().FirstOrDefault(); if (Result == null) SendMessageToPlayer(PlayerId, CharacterServerId, "No results."); else SendMessageToPlayer(PlayerId, CharacterServerId, String.Format("{0}: {1} - {2}", Result.Title, Result.Url, Result.Description)); IncrementStatistic("IRC_COMMAND_WEBSEARCH"); } catch (Exception) { SendMessageToPlayer(PlayerId, CharacterServerId, String.Format("Unable to retrieve search results for {0}.", Text)); } }
public SearchResult[] ContextAwareSearch([FromUri] string query, [FromUri] string[] keywords) { query = query.Trim(); List <string> queryModifications = new List <string>(); queryModifications.Add("learning " + query); queryModifications.Add(query + " events"); queryModifications.Add(query + " basics"); queryModifications.Add(query + " research"); queryModifications.Add(query + " courses"); string[] context = { "coursera", "instructables", "edx", "udacity", "itunesu", "github", "khan academy" }; //Set default web proxy - ONLY NEEDED FOR 1AND1 HOSTING //WebRequest.DefaultWebProxy = new WebProxy("ntproxyus.lxa.perfora.net", 3128); //Set up Bing connection string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountKey = ConfigurationManager.AppSettings["BING_KEY"]; bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); //Set up search results list List <IEnumerable <Bing.WebResult> > searchResults = new List <IEnumerable <Bing.WebResult> >(); //Search for given topic DataServiceQuery <Bing.WebResult> webQuery = bingContainer.Web(query, null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); //Search for keywords foreach (string keyword in keywords) { webQuery = bingContainer.Web(query + keyword.Trim(), null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); } //Add using query modifications foreach (string queryMod in queryModifications) { webQuery = bingContainer.Web(queryMod, null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); } //Parse search results List <SearchResult> items = new List <SearchResult>(); int listNumber = 1; for (int i = 0; i < searchResults.Count; i++) { int initialRank = listNumber; foreach (Bing.WebResult result in searchResults[i]) { int rank = initialRank; SearchResult temp = new SearchResult(); temp.title = result.Title; temp.description = result.Description; temp.url = result.Url; //Modify rank based on user preferences foreach (string keyword in keywords) { if (result.Title.ToLower().Contains(keyword)) { rank = rank / 4; } else if (result.Description.ToLower().Contains(keyword)) { rank = rank / 2; } } //Modify rank based on static context foreach (string word in context) { if (result.Url.ToLower().Contains(word)) { rank = rank / 10; } else if (result.Title.ToLower().Contains(word)) { rank = rank / 4; } else if (result.Description.ToLower().Contains(word)) { rank = rank / 2; } } if (result.Url.ToLower().Contains("youtube")) { rank = rank * 100; } else if (result.Title.ToLower().Contains("youtube")) { rank = rank * 100; } else if (result.Description.ToLower().Contains("youtube")) { rank = rank * 100; } temp.ranking = rank; items.Add(temp); initialRank += 100; } listNumber++; } //Sort results by rank items.Sort((s1, s2) => s1.ranking.CompareTo(s2.ranking)); List <string> results = new List <string>(); foreach (SearchResult item in items) { results.Add(item.title + "\n" + item.description + "\n" + item.url + "\n\n"); } SearchResult[] resultArray = items.ToArray(); return(resultArray); }
async Task doSearch(ImageSearchQuery state, int imageOffset) { if (String.IsNullOrEmpty(state.Query) || String.IsNullOrWhiteSpace(state.Query)) { return; } var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(BingAccountKey.accountKey, BingAccountKey.accountKey); // Build the query. String imageFilters = null; if (!state.Size.Equals(size[0])) { imageFilters = "Size:" + state.Size; } if (!state.Layout.Equals(layout[0])) { if (imageFilters != null) imageFilters += "+"; imageFilters += "Aspect:" + state.Layout; } if (!state.Type.Equals(type[0])) { if (imageFilters != null) imageFilters += "+"; imageFilters += "Style:" + state.Type; } if (!state.People.Equals(type[0])) { if (imageFilters != null) imageFilters += "+"; imageFilters += "Face:" + state.People; } if (!state.Color.Equals(type[0])) { if (imageFilters != null) imageFilters += "+"; imageFilters += "Color:" + state.Color; } var imageQuery = bingContainer.Image(Query, null, null, state.SafeSearch, state.GeoTag.LatDecimal, state.GeoTag.LonDecimal, imageFilters); imageQuery = imageQuery.AddQueryOption("$top", 50); imageQuery = imageQuery.AddQueryOption("$skip", imageOffset); IEnumerable<Bing.ImageResult> imageResults = await Task.Factory.FromAsync<IEnumerable<Bing.ImageResult>>(imageQuery.BeginExecute(null, null), imageQuery.EndExecute); if (imageOffset == 0) { MediaState.clearUIState(Query, DateTime.Now, MediaStateType.SearchResult); } List<MediaItem> results = new List<MediaItem>(); int relevance = imageOffset; MediaState.UIMediaCollection.EnterReadLock(); foreach (var image in imageResults) { MediaItem item = new ImageResultItem(image, relevance); if (MediaState.UIMediaCollection.Contains(item)) continue; results.Add(item); relevance++; } MediaState.UIMediaCollection.ExitReadLock(); MediaState.addUIState(results); }
protected void socialSearch_Click(object sender, EventArgs e) { string query = socialsearchtbox.Text; string queryfacebook = query + " " + "site:facebook.com"; string querytwitter = query + " " + "site:twitter.com"; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. string market = "en-us"; string accountKey = "3OL0xieASOtqcyusoHZ447oH2wCJd/Mkz7gM/+ZjQF0"; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var webqueryfacebook = bingContainer.Web(queryfacebook, null, null, market, null, null, null, null); webqueryfacebook = webqueryfacebook.AddQueryOption("$top", 10); var webresultsfacebook = webqueryfacebook.Execute(); var webquerytwitter = bingContainer.Web(querytwitter, null, null, market, null, null, null, null); webquerytwitter = webquerytwitter.AddQueryOption("$top", 10); var webresulttwitter = webquerytwitter.Execute(); DataTable facebookdt = new DataTable(); facebookdt.Columns.Add("fbname", typeof(string)); facebookdt.Columns.Add("fburl", typeof(string)); DataTable twitterdt = new DataTable(); twitterdt.Columns.Add("twittername",typeof(string)); twitterdt.Columns.Add("twitterurl", typeof(string)); //facebookurllst.Items.Clear(); //twitterurllst.Items.Clear(); foreach(var fbresult in webresultsfacebook) { facebookdt.Rows.Add(fbresult.Title, fbresult.Url); } foreach(var twitterresult in webresulttwitter) { twitterdt.Rows.Add(twitterresult.Title,twitterresult.Url); } facebookrepeater.DataSource = facebookdt; facebookrepeater.DataBind(); twitterrepeater.DataSource = twitterdt; twitterrepeater.DataBind(); fbrow.Visible = true; twitterrow.Visible = true; }
public List<Article> MakeList(params string[] searchCriteria) { List<Article> articles = new List<Article>(); var bingContainer = new Bing.BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/")) {Credentials = new NetworkCredential(AccountKey, AccountKey)}; foreach (string s in searchCriteria) { var searchQuery = bingContainer.Web(string.Format("{0}({1})", s, Variables.URL), null, null, null, null, null, null, null); var searchResults = searchQuery.Execute(); if (searchResults == null) { continue; } foreach (var result in searchResults) { articles.Add(new Article(result.Title)); Console.WriteLine(result.Title); } } return articles; }
public SearchResult[] ContextAwareSearch([FromUri] string query, [FromUri] string[] keywords) { query = query.Trim(); List<string> queryModifications = new List<string>(); queryModifications.Add("learning " + query); queryModifications.Add(query + " events"); queryModifications.Add(query + " basics"); queryModifications.Add(query + " research"); queryModifications.Add(query + " courses"); string[] context = {"coursera", "instructables", "edx", "udacity", "itunesu", "github", "khan academy"}; //Set default web proxy - ONLY NEEDED FOR 1AND1 HOSTING //WebRequest.DefaultWebProxy = new WebProxy("ntproxyus.lxa.perfora.net", 3128); //Set up Bing connection string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountKey = ConfigurationManager.AppSettings["BING_KEY"]; bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); //Set up search results list List<IEnumerable<Bing.WebResult>> searchResults = new List<IEnumerable<Bing.WebResult>>(); //Search for given topic DataServiceQuery<Bing.WebResult> webQuery = bingContainer.Web(query, null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); //Search for keywords foreach (string keyword in keywords) { webQuery = bingContainer.Web(query + keyword.Trim(), null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); } //Add using query modifications foreach (string queryMod in queryModifications) { webQuery = bingContainer.Web(queryMod, null, null, "en-us", null, null, null, null); webQuery = webQuery.AddQueryOption("$top", 20); searchResults.Add(webQuery.Execute()); } //Parse search results List<SearchResult> items = new List<SearchResult>(); int listNumber = 1; for (int i = 0; i < searchResults.Count; i++) { int initialRank = listNumber; foreach (Bing.WebResult result in searchResults[i]) { int rank = initialRank; SearchResult temp = new SearchResult(); temp.title = result.Title; temp.description = result.Description; temp.url = result.Url; //Modify rank based on user preferences foreach (string keyword in keywords) { if (result.Title.ToLower().Contains(keyword)) { rank = rank / 4; } else if (result.Description.ToLower().Contains(keyword)) { rank = rank / 2; } } //Modify rank based on static context foreach (string word in context) { if (result.Url.ToLower().Contains(word)) { rank = rank / 10; } else if (result.Title.ToLower().Contains(word)) { rank = rank / 4; } else if (result.Description.ToLower().Contains(word)) { rank = rank / 2; } } if (result.Url.ToLower().Contains("youtube")) { rank = rank * 100; } else if (result.Title.ToLower().Contains("youtube")) { rank = rank * 100; } else if (result.Description.ToLower().Contains("youtube")) { rank = rank * 100; } temp.ranking = rank; items.Add(temp); initialRank += 100; } listNumber++; } //Sort results by rank items.Sort((s1, s2) => s1.ranking.CompareTo(s2.ranking)); List<string> results = new List<string>(); foreach (SearchResult item in items) { results.Add(item.title + "\n" + item.description + "\n" + item.url + "\n\n"); } SearchResult[] resultArray = items.ToArray(); return resultArray; }
private string[] GetImages(string year, string make, string model) { string query = year + " " + make + " " + model; string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountKey = "/7AIpfB3zsaqbfg8L/DsttX/YgDqetIK7xv3iZo+hKw="; bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); List<string> imageURLs = new List<string>(); foreach (var result in imageResults) { // check for http response code 200 before adding if (UrlCtrl.IsUrl(result.MediaUrl)) { imageURLs.Add(result.MediaUrl); } } return imageURLs.ToArray(); }
/// <summary> /// Documentation under IChronozoomSVC /// </summary> BaseJsonResult<IEnumerable<Bing.WebResult>> IBingSearchAPI.GetDocuments(string query, string doctype, string top, string skip) { return ApiOperation<BaseJsonResult<IEnumerable<Bing.WebResult>>>(delegate(User user, Storage storage) { var searchResults = new List<Bing.WebResult>(); if (string.IsNullOrEmpty(BingAccountKey) && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"])) { BingAccountKey = ConfigurationManager.AppSettings["AzureMarketplaceAccountKey"]; } #if RELEASE if (user == null) { // Setting status code to 403 to prevent redirection to authentication resource if status code is 401. SetStatusCode(HttpStatusCode.Forbidden, ErrorDescription.UnauthorizedUser); return new BaseJsonResult<IEnumerable<Bing.WebResult>>(searchResults); } #endif int resultsCount = int.TryParse(top, out resultsCount) ? resultsCount : BingDefaultSearchLimit; int offset = int.TryParse(skip, out offset) ? offset : BingDefaultOffset; try { var bingContainer = new Bing.BingSearchContainer(new Uri(BingAPIRootUrl)); bingContainer.Credentials = new NetworkCredential(BingAccountKey, BingAccountKey); var webQuery = bingContainer.Web(query, null, null, null, null, null, null, doctype); webQuery = webQuery.AddQueryOption("$top", resultsCount); webQuery = webQuery.AddQueryOption("$skip", offset); var webResults = webQuery.Execute(); foreach (var result in webResults) { searchResults.Add(result); } } catch (ArgumentNullException) { SetStatusCode(HttpStatusCode.BadRequest, ErrorDescription.NullSearchQuery); } catch (System.Data.Services.Client.DataServiceQueryException ex) { if (ex.InnerException != null) { SetStatusCode(HttpStatusCode.NotFound, ex.InnerException.Message); } else { SetStatusCode(HttpStatusCode.NotFound, ex.Message); } } catch (Exception ex) { SetStatusCode(HttpStatusCode.InternalServerError, ex.Message); } return new BaseJsonResult<IEnumerable<Bing.WebResult>>(searchResults); }); }
private string[] GetImages(string year, string make, string model, string trim) { string query = string.Concat(year, " ", make, " ", model, " ", trim); // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // My account key. var accountKey = "SFqfTsHuISE5EHYum81ONhrG5Eji5oaqZqGmv2QwjjM="; // Configure bingContainer to use my credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var imageResults = bingContainer.Image(query, null, null, null, null, null, null)// Build the query but do not executy the query .AddQueryOption("$top", 5)//limit images returned to 5 .Execute();//execute the query List<string> images = new List<string>(); foreach (var results in imageResults) { images.Add(results.Thumbnail.MediaUrl); } return images.ToArray(); }
private void searchButton_Click(object sender, RoutedEventArgs e) { if (searchBox.Text != "") { currentSearch++; progressBar.Visibility = Visibility.Visible; grid1.RowDefinitions.Clear(); grid1.Children.Clear(); var accountKey = "XXQj7RFCzyb5w0QR0xhLd3g3pFCu4zRuBKhwJ/25Vh0="; AppSettings settings = new AppSettings(); var bingContainer = new Bing.BingSearchContainer( new Uri("https://api.datamarket.azure.com/Bing/Search/")); bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); bingContainer.UseDefaultCredentials = false; var imageQuery = bingContainer.Image(searchBox.Text, null, "en-US", null, null, null, "Size:Medium"); imageQuery = imageQuery.AddQueryOption("$top", settings.bingMaxResults); imageQuery.BeginExecute(new AsyncCallback(this.ImageResultLoadedCallback), imageQuery); } else { progressBar.Visibility = Visibility.Collapsed; MessageBox.Show("No results"); } }
/// <summary> /// This section searches for the top 5 photos of the selected car from Bing using year, make, model and trim as the parameters /// We create a Bing container and pass the assigned key for credentials /// </summary> /// <param name="year"></param> /// <param name="make"></param> /// <param name="model"></param> /// <param name="trim"></param> /// <returns></returns> private string[] GetImages(string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "i52CgTJWkEZb7wR4q0/XNKItRAQrkaUAFZuijkBao+k="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); //extract the properties needed for the images List<string> images = new List<string>(); foreach (var result in imageResults) { images.Add(result.MediaUrl); } return images.ToArray(); }
private string[] GetImages (string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = ""; if (trim == null) query = year + " " + make + " " + model; else query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "ZMMsPNe6jZ6qK372fUwv7eaneomhgGw3jxLrwr0w2nk="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 6); var imageResults = imageQuery.Execute(); //extract the properties needed for the images List<string> images = new List<string>(); foreach (var result in imageResults) { if( UrlCtrl.IsUrl(result.MediaUrl)) { images.Add(result.MediaUrl); } } return images.ToArray(); }
private void OnCommandBing_AzureAPI(string Source, string Query) { try { Bing.BingSearchContainer SearchService = new Bing.BingSearchContainer(new Uri(BingAzureBaseURL)); SearchService.Credentials = new NetworkCredential(BingApplicationKey, BingApplicationKey); DataServiceQuery<Bing.WebResult> ServiceQuery = SearchService.Web(Query, "en-US", "Moderate", null, null, null); Bing.WebResult Result = ServiceQuery.Execute().FirstOrDefault(); if (Result == null) SendMessage(SendType.Message, Source, "No results."); else SendMessage(SendType.Message, Source, String.Format("{0}: {1} - {2}", Result.Title, Result.Url, Result.Description)); } catch (Exception) { SendMessage(SendType.Message, Source, String.Format("Unable to retrieve search results for {0}.", Query)); } }
async Task doSearch(ImageSearchQuery state, int imageOffset) { if (String.IsNullOrEmpty(state.Query) || String.IsNullOrWhiteSpace(state.Query)) { return; } var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(BingAccountKey.accountKey, BingAccountKey.accountKey); // Build the query. String imageFilters = null; if (!state.Size.Equals(size[0])) { imageFilters = "Size:" + state.Size; } if (!state.Layout.Equals(layout[0])) { if (imageFilters != null) { imageFilters += "+"; } imageFilters += "Aspect:" + state.Layout; } if (!state.Type.Equals(type[0])) { if (imageFilters != null) { imageFilters += "+"; } imageFilters += "Style:" + state.Type; } if (!state.People.Equals(type[0])) { if (imageFilters != null) { imageFilters += "+"; } imageFilters += "Face:" + state.People; } if (!state.Color.Equals(type[0])) { if (imageFilters != null) { imageFilters += "+"; } imageFilters += "Color:" + state.Color; } var imageQuery = bingContainer.Image(Query, null, null, state.SafeSearch, state.GeoTag.LatDecimal, state.GeoTag.LonDecimal, imageFilters); imageQuery = imageQuery.AddQueryOption("$top", 50); imageQuery = imageQuery.AddQueryOption("$skip", imageOffset); IEnumerable <Bing.ImageResult> imageResults = await Task.Factory.FromAsync <IEnumerable <Bing.ImageResult> >(imageQuery.BeginExecute(null, null), imageQuery.EndExecute); if (imageOffset == 0) { MediaState.clearUIState(Query, DateTime.Now, MediaStateType.SearchResult); } List <MediaItem> results = new List <MediaItem>(); int relevance = imageOffset; MediaState.UIMediaCollection.EnterReadLock(); foreach (var image in imageResults) { MediaItem item = new ImageResultItem(image, relevance); if (MediaState.UIMediaCollection.Contains(item)) { continue; } results.Add(item); relevance++; } MediaState.UIMediaCollection.ExitReadLock(); MediaState.addUIState(results); }
/* This class will get images for year, make, and model */ private string[] GetImages(string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "B7fUsZ3RushD0tSHsGmJfD2UywS5m4cpIlJ9v5Uca/M="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); //extract the properties need for the images List<string> images = new List<string>(); //for each results in this collection foreach (var result in imageResults) { if (UrlCtrl.IsUrl(result.MediaUrl)) { images.Add(result.MediaUrl); } else { continue; } } //matching and converting into strings. return images.ToArray(); }
// Next, we need to retrieve image URLs that match our car selections. We will need to set up our // Azure accounts to work with the Bing Search API to do so. https://datamarket.azure.com private string[] GetImages(string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // BingSearchContainer is a proprietary way to access the Bing api // Replace this value with your account key. var accountKey = "/7AIpfB3zsaqbfg8L/DsttX/YgDqetIK7xv3iZo+hKw="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential("accountKey", accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); // caps the image urls to only 5 (the top 5 results). otherwise it's 50 by default var imageResults = imageQuery.Execute(); // extract the properties needed for the images List<string> imageURLs = new List<string>(); foreach (var result in imageResults) { imageURLs.Add(result.MediaUrl); } return imageURLs.ToArray(); }
private string[] GetImages(string year, string make, string model) { string query = string.Concat(year," ", make, " ", model); string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); var accountKey = "SFqfTsHuISE5EHYum81ONhrG5Eji5oaqZqGmv2QwjjM="; bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); var imageResults = bingContainer.Image(query, null, null, null, null, null, null).AddQueryOption("$top", 5).Execute(); List<string> images = new List<string>(); foreach (var results in imageResults) { images.Add(results.Thumbnail.MediaUrl); } return images.ToArray(); }
private string[] GetImages(string year, string make, string model, string trim) { // This is the query - or you could get it from args. string query = year + " " + make + " " + model + " " + trim; // Create a Bing container. string rootUri = "https://api.datamarket.azure.com/Bing/Search"; var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri)); // Replace this value with your account key. var accountKey = "gfVShPxSX5M5xEOjsZCXHyVdHx8xm4g0RK2BpLUx1zw="; // Configure bingContainer to use your credentials. bingContainer.Credentials = new NetworkCredential(accountKey, accountKey); // Build the query. var imageQuery = bingContainer.Image(query, null, null, null, null, null, null); imageQuery = imageQuery.AddQueryOption("$top", 5); var imageResults = imageQuery.Execute(); //extract the properties needed for the images //check to make sure that each picture is valid List<string> images = new List<string>(); foreach (var result in imageResults) { WebRequest webRequest = WebRequest.Create(result.MediaUrl); webRequest.Timeout = 1200; // miliseconds webRequest.Method = "HEAD"; WebResponse res = null; try { res = webRequest.GetResponse(); images.Add(result.MediaUrl); } catch { } finally { if (res != null) { res.Close(); } } } return images.ToArray(); }