neolei neolei - 1 month ago 9
C# Question

Bing API image search filter

I'm using Bing Sharp 2.0. I'd like to do image search by filters, so I follow the codes in sample:

SearchRequest searchRequest = new SearchRequest { AppId = appId, Query = query, Market = "en-US" };
ImageRequest imageRequest = new ImageRequest();
imageRequest.Filters = buildFilterArray();
imageRequest.Count = imageCount;
imageRequest.Offset = (imageCount * pageNumber);
ImageResponse response = API.Image(searchRequest, imageRequest);

And this is buildFilterArray:

private string[] BuildFilterArray()
List<string> filters = new List<string>();
return filters.ToArray();

But the result comes back nothing (response.Total == 0).

I found the reason is because I specified 2 filters in buildFilterArray(), as long as I remove one (no matter which one), my search comes back with expected results.

This also proved by issuing http get request directly from IE, This returns results:

While this not:

Am I doing anything wrong? How can I put more than one filters into search request?

Answer Source

This is actually quite a simple fix...

You will see in your second one "Image.Filters=Size:Medium&Image.Filters=Size:Small" That the image filters bit is repeated. Change it to:


or even:


and both return results.