| | 1 | | // <auto-generated> |
| | 2 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 3 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 4 | | // regenerated. |
| | 5 | | // </auto-generated> |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.Search.WebSearch |
| | 8 | | { |
| | 9 | | using Models; |
| | 10 | | using System.Collections; |
| | 11 | | using System.Collections.Generic; |
| | 12 | | using System.Threading; |
| | 13 | | using System.Threading.Tasks; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Extension methods for Web. |
| | 17 | | /// </summary> |
| | 18 | | public static partial class WebExtensions |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// The Web Search API lets you send a search query to Bing and get back search |
| | 22 | | /// results that include links to webpages, images, and more. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name='operations'> |
| | 25 | | /// The operations group for this extension method. |
| | 26 | | /// </param> |
| | 27 | | /// <param name='query'> |
| | 28 | | /// The user's search query term. The term may not be empty. The term may |
| | 29 | | /// contain Bing Advanced Operators. For example, to limit results to a |
| | 30 | | /// specific domain, use the site: operator. |
| | 31 | | /// </param> |
| | 32 | | /// <param name='acceptLanguage'> |
| | 33 | | /// A comma-delimited list of one or more languages to use for user interface |
| | 34 | | /// strings. The list is in decreasing order of preference. For additional |
| | 35 | | /// information, including expected format, see |
| | 36 | | /// [RFC2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). This |
| | 37 | | /// header and the setLang query parameter are mutually exclusive; do not |
| | 38 | | /// specify both. If you set this header, you must also specify the cc query |
| | 39 | | /// parameter. Bing will use the first supported language it finds from the |
| | 40 | | /// list, and combine that language with the cc parameter value to determine |
| | 41 | | /// the market to return results for. If the list does not include a supported |
| | 42 | | /// language, Bing will find the closest language and market that supports the |
| | 43 | | /// request, and may use an aggregated or default market for the results |
| | 44 | | /// instead of a specified one. You should use this header and the cc query |
| | 45 | | /// parameter only if you specify multiple languages; otherwise, you should use |
| | 46 | | /// the mkt and setLang query parameters. A user interface string is a string |
| | 47 | | /// that's used as a label in a user interface. There are very few user |
| | 48 | | /// interface strings in the JSON response objects. Any links in the response |
| | 49 | | /// objects to Bing.com properties will apply the specified language. |
| | 50 | | /// </param> |
| | 51 | | /// <param name='pragma'> |
| | 52 | | /// By default, Bing returns cached content, if available. To prevent Bing from |
| | 53 | | /// returning cached content, set the Pragma header to no-cache (for example, |
| | 54 | | /// Pragma: no-cache). |
| | 55 | | /// </param> |
| | 56 | | /// <param name='userAgent'> |
| | 57 | | /// The user agent originating the request. Bing uses the user agent to provide |
| | 58 | | /// mobile users with an optimized experience. Although optional, you are |
| | 59 | | /// strongly encouraged to always specify this header. The user-agent should be |
| | 60 | | /// the same string that any commonly used browser would send. For information |
| | 61 | | /// about user agents, see [RFC |
| | 62 | | /// 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html). |
| | 63 | | /// </param> |
| | 64 | | /// <param name='clientId'> |
| | 65 | | /// Bing uses this header to provide users with consistent behavior across Bing |
| | 66 | | /// API calls. Bing often flights new features and improvements, and it uses |
| | 67 | | /// the client ID as a key for assigning traffic on different flights. If you |
| | 68 | | /// do not use the same client ID for a user across multiple requests, then |
| | 69 | | /// Bing may assign the user to multiple conflicting flights. Being assigned to |
| | 70 | | /// multiple conflicting flights can lead to an inconsistent user experience. |
| | 71 | | /// For example, if the second request has a different flight assignment than |
| | 72 | | /// the first, the experience may be unexpected. Also, Bing can use the client |
| | 73 | | /// ID to tailor web results to that client ID’s search history, providing a |
| | 74 | | /// richer experience for the user. Bing also uses this header to help improve |
| | 75 | | /// result rankings by analyzing the activity generated by a client ID. The |
| | 76 | | /// relevance improvements help with better quality of results delivered by |
| | 77 | | /// Bing APIs and in turn enables higher click-through rates for the API |
| | 78 | | /// consumer. IMPORTANT: Although optional, you should consider this header |
| | 79 | | /// required. Persisting the client ID across multiple requests for the same |
| | 80 | | /// end user and device combination enables 1) the API consumer to receive a |
| | 81 | | /// consistent user experience, and 2) higher click-through rates via better |
| | 82 | | /// quality of results from the Bing APIs. Each user that uses your application |
| | 83 | | /// on the device must have a unique, Bing generated client ID. If you do not |
| | 84 | | /// include this header in the request, Bing generates an ID and returns it in |
| | 85 | | /// the X-MSEdge-ClientID response header. The only time that you should NOT |
| | 86 | | /// include this header in a request is the first time the user uses your app |
| | 87 | | /// on that device. Use the client ID for each Bing API request that your app |
| | 88 | | /// makes for this user on the device. Persist the client ID. To persist the ID |
| | 89 | | /// in a browser app, use a persistent HTTP cookie to ensure the ID is used |
| | 90 | | /// across all sessions. Do not use a session cookie. For other apps such as |
| | 91 | | /// mobile apps, use the device's persistent storage to persist the ID. The |
| | 92 | | /// next time the user uses your app on that device, get the client ID that you |
| | 93 | | /// persisted. Bing responses may or may not include this header. If the |
| | 94 | | /// response includes this header, capture the client ID and use it for all |
| | 95 | | /// subsequent Bing requests for the user on that device. If you include the |
| | 96 | | /// X-MSEdge-ClientID, you must not include cookies in the request. |
| | 97 | | /// </param> |
| | 98 | | /// <param name='clientIp'> |
| | 99 | | /// The IPv4 or IPv6 address of the client device. The IP address is used to |
| | 100 | | /// discover the user's location. Bing uses the location information to |
| | 101 | | /// determine safe search behavior. Although optional, you are encouraged to |
| | 102 | | /// always specify this header and the X-Search-Location header. Do not |
| | 103 | | /// obfuscate the address (for example, by changing the last octet to 0). |
| | 104 | | /// Obfuscating the address results in the location not being anywhere near the |
| | 105 | | /// device's actual location, which may result in Bing serving erroneous |
| | 106 | | /// results. |
| | 107 | | /// </param> |
| | 108 | | /// <param name='location'> |
| | 109 | | /// A semicolon-delimited list of key/value pairs that describe the client's |
| | 110 | | /// geographical location. Bing uses the location information to determine safe |
| | 111 | | /// search behavior and to return relevant local content. Specify the key/value |
| | 112 | | /// pair as <key>:<value>. The following are the keys that you use |
| | 113 | | /// to specify the user's location. lat (required): The latitude of the |
| | 114 | | /// client's location, in degrees. The latitude must be greater than or equal |
| | 115 | | /// to -90.0 and less than or equal to +90.0. Negative values indicate southern |
| | 116 | | /// latitudes and positive values indicate northern latitudes. long (required): |
| | 117 | | /// The longitude of the client's location, in degrees. The longitude must be |
| | 118 | | /// greater than or equal to -180.0 and less than or equal to +180.0. Negative |
| | 119 | | /// values indicate western longitudes and positive values indicate eastern |
| | 120 | | /// longitudes. re (required): The radius, in meters, which specifies the |
| | 121 | | /// horizontal accuracy of the coordinates. Pass the value returned by the |
| | 122 | | /// device's location service. Typical values might be 22m for GPS/Wi-Fi, 380m |
| | 123 | | /// for cell tower triangulation, and 18,000m for reverse IP lookup. ts |
| | 124 | | /// (optional): The UTC UNIX timestamp of when the client was at the location. |
| | 125 | | /// (The UNIX timestamp is the number of seconds since January 1, 1970.) head |
| | 126 | | /// (optional): The client's relative heading or direction of travel. Specify |
| | 127 | | /// the direction of travel as degrees from 0 through 360, counting clockwise |
| | 128 | | /// relative to true north. Specify this key only if the sp key is nonzero. sp |
| | 129 | | /// (optional): The horizontal velocity (speed), in meters per second, that the |
| | 130 | | /// client device is traveling. alt (optional): The altitude of the client |
| | 131 | | /// device, in meters. are (optional): The radius, in meters, that specifies |
| | 132 | | /// the vertical accuracy of the coordinates. Specify this key only if you |
| | 133 | | /// specify the alt key. Although many of the keys are optional, the more |
| | 134 | | /// information that you provide, the more accurate the location results are. |
| | 135 | | /// Although optional, you are encouraged to always specify the user's |
| | 136 | | /// geographical location. Providing the location is especially important if |
| | 137 | | /// the client's IP address does not accurately reflect the user's physical |
| | 138 | | /// location (for example, if the client uses VPN). For optimal results, you |
| | 139 | | /// should include this header and the X-MSEdge-ClientIP header, but at a |
| | 140 | | /// minimum, you should include this header. |
| | 141 | | /// </param> |
| | 142 | | /// <param name='answerCount'> |
| | 143 | | /// The number of answers that you want the response to include. The answers |
| | 144 | | /// that Bing returns are based on ranking. For example, if Bing returns |
| | 145 | | /// webpages, images, videos, and relatedSearches for a request and you set |
| | 146 | | /// this parameter to two (2), the response includes webpages and images.If you |
| | 147 | | /// included the responseFilter query parameter in the same request and set it |
| | 148 | | /// to webpages and news, the response would include only webpages. |
| | 149 | | /// </param> |
| | 150 | | /// <param name='countryCode'> |
| | 151 | | /// A 2-character country code of the country where the results come from. This |
| | 152 | | /// API supports only the United States market. If you specify this query |
| | 153 | | /// parameter, it must be set to us. If you set this parameter, you must also |
| | 154 | | /// specify the Accept-Language header. Bing uses the first supported language |
| | 155 | | /// it finds from the languages list, and combine that language with the |
| | 156 | | /// country code that you specify to determine the market to return results |
| | 157 | | /// for. If the languages list does not include a supported language, Bing |
| | 158 | | /// finds the closest language and market that supports the request, or it may |
| | 159 | | /// use an aggregated or default market for the results instead of a specified |
| | 160 | | /// one. You should use this query parameter and the Accept-Language query |
| | 161 | | /// parameter only if you specify multiple languages; otherwise, you should use |
| | 162 | | /// the mkt and setLang query parameters. This parameter and the mkt query |
| | 163 | | /// parameter are mutually exclusive—do not specify both. |
| | 164 | | /// </param> |
| | 165 | | /// <param name='count'> |
| | 166 | | /// The number of search results to return in the response. The default is 10 |
| | 167 | | /// and the maximum value is 50. The actual number delivered may be less than |
| | 168 | | /// requested.Use this parameter along with the offset parameter to page |
| | 169 | | /// results.For example, if your user interface displays 10 search results per |
| | 170 | | /// page, set count to 10 and offset to 0 to get the first page of results. For |
| | 171 | | /// each subsequent page, increment offset by 10 (for example, 0, 10, 20). It |
| | 172 | | /// is possible for multiple pages to include some overlap in results. |
| | 173 | | /// </param> |
| | 174 | | /// <param name='freshness'> |
| | 175 | | /// Filter search results by the following age values: Day—Return webpages that |
| | 176 | | /// Bing discovered within the last 24 hours. Week—Return webpages that Bing |
| | 177 | | /// discovered within the last 7 days. Month—Return webpages that discovered |
| | 178 | | /// within the last 30 days. This filter applies only to webpage results and |
| | 179 | | /// not to the other results such as news and images. Possible values include: |
| | 180 | | /// 'Day', 'Week', 'Month' |
| | 181 | | /// </param> |
| | 182 | | /// <param name='market'> |
| | 183 | | /// The market where the results come from. Typically, mkt is the country where |
| | 184 | | /// the user is making the request from. However, it could be a different |
| | 185 | | /// country if the user is not located in a country where Bing delivers |
| | 186 | | /// results. The market must be in the form <language code>-<country |
| | 187 | | /// code>. For example, en-US. The string is case insensitive. If known, you |
| | 188 | | /// are encouraged to always specify the market. Specifying the market helps |
| | 189 | | /// Bing route the request and return an appropriate and optimal response. If |
| | 190 | | /// you specify a market that is not listed in Market Codes, Bing uses a best |
| | 191 | | /// fit market code based on an internal mapping that is subject to change. |
| | 192 | | /// This parameter and the cc query parameter are mutually exclusive—do not |
| | 193 | | /// specify both. |
| | 194 | | /// </param> |
| | 195 | | /// <param name='offset'> |
| | 196 | | /// The zero-based offset that indicates the number of search results to skip |
| | 197 | | /// before returning results. The default is 0. The offset should be less than |
| | 198 | | /// (totalEstimatedMatches - count). Use this parameter along with the count |
| | 199 | | /// parameter to page results. For example, if your user interface displays 10 |
| | 200 | | /// search results per page, set count to 10 and offset to 0 to get the first |
| | 201 | | /// page of results. For each subsequent page, increment offset by 10 (for |
| | 202 | | /// example, 0, 10, 20). it is possible for multiple pages to include some |
| | 203 | | /// overlap in results. |
| | 204 | | /// </param> |
| | 205 | | /// <param name='promote'> |
| | 206 | | /// A comma-delimited list of answers that you want the response to include |
| | 207 | | /// regardless of their ranking. For example, if you set answerCount) to two |
| | 208 | | /// (2) so Bing returns the top two ranked answers, but you also want the |
| | 209 | | /// response to include news, you'd set promote to news. If the top ranked |
| | 210 | | /// answers are webpages, images, videos, and relatedSearches, the response |
| | 211 | | /// includes webpages and images because news is not a ranked answer. But if |
| | 212 | | /// you set promote to video, Bing would promote the video answer into the |
| | 213 | | /// response and return webpages, images, and videos. The answers that you want |
| | 214 | | /// to promote do not count against the answerCount limit. For example, if the |
| | 215 | | /// ranked answers are news, images, and videos, and you set answerCount to 1 |
| | 216 | | /// and promote to news, the response contains news and images. Or, if the |
| | 217 | | /// ranked answers are videos, images, and news, the response contains videos |
| | 218 | | /// and news. Possible values are Computation, Images, News, RelatedSearches, |
| | 219 | | /// SpellSuggestions, TimeZone, Videos, Webpages. Use only if you specify |
| | 220 | | /// answerCount. |
| | 221 | | /// </param> |
| | 222 | | /// <param name='responseFilter'> |
| | 223 | | /// A comma-delimited list of answers to include in the response. If you do not |
| | 224 | | /// specify this parameter, the response includes all search answers for which |
| | 225 | | /// there's relevant data. Possible filter values are Computation, Images, |
| | 226 | | /// News, RelatedSearches, SpellSuggestions, TimeZone, Videos, Webpages. |
| | 227 | | /// Although you may use this filter to get a single answer, you should instead |
| | 228 | | /// use the answer-specific endpoint in order to get richer results. For |
| | 229 | | /// example, to receive only images, send the request to one of the Image |
| | 230 | | /// Search API endpoints. The RelatedSearches and SpellSuggestions answers do |
| | 231 | | /// not support a separate endpoint like the Image Search API does (only the |
| | 232 | | /// Web Search API returns them). To include answers that would otherwise be |
| | 233 | | /// excluded because of ranking, see the promote query parameter. |
| | 234 | | /// </param> |
| | 235 | | /// <param name='safeSearch'> |
| | 236 | | /// A filter used to filter adult content. Off: Return webpages with adult |
| | 237 | | /// text, images, or videos. Moderate: Return webpages with adult text, but not |
| | 238 | | /// adult images or videos. Strict: Do not return webpages with adult text, |
| | 239 | | /// images, or videos. The default is Moderate. If the request comes from a |
| | 240 | | /// market that Bing's adult policy requires that safeSearch is set to Strict, |
| | 241 | | /// Bing ignores the safeSearch value and uses Strict. If you use the site: |
| | 242 | | /// query operator, there is the chance that the response may contain adult |
| | 243 | | /// content regardless of what the safeSearch query parameter is set to. Use |
| | 244 | | /// site: only if you are aware of the content on the site and your scenario |
| | 245 | | /// supports the possibility of adult content. Possible values include: 'Off', |
| | 246 | | /// 'Moderate', 'Strict' |
| | 247 | | /// </param> |
| | 248 | | /// <param name='setLang'> |
| | 249 | | /// The language to use for user interface strings. Specify the language using |
| | 250 | | /// the ISO 639-1 2-letter language code. For example, the language code for |
| | 251 | | /// English is EN. The default is EN (English). Although optional, you should |
| | 252 | | /// always specify the language. Typically, you set setLang to the same |
| | 253 | | /// language specified by mkt unless the user wants the user interface strings |
| | 254 | | /// displayed in a different language. This parameter and the Accept-Language |
| | 255 | | /// header are mutually exclusive; do not specify both. A user interface string |
| | 256 | | /// is a string that's used as a label in a user interface. There are few user |
| | 257 | | /// interface strings in the JSON response objects. Also, any links to Bing.com |
| | 258 | | /// properties in the response objects apply the specified language. |
| | 259 | | /// </param> |
| | 260 | | /// <param name='textDecorations'> |
| | 261 | | /// A Boolean value that determines whether display strings should contain |
| | 262 | | /// decoration markers such as hit highlighting characters. If true, the |
| | 263 | | /// strings may include markers. The default is false. To specify whether to |
| | 264 | | /// use Unicode characters or HTML tags as the markers, see the textFormat |
| | 265 | | /// query parameter. |
| | 266 | | /// </param> |
| | 267 | | /// <param name='textFormat'> |
| | 268 | | /// The type of markers to use for text decorations (see the textDecorations |
| | 269 | | /// query parameter). Possible values are Raw—Use Unicode characters to mark |
| | 270 | | /// content that needs special formatting. The Unicode characters are in the |
| | 271 | | /// range E000 through E019. For example, Bing uses E000 and E001 to mark the |
| | 272 | | /// beginning and end of query terms for hit highlighting. HTML—Use HTML tags |
| | 273 | | /// to mark content that needs special formatting. For example, use <b> |
| | 274 | | /// tags to highlight query terms in display strings. The default is Raw. For |
| | 275 | | /// display strings that contain escapable HTML characters such as <, >, |
| | 276 | | /// and &, if textFormat is set to HTML, Bing escapes the characters as |
| | 277 | | /// appropriate (for example, < is escaped to &lt;). Possible values |
| | 278 | | /// include: 'Raw', 'Html' |
| | 279 | | /// </param> |
| | 280 | | /// <param name='cancellationToken'> |
| | 281 | | /// The cancellation token. |
| | 282 | | /// </param> |
| | 283 | | public static async Task<SearchResponse> SearchAsync(this IWeb operations, string query, string acceptLangua |
| | 284 | | { |
| 2 | 285 | | using (var _result = await operations.SearchWithHttpMessagesAsync(query, acceptLanguage, pragma, userAge |
| | 286 | | { |
| 2 | 287 | | return _result.Body; |
| | 288 | | } |
| 2 | 289 | | } |
| | 290 | |
|
| | 291 | | } |
| | 292 | | } |