Skip to content

Commit

Permalink
Upgraded intelligence-SimilarProducts to latest Web Search API (v7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Stein committed Jan 19, 2018
1 parent 230594b commit f68857d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ public class BingImageResponse

public BingImageInstrumentation Instrumentation { get; set; }

public List<BingImageVisuallySimilarProduct> VisuallySimilarProducts { get; set; }
public ValueList<BingImageVisuallySimilarProduct> VisuallySimilarProducts { get; set; }

public string ImageInsightsToken { get; set; }
}

public class ValueList<T>
{
public List<T> Value { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BingImageSearchService : IImageSearchService
/// <summary>
/// The bing API URL.
/// </summary>
private static readonly string BingApiUrl = "https://api.cognitive.microsoft.com/bing/v5.0/images/search?modulesRequested=SimilarProducts&mkt=en-us&form=BCSPRD";
private static readonly string BingApiUrl = "https://api.cognitive.microsoft.com/bing/v7.0/images/details?modules=SimilarProducts&mkt=en-us";

/// <summary>
/// Gets a list of visually similar products from an image URL.
Expand All @@ -43,7 +43,7 @@ public async Task<IList<ImageResult>> GetSimilarProductImagesAsync(string url)
var text = await httpClient.GetStringAsync(apiUrl);
var response = JsonConvert.DeserializeObject<BingImageResponse>(text);

return response?.VisuallySimilarProducts?.Select(i => new ImageResult
return response?.VisuallySimilarProducts?.Value.Select(i => new ImageResult
{
HostPageDisplayUrl = i.HostPageDisplayUrl,
HostPageUrl = i.HostPageUrl,
Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task<IList<ImageResult>> GetSimilarProductImagesAsync(Stream stream
var text = await postResponse.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<BingImageResponse>(text);

return response?.VisuallySimilarProducts?.Select(i => new ImageResult
return response?.VisuallySimilarProducts?.Value.Select(i => new ImageResult
{
HostPageDisplayUrl = i.HostPageDisplayUrl,
HostPageUrl = i.HostPageUrl,
Expand Down

0 comments on commit f68857d

Please sign in to comment.