Home > Uncategorized > Bing Image search using #Cognitive Search

Bing Image search using #Cognitive Search

bing speech

The Bing Image search based on the DataMarket service by Microsoft is closing down, and it is moving to cognitive services. This means that if you have code that uses an endpoint like this;

https://api.datamarket.azure.com/Bing/Search/v1/Image

It needs to be changed to code like this:

https://api.cognitive.microsoft.com/bing/v5.0/images/search

And your quote is reduced to 1,000 per month… 😦

Here’s some code I’ve written in C# to do a basic image search

public static List<String> GetImages(string searchText)
{
var strUrl = “https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=&#8221; + searchText + “&count=1000”;
var wc = new WebClient();
wc.Headers[“Ocp-Apim-Subscription-Key”] = “xxxxxxxxxxx”;
var strJson = wc.DownloadString(strUrl);
var bing = JavascriptDeserialize<BingSearchObject>(strJson);
var lResults = new List<string>();
foreach (var result in bing.value)
{
var qs = HttpUtility.ParseQueryString(result.contentUrl);
lResults.Add(qs[“r”]);

}
return lResults;
}

Where “BingSearchObject” is defined as:

#region BingSearchResults
public class Instrumentation
{
public string pageLoadPingUrl { get; set; }
}

public class Thumbnail
{
public int width { get; set; }
public int height { get; set; }
}

public class InsightsSourcesSummary
{
public int shoppingSourcesCount { get; set; }
public int recipeSourcesCount { get; set; }
}

public class Value
{
public string name { get; set; }
public string webSearchUrl { get; set; }
public string thumbnailUrl { get; set; }
public string datePublished { get; set; }
public string contentUrl { get; set; }
public string hostPageUrl { get; set; }
public string contentSize { get; set; }
public string encodingFormat { get; set; }
public string hostPageDisplayUrl { get; set; }
public int width { get; set; }
public int height { get; set; }
public Thumbnail thumbnail { get; set; }
public string imageInsightsToken { get; set; }
public InsightsSourcesSummary insightsSourcesSummary { get; set; }
public string imageId { get; set; }
public string accentColor { get; set; }
}

public class Thumbnail2
{
public string thumbnailUrl { get; set; }
}

public class QueryExpansion
{
public string text { get; set; }
public string displayText { get; set; }
public string webSearchUrl { get; set; }
public string searchLink { get; set; }
public Thumbnail2 thumbnail { get; set; }
}

public class Thumbnail3
{
public string thumbnailUrl { get; set; }
}

public class Suggestion
{
public string text { get; set; }
public string displayText { get; set; }
public string webSearchUrl { get; set; }
public string searchLink { get; set; }
public Thumbnail3 thumbnail { get; set; }
}

public class PivotSuggestion
{
public string pivot { get; set; }
public List<Suggestion> suggestions { get; set; }
}

public class Thumbnail4
{
public string url { get; set; }
}

public class SimilarTerm
{
public string text { get; set; }
public string displayText { get; set; }
public string webSearchUrl { get; set; }
public Thumbnail4 thumbnail { get; set; }
}

public class BingSearchObject
{
public string _type { get; set; }
public Instrumentation instrumentation { get; set; }
public string readLink { get; set; }
public string webSearchUrl { get; set; }
public int totalEstimatedMatches { get; set; }
public List<Value> value { get; set; }
public List<QueryExpansion> queryExpansions { get; set; }
public int nextOffsetAddCount { get; set; }
public List<PivotSuggestion> pivotSuggestions { get; set; }
public bool displayShoppingSourcesBadges { get; set; }
public bool displayRecipeSourcesBadges { get; set; }
public List<SimilarTerm> similarTerms { get; set; }
}
#endregion

Advertisements
Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: