Search commonalities

For all the APIs we have covered, there are a few similarities. We will cover these now.

Languages

It is highly recommended to specify which market you want results for. Searches will typically return results for the local market and language of the user, based on the current location. As you can imagine, this is not always what the user wants. By specifying the market, you can tailor the search results for the user.

How you choose to solve this technically is dependent on the requirements of your application. For a smart-house application, you would probably allow the user to set the market in the settings. For a web application created only for French users in France, you would probably not allow the user to change the market.

Specifying the market is done by adding the mkt parameter to the GET request. This should then specify the market code, for example, en-US for English in the United States.

Note

While any API may support a specific market, some features may not support a given market.

A subset of the languages supported is English, Spanish, German, Dutch, French, Portuguese, Traditional Chinese, Italian, Russian, and Arabic.

In addition, we can specify a cc parameter to the GET request. This specifies a country (typically, the country the user is in). This parameter should be in the form of a two-letter country code, for instance, GB for United Kingdom.

A wide variety of countries can be specified, and the list is continuously subject to change.

Pagination

Some searches may yield a large number of results. In these cases, you may want to perform pagination. This can be achieved by specifying the count and offset parameters in the GET request.

If you want 10 results per page, you would start by setting the count to 10, and the offset to 0 for the first page. When the user navigates to the next page, you would keep the count at 10, but increase the offset to 10. For the next page, you would increase the offset to 20, and so on.

The maximum number of results returned in each query (the count parameter) varies for each API. See the following table for the current maximum count per API:

API

Maximum search results

Default search results

Bing News Search

100

10

Bing Web Search

50

10

Bing Image Search

150

35

Bing Video Search

105

35

Filters

We have seen some filters for individual APIs. In addition to these, there are a couple of filters which can be applied to all searches.

Safe search

The safe search filter can be used to filter search results for adult content. This parameter is added in the request URL.

The safeSearch parameter can be one of the following values:

  • Off: All result items will be returned
  • Moderate: Result items can contain adult text, but no adult images or videos will be included
  • Strict: No adult text, images, or videos are included in the result items

Note that, if the IP address of the user indicates a location that requires the Strict safe search, this setting will be ignored. Bing will, in this case, default to the Strict policy.

If the parameter has not been set, it defaults to moderate.

Freshness

By adding the freshness parameter to a request, you can filter search results based on the age of result items. The values that can be specified are as follows:

  • Day: Results from the last 24 hours
  • Week: Results from the last 7 days
  • Month: Results from the last 30 days

Errors

Among all the APIs we have covered, there are a few possible response codes that you may receive for each request. The following table describes all of the possible response codes:

Code

Description

200

Successful request.

400

One or more required query parameters are missing, or one of the parameters is invalid. More details are described in the ErrorResponse field.

401

The provided subscription key is invalid or missing.

403

Typically returned if the monthly quota is exceeded. Can also be used if the caller does not have permission to access the requested resource.

410

The HTTP protocol has been used instead of HTTPS, which is the only supported protocol.

429

The quota per second has been exceeded.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.251.206