| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.Search.Documents.Indexes.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.Search.Documents |
| | 18 | | { |
| | 19 | | internal partial class IndexesRestClient |
| | 20 | | { |
| | 21 | | private string endpoint; |
| | 22 | | private Guid? xMsClientRequestId; |
| | 23 | | private string apiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of IndexesRestClient. </summary> |
| | 28 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 29 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 30 | | /// <param name="endpoint"> The endpoint URL of the search service. </param> |
| | 31 | | /// <param name="xMsClientRequestId"> The tracking ID sent with the request to help with debugging. </param> |
| | 32 | | /// <param name="apiVersion"> Api Version. </param> |
| | 33 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> or <paramref name="apiVersion"/> is nul |
| 17 | 34 | | public IndexesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMsC |
| | 35 | | { |
| 17 | 36 | | if (endpoint == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 39 | | } |
| 17 | 40 | | if (apiVersion == null) |
| | 41 | | { |
| 0 | 42 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 43 | | } |
| | 44 | |
|
| 17 | 45 | | this.endpoint = endpoint; |
| 17 | 46 | | this.xMsClientRequestId = xMsClientRequestId; |
| 17 | 47 | | this.apiVersion = apiVersion; |
| 17 | 48 | | _clientDiagnostics = clientDiagnostics; |
| 17 | 49 | | _pipeline = pipeline; |
| 17 | 50 | | } |
| | 51 | |
|
| | 52 | | internal HttpMessage CreateCreateRequest(SearchIndex index) |
| | 53 | | { |
| 8 | 54 | | var message = _pipeline.CreateMessage(); |
| 8 | 55 | | var request = message.Request; |
| 8 | 56 | | request.Method = RequestMethod.Post; |
| 8 | 57 | | var uri = new RawRequestUriBuilder(); |
| 8 | 58 | | uri.AppendRaw(endpoint, false); |
| 8 | 59 | | uri.AppendPath("/indexes", false); |
| 8 | 60 | | uri.AppendQuery("api-version", apiVersion, true); |
| 8 | 61 | | request.Uri = uri; |
| 8 | 62 | | if (xMsClientRequestId != null) |
| | 63 | | { |
| 0 | 64 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 65 | | } |
| 8 | 66 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 8 | 67 | | request.Headers.Add("Content-Type", "application/json"); |
| 8 | 68 | | var content = new Utf8JsonRequestContent(); |
| 8 | 69 | | content.JsonWriter.WriteObjectValue(index); |
| 8 | 70 | | request.Content = content; |
| 8 | 71 | | return message; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | /// <summary> Creates a new search index. </summary> |
| | 75 | | /// <param name="index"> The definition of the index to create. </param> |
| | 76 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 77 | | /// <exception cref="ArgumentNullException"> <paramref name="index"/> is null. </exception> |
| | 78 | | public async Task<Response<SearchIndex>> CreateAsync(SearchIndex index, CancellationToken cancellationToken = de |
| | 79 | | { |
| 4 | 80 | | if (index == null) |
| | 81 | | { |
| 1 | 82 | | throw new ArgumentNullException(nameof(index)); |
| | 83 | | } |
| | 84 | |
|
| 3 | 85 | | using var message = CreateCreateRequest(index); |
| 3 | 86 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 3 | 87 | | switch (message.Response.Status) |
| | 88 | | { |
| | 89 | | case 201: |
| | 90 | | { |
| | 91 | | SearchIndex value = default; |
| 3 | 92 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 3 | 93 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 3 | 94 | | return Response.FromValue(value, message.Response); |
| | 95 | | } |
| | 96 | | default: |
| 0 | 97 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 98 | | } |
| 3 | 99 | | } |
| | 100 | |
|
| | 101 | | /// <summary> Creates a new search index. </summary> |
| | 102 | | /// <param name="index"> The definition of the index to create. </param> |
| | 103 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 104 | | /// <exception cref="ArgumentNullException"> <paramref name="index"/> is null. </exception> |
| | 105 | | public Response<SearchIndex> Create(SearchIndex index, CancellationToken cancellationToken = default) |
| | 106 | | { |
| 6 | 107 | | if (index == null) |
| | 108 | | { |
| 1 | 109 | | throw new ArgumentNullException(nameof(index)); |
| | 110 | | } |
| | 111 | |
|
| 5 | 112 | | using var message = CreateCreateRequest(index); |
| 5 | 113 | | _pipeline.Send(message, cancellationToken); |
| 5 | 114 | | switch (message.Response.Status) |
| | 115 | | { |
| | 116 | | case 201: |
| | 117 | | { |
| | 118 | | SearchIndex value = default; |
| 5 | 119 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 5 | 120 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 5 | 121 | | return Response.FromValue(value, message.Response); |
| | 122 | | } |
| | 123 | | default: |
| 0 | 124 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 125 | | } |
| 5 | 126 | | } |
| | 127 | |
|
| | 128 | | internal HttpMessage CreateListRequest(string select) |
| | 129 | | { |
| 2 | 130 | | var message = _pipeline.CreateMessage(); |
| 2 | 131 | | var request = message.Request; |
| 2 | 132 | | request.Method = RequestMethod.Get; |
| 2 | 133 | | var uri = new RawRequestUriBuilder(); |
| 2 | 134 | | uri.AppendRaw(endpoint, false); |
| 2 | 135 | | uri.AppendPath("/indexes", false); |
| 2 | 136 | | if (select != null) |
| | 137 | | { |
| 2 | 138 | | uri.AppendQuery("$select", select, true); |
| | 139 | | } |
| 2 | 140 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 141 | | request.Uri = uri; |
| 2 | 142 | | if (xMsClientRequestId != null) |
| | 143 | | { |
| 0 | 144 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 145 | | } |
| 2 | 146 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 147 | | return message; |
| | 148 | | } |
| | 149 | |
|
| | 150 | | /// <summary> Lists all indexes available for a search service. </summary> |
| | 151 | | /// <param name="select"> Selects which top-level properties of the index definitions to retrieve. Specified as |
| | 152 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 153 | | public async Task<Response<ListIndexesResult>> ListAsync(string select = null, CancellationToken cancellationTok |
| | 154 | | { |
| 1 | 155 | | using var message = CreateListRequest(select); |
| 1 | 156 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 157 | | switch (message.Response.Status) |
| | 158 | | { |
| | 159 | | case 200: |
| | 160 | | { |
| | 161 | | ListIndexesResult value = default; |
| 1 | 162 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 163 | | value = ListIndexesResult.DeserializeListIndexesResult(document.RootElement); |
| 1 | 164 | | return Response.FromValue(value, message.Response); |
| | 165 | | } |
| | 166 | | default: |
| 0 | 167 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 168 | | } |
| 1 | 169 | | } |
| | 170 | |
|
| | 171 | | /// <summary> Lists all indexes available for a search service. </summary> |
| | 172 | | /// <param name="select"> Selects which top-level properties of the index definitions to retrieve. Specified as |
| | 173 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 174 | | public Response<ListIndexesResult> List(string select = null, CancellationToken cancellationToken = default) |
| | 175 | | { |
| 1 | 176 | | using var message = CreateListRequest(select); |
| 1 | 177 | | _pipeline.Send(message, cancellationToken); |
| 1 | 178 | | switch (message.Response.Status) |
| | 179 | | { |
| | 180 | | case 200: |
| | 181 | | { |
| | 182 | | ListIndexesResult value = default; |
| 1 | 183 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 184 | | value = ListIndexesResult.DeserializeListIndexesResult(document.RootElement); |
| 1 | 185 | | return Response.FromValue(value, message.Response); |
| | 186 | | } |
| | 187 | | default: |
| 0 | 188 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 189 | | } |
| 1 | 190 | | } |
| | 191 | |
|
| | 192 | | internal HttpMessage CreateCreateOrUpdateRequest(string indexName, SearchIndex index, bool? allowIndexDowntime, |
| | 193 | | { |
| 2 | 194 | | var message = _pipeline.CreateMessage(); |
| 2 | 195 | | var request = message.Request; |
| 2 | 196 | | request.Method = RequestMethod.Put; |
| 2 | 197 | | var uri = new RawRequestUriBuilder(); |
| 2 | 198 | | uri.AppendRaw(endpoint, false); |
| 2 | 199 | | uri.AppendPath("/indexes('", false); |
| 2 | 200 | | uri.AppendPath(indexName, true); |
| 2 | 201 | | uri.AppendPath("')", false); |
| 2 | 202 | | if (allowIndexDowntime != null) |
| | 203 | | { |
| 2 | 204 | | uri.AppendQuery("allowIndexDowntime", allowIndexDowntime.Value, true); |
| | 205 | | } |
| 2 | 206 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 207 | | request.Uri = uri; |
| 2 | 208 | | if (xMsClientRequestId != null) |
| | 209 | | { |
| 0 | 210 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 211 | | } |
| 2 | 212 | | if (ifMatch != null) |
| | 213 | | { |
| 2 | 214 | | request.Headers.Add("If-Match", ifMatch); |
| | 215 | | } |
| 2 | 216 | | if (ifNoneMatch != null) |
| | 217 | | { |
| 0 | 218 | | request.Headers.Add("If-None-Match", ifNoneMatch); |
| | 219 | | } |
| 2 | 220 | | request.Headers.Add("Prefer", "return=representation"); |
| 2 | 221 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 222 | | request.Headers.Add("Content-Type", "application/json"); |
| 2 | 223 | | var content = new Utf8JsonRequestContent(); |
| 2 | 224 | | content.JsonWriter.WriteObjectValue(index); |
| 2 | 225 | | request.Content = content; |
| 2 | 226 | | return message; |
| | 227 | | } |
| | 228 | |
|
| | 229 | | /// <summary> Creates a new search index or updates an index if it already exists. </summary> |
| | 230 | | /// <param name="indexName"> The definition of the index to create or update. </param> |
| | 231 | | /// <param name="index"> The definition of the index to create or update. </param> |
| | 232 | | /// <param name="allowIndexDowntime"> Allows new analyzers, tokenizers, token filters, or char filters to be add |
| | 233 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 234 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 235 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 236 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> or <paramref name="index"/> is null. < |
| | 237 | | public async Task<Response<SearchIndex>> CreateOrUpdateAsync(string indexName, SearchIndex index, bool? allowInd |
| | 238 | | { |
| 1 | 239 | | if (indexName == null) |
| | 240 | | { |
| 0 | 241 | | throw new ArgumentNullException(nameof(indexName)); |
| | 242 | | } |
| 1 | 243 | | if (index == null) |
| | 244 | | { |
| 0 | 245 | | throw new ArgumentNullException(nameof(index)); |
| | 246 | | } |
| | 247 | |
|
| 1 | 248 | | using var message = CreateCreateOrUpdateRequest(indexName, index, allowIndexDowntime, ifMatch, ifNoneMatch); |
| 1 | 249 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 250 | | switch (message.Response.Status) |
| | 251 | | { |
| | 252 | | case 200: |
| | 253 | | case 201: |
| | 254 | | { |
| | 255 | | SearchIndex value = default; |
| 1 | 256 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 257 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 1 | 258 | | return Response.FromValue(value, message.Response); |
| | 259 | | } |
| | 260 | | default: |
| 0 | 261 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 262 | | } |
| 1 | 263 | | } |
| | 264 | |
|
| | 265 | | /// <summary> Creates a new search index or updates an index if it already exists. </summary> |
| | 266 | | /// <param name="indexName"> The definition of the index to create or update. </param> |
| | 267 | | /// <param name="index"> The definition of the index to create or update. </param> |
| | 268 | | /// <param name="allowIndexDowntime"> Allows new analyzers, tokenizers, token filters, or char filters to be add |
| | 269 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 270 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 271 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 272 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> or <paramref name="index"/> is null. < |
| | 273 | | public Response<SearchIndex> CreateOrUpdate(string indexName, SearchIndex index, bool? allowIndexDowntime = null |
| | 274 | | { |
| 1 | 275 | | if (indexName == null) |
| | 276 | | { |
| 0 | 277 | | throw new ArgumentNullException(nameof(indexName)); |
| | 278 | | } |
| 1 | 279 | | if (index == null) |
| | 280 | | { |
| 0 | 281 | | throw new ArgumentNullException(nameof(index)); |
| | 282 | | } |
| | 283 | |
|
| 1 | 284 | | using var message = CreateCreateOrUpdateRequest(indexName, index, allowIndexDowntime, ifMatch, ifNoneMatch); |
| 1 | 285 | | _pipeline.Send(message, cancellationToken); |
| 1 | 286 | | switch (message.Response.Status) |
| | 287 | | { |
| | 288 | | case 200: |
| | 289 | | case 201: |
| | 290 | | { |
| | 291 | | SearchIndex value = default; |
| 1 | 292 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 293 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 1 | 294 | | return Response.FromValue(value, message.Response); |
| | 295 | | } |
| | 296 | | default: |
| 0 | 297 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 298 | | } |
| 1 | 299 | | } |
| | 300 | |
|
| | 301 | | internal HttpMessage CreateDeleteRequest(string indexName, string ifMatch, string ifNoneMatch) |
| | 302 | | { |
| 1 | 303 | | var message = _pipeline.CreateMessage(); |
| 1 | 304 | | var request = message.Request; |
| 1 | 305 | | request.Method = RequestMethod.Delete; |
| 1 | 306 | | var uri = new RawRequestUriBuilder(); |
| 1 | 307 | | uri.AppendRaw(endpoint, false); |
| 1 | 308 | | uri.AppendPath("/indexes('", false); |
| 1 | 309 | | uri.AppendPath(indexName, true); |
| 1 | 310 | | uri.AppendPath("')", false); |
| 1 | 311 | | uri.AppendQuery("api-version", apiVersion, true); |
| 1 | 312 | | request.Uri = uri; |
| 1 | 313 | | if (xMsClientRequestId != null) |
| | 314 | | { |
| 0 | 315 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 316 | | } |
| 1 | 317 | | if (ifMatch != null) |
| | 318 | | { |
| 0 | 319 | | request.Headers.Add("If-Match", ifMatch); |
| | 320 | | } |
| 1 | 321 | | if (ifNoneMatch != null) |
| | 322 | | { |
| 0 | 323 | | request.Headers.Add("If-None-Match", ifNoneMatch); |
| | 324 | | } |
| 1 | 325 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 1 | 326 | | return message; |
| | 327 | | } |
| | 328 | |
|
| | 329 | | /// <summary> Deletes a search index and all the documents it contains. This operation is permanent, with no rec |
| | 330 | | /// <param name="indexName"> The name of the index to delete. </param> |
| | 331 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 332 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 333 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 334 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 335 | | public async Task<Response> DeleteAsync(string indexName, string ifMatch = null, string ifNoneMatch = null, Canc |
| | 336 | | { |
| 2 | 337 | | if (indexName == null) |
| | 338 | | { |
| 1 | 339 | | throw new ArgumentNullException(nameof(indexName)); |
| | 340 | | } |
| | 341 | |
|
| 1 | 342 | | using var message = CreateDeleteRequest(indexName, ifMatch, ifNoneMatch); |
| 1 | 343 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 344 | | switch (message.Response.Status) |
| | 345 | | { |
| | 346 | | case 204: |
| | 347 | | case 404: |
| 1 | 348 | | return message.Response; |
| | 349 | | default: |
| 0 | 350 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 351 | | } |
| 1 | 352 | | } |
| | 353 | |
|
| | 354 | | /// <summary> Deletes a search index and all the documents it contains. This operation is permanent, with no rec |
| | 355 | | /// <param name="indexName"> The name of the index to delete. </param> |
| | 356 | | /// <param name="ifMatch"> Defines the If-Match condition. The operation will be performed only if the ETag on t |
| | 357 | | /// <param name="ifNoneMatch"> Defines the If-None-Match condition. The operation will be performed only if the |
| | 358 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 359 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 360 | | public Response Delete(string indexName, string ifMatch = null, string ifNoneMatch = null, CancellationToken can |
| | 361 | | { |
| 1 | 362 | | if (indexName == null) |
| | 363 | | { |
| 1 | 364 | | throw new ArgumentNullException(nameof(indexName)); |
| | 365 | | } |
| | 366 | |
|
| 0 | 367 | | using var message = CreateDeleteRequest(indexName, ifMatch, ifNoneMatch); |
| 0 | 368 | | _pipeline.Send(message, cancellationToken); |
| 0 | 369 | | switch (message.Response.Status) |
| | 370 | | { |
| | 371 | | case 204: |
| | 372 | | case 404: |
| 0 | 373 | | return message.Response; |
| | 374 | | default: |
| 0 | 375 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 376 | | } |
| 0 | 377 | | } |
| | 378 | |
|
| | 379 | | internal HttpMessage CreateGetRequest(string indexName) |
| | 380 | | { |
| 2 | 381 | | var message = _pipeline.CreateMessage(); |
| 2 | 382 | | var request = message.Request; |
| 2 | 383 | | request.Method = RequestMethod.Get; |
| 2 | 384 | | var uri = new RawRequestUriBuilder(); |
| 2 | 385 | | uri.AppendRaw(endpoint, false); |
| 2 | 386 | | uri.AppendPath("/indexes('", false); |
| 2 | 387 | | uri.AppendPath(indexName, true); |
| 2 | 388 | | uri.AppendPath("')", false); |
| 2 | 389 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 390 | | request.Uri = uri; |
| 2 | 391 | | if (xMsClientRequestId != null) |
| | 392 | | { |
| 0 | 393 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 394 | | } |
| 2 | 395 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 396 | | return message; |
| | 397 | | } |
| | 398 | |
|
| | 399 | | /// <summary> Retrieves an index definition. </summary> |
| | 400 | | /// <param name="indexName"> The name of the index to retrieve. </param> |
| | 401 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 402 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 403 | | public async Task<Response<SearchIndex>> GetAsync(string indexName, CancellationToken cancellationToken = defaul |
| | 404 | | { |
| 2 | 405 | | if (indexName == null) |
| | 406 | | { |
| 1 | 407 | | throw new ArgumentNullException(nameof(indexName)); |
| | 408 | | } |
| | 409 | |
|
| 1 | 410 | | using var message = CreateGetRequest(indexName); |
| 1 | 411 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 412 | | switch (message.Response.Status) |
| | 413 | | { |
| | 414 | | case 200: |
| | 415 | | { |
| | 416 | | SearchIndex value = default; |
| 1 | 417 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 418 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 1 | 419 | | return Response.FromValue(value, message.Response); |
| | 420 | | } |
| | 421 | | default: |
| 0 | 422 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 423 | | } |
| 1 | 424 | | } |
| | 425 | |
|
| | 426 | | /// <summary> Retrieves an index definition. </summary> |
| | 427 | | /// <param name="indexName"> The name of the index to retrieve. </param> |
| | 428 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 429 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 430 | | public Response<SearchIndex> Get(string indexName, CancellationToken cancellationToken = default) |
| | 431 | | { |
| 2 | 432 | | if (indexName == null) |
| | 433 | | { |
| 1 | 434 | | throw new ArgumentNullException(nameof(indexName)); |
| | 435 | | } |
| | 436 | |
|
| 1 | 437 | | using var message = CreateGetRequest(indexName); |
| 1 | 438 | | _pipeline.Send(message, cancellationToken); |
| 1 | 439 | | switch (message.Response.Status) |
| | 440 | | { |
| | 441 | | case 200: |
| | 442 | | { |
| | 443 | | SearchIndex value = default; |
| 1 | 444 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 445 | | value = SearchIndex.DeserializeSearchIndex(document.RootElement); |
| 1 | 446 | | return Response.FromValue(value, message.Response); |
| | 447 | | } |
| | 448 | | default: |
| 0 | 449 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 450 | | } |
| 1 | 451 | | } |
| | 452 | |
|
| | 453 | | internal HttpMessage CreateGetStatisticsRequest(string indexName) |
| | 454 | | { |
| 0 | 455 | | var message = _pipeline.CreateMessage(); |
| 0 | 456 | | var request = message.Request; |
| 0 | 457 | | request.Method = RequestMethod.Get; |
| 0 | 458 | | var uri = new RawRequestUriBuilder(); |
| 0 | 459 | | uri.AppendRaw(endpoint, false); |
| 0 | 460 | | uri.AppendPath("/indexes('", false); |
| 0 | 461 | | uri.AppendPath(indexName, true); |
| 0 | 462 | | uri.AppendPath("')/search.stats", false); |
| 0 | 463 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 464 | | request.Uri = uri; |
| 0 | 465 | | if (xMsClientRequestId != null) |
| | 466 | | { |
| 0 | 467 | | request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 468 | | } |
| 0 | 469 | | request.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 0 | 470 | | return message; |
| | 471 | | } |
| | 472 | |
|
| | 473 | | /// <summary> Returns statistics for the given index, including a document count and storage usage. </summary> |
| | 474 | | /// <param name="indexName"> The name of the index for which to retrieve statistics. </param> |
| | 475 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 476 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 477 | | public async Task<Response<SearchIndexStatistics>> GetStatisticsAsync(string indexName, CancellationToken cancel |
| | 478 | | { |
| 0 | 479 | | if (indexName == null) |
| | 480 | | { |
| 0 | 481 | | throw new ArgumentNullException(nameof(indexName)); |
| | 482 | | } |
| | 483 | |
|
| 0 | 484 | | using var message = CreateGetStatisticsRequest(indexName); |
| 0 | 485 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 486 | | switch (message.Response.Status) |
| | 487 | | { |
| | 488 | | case 200: |
| | 489 | | { |
| | 490 | | SearchIndexStatistics value = default; |
| 0 | 491 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 492 | | value = SearchIndexStatistics.DeserializeSearchIndexStatistics(document.RootElement); |
| 0 | 493 | | return Response.FromValue(value, message.Response); |
| | 494 | | } |
| | 495 | | default: |
| 0 | 496 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 497 | | } |
| 0 | 498 | | } |
| | 499 | |
|
| | 500 | | /// <summary> Returns statistics for the given index, including a document count and storage usage. </summary> |
| | 501 | | /// <param name="indexName"> The name of the index for which to retrieve statistics. </param> |
| | 502 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 503 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> is null. </exception> |
| | 504 | | public Response<SearchIndexStatistics> GetStatistics(string indexName, CancellationToken cancellationToken = def |
| | 505 | | { |
| 0 | 506 | | if (indexName == null) |
| | 507 | | { |
| 0 | 508 | | throw new ArgumentNullException(nameof(indexName)); |
| | 509 | | } |
| | 510 | |
|
| 0 | 511 | | using var message = CreateGetStatisticsRequest(indexName); |
| 0 | 512 | | _pipeline.Send(message, cancellationToken); |
| 0 | 513 | | switch (message.Response.Status) |
| | 514 | | { |
| | 515 | | case 200: |
| | 516 | | { |
| | 517 | | SearchIndexStatistics value = default; |
| 0 | 518 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 519 | | value = SearchIndexStatistics.DeserializeSearchIndexStatistics(document.RootElement); |
| 0 | 520 | | return Response.FromValue(value, message.Response); |
| | 521 | | } |
| | 522 | | default: |
| 0 | 523 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 524 | | } |
| 0 | 525 | | } |
| | 526 | |
|
| | 527 | | internal HttpMessage CreateAnalyzeRequest(string indexName, AnalyzeTextOptions request) |
| | 528 | | { |
| 2 | 529 | | var message = _pipeline.CreateMessage(); |
| 2 | 530 | | var request0 = message.Request; |
| 2 | 531 | | request0.Method = RequestMethod.Post; |
| 2 | 532 | | var uri = new RawRequestUriBuilder(); |
| 2 | 533 | | uri.AppendRaw(endpoint, false); |
| 2 | 534 | | uri.AppendPath("/indexes('", false); |
| 2 | 535 | | uri.AppendPath(indexName, true); |
| 2 | 536 | | uri.AppendPath("')/search.analyze", false); |
| 2 | 537 | | uri.AppendQuery("api-version", apiVersion, true); |
| 2 | 538 | | request0.Uri = uri; |
| 2 | 539 | | if (xMsClientRequestId != null) |
| | 540 | | { |
| 0 | 541 | | request0.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value); |
| | 542 | | } |
| 2 | 543 | | request0.Headers.Add("Accept", "application/json; odata.metadata=minimal"); |
| 2 | 544 | | request0.Headers.Add("Content-Type", "application/json"); |
| 2 | 545 | | var content = new Utf8JsonRequestContent(); |
| 2 | 546 | | content.JsonWriter.WriteObjectValue(request); |
| 2 | 547 | | request0.Content = content; |
| 2 | 548 | | return message; |
| | 549 | | } |
| | 550 | |
|
| | 551 | | /// <summary> Shows how an analyzer breaks text into tokens. </summary> |
| | 552 | | /// <param name="indexName"> The name of the index for which to test an analyzer. </param> |
| | 553 | | /// <param name="request"> The text and analyzer or analysis components to test. </param> |
| | 554 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 555 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> or <paramref name="request"/> is null. |
| | 556 | | public async Task<Response<AnalyzeResult>> AnalyzeAsync(string indexName, AnalyzeTextOptions request, Cancellati |
| | 557 | | { |
| 1 | 558 | | if (indexName == null) |
| | 559 | | { |
| 0 | 560 | | throw new ArgumentNullException(nameof(indexName)); |
| | 561 | | } |
| 1 | 562 | | if (request == null) |
| | 563 | | { |
| 0 | 564 | | throw new ArgumentNullException(nameof(request)); |
| | 565 | | } |
| | 566 | |
|
| 1 | 567 | | using var message = CreateAnalyzeRequest(indexName, request); |
| 1 | 568 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 1 | 569 | | switch (message.Response.Status) |
| | 570 | | { |
| | 571 | | case 200: |
| | 572 | | { |
| | 573 | | AnalyzeResult value = default; |
| 1 | 574 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 1 | 575 | | value = AnalyzeResult.DeserializeAnalyzeResult(document.RootElement); |
| 1 | 576 | | return Response.FromValue(value, message.Response); |
| | 577 | | } |
| | 578 | | default: |
| 0 | 579 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 580 | | } |
| 1 | 581 | | } |
| | 582 | |
|
| | 583 | | /// <summary> Shows how an analyzer breaks text into tokens. </summary> |
| | 584 | | /// <param name="indexName"> The name of the index for which to test an analyzer. </param> |
| | 585 | | /// <param name="request"> The text and analyzer or analysis components to test. </param> |
| | 586 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 587 | | /// <exception cref="ArgumentNullException"> <paramref name="indexName"/> or <paramref name="request"/> is null. |
| | 588 | | public Response<AnalyzeResult> Analyze(string indexName, AnalyzeTextOptions request, CancellationToken cancellat |
| | 589 | | { |
| 1 | 590 | | if (indexName == null) |
| | 591 | | { |
| 0 | 592 | | throw new ArgumentNullException(nameof(indexName)); |
| | 593 | | } |
| 1 | 594 | | if (request == null) |
| | 595 | | { |
| 0 | 596 | | throw new ArgumentNullException(nameof(request)); |
| | 597 | | } |
| | 598 | |
|
| 1 | 599 | | using var message = CreateAnalyzeRequest(indexName, request); |
| 1 | 600 | | _pipeline.Send(message, cancellationToken); |
| 1 | 601 | | switch (message.Response.Status) |
| | 602 | | { |
| | 603 | | case 200: |
| | 604 | | { |
| | 605 | | AnalyzeResult value = default; |
| 1 | 606 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 1 | 607 | | value = AnalyzeResult.DeserializeAnalyzeResult(document.RootElement); |
| 1 | 608 | | return Response.FromValue(value, message.Response); |
| | 609 | | } |
| | 610 | | default: |
| 0 | 611 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 612 | | } |
| 1 | 613 | | } |
| | 614 | | } |
| | 615 | | } |