< Summary

Class:Azure.Search.Documents.IndexesRestClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\IndexesRestClient.cs
Covered lines:200
Uncovered lines:70
Coverable lines:270
Total lines:615
Line coverage:74% (200 of 270)
Covered branches:48
Total branches:94
Branch coverage:51% (48 of 94)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-81.82%50%
CreateCreateRequest(...)-93.75%50%
CreateAsync()-90%75%
Create(...)-90%75%
CreateListRequest(...)-92.86%75%
ListAsync()-87.5%50%
List(...)-87.5%50%
CreateCreateOrUpdateRequest(...)-92%75%
CreateOrUpdateAsync()-75%50%
CreateOrUpdate(...)-75%50%
CreateDeleteRequest(...)-83.33%50%
DeleteAsync()-87.5%66.67%
Delete(...)-25%16.67%
CreateGetRequest(...)-92.86%50%
GetAsync()-90%75%
Get(...)-90%75%
CreateGetStatisticsRequest(...)-0%0%
GetStatisticsAsync()-0%0%
GetStatistics(...)-0%0%
CreateAnalyzeRequest(...)-94.44%50%
AnalyzeAsync()-75%50%
Analyze(...)-75%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Generated\IndexesRestClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// <auto-generated/>
 5
 6#nullable disable
 7
 8using System;
 9using System.Text.Json;
 10using System.Threading;
 11using System.Threading.Tasks;
 12using Azure;
 13using Azure.Core;
 14using Azure.Core.Pipeline;
 15using Azure.Search.Documents.Indexes.Models;
 16
 17namespace 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
 1734        public IndexesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint, Guid? xMsC
 35        {
 1736            if (endpoint == null)
 37            {
 038                throw new ArgumentNullException(nameof(endpoint));
 39            }
 1740            if (apiVersion == null)
 41            {
 042                throw new ArgumentNullException(nameof(apiVersion));
 43            }
 44
 1745            this.endpoint = endpoint;
 1746            this.xMsClientRequestId = xMsClientRequestId;
 1747            this.apiVersion = apiVersion;
 1748            _clientDiagnostics = clientDiagnostics;
 1749            _pipeline = pipeline;
 1750        }
 51
 52        internal HttpMessage CreateCreateRequest(SearchIndex index)
 53        {
 854            var message = _pipeline.CreateMessage();
 855            var request = message.Request;
 856            request.Method = RequestMethod.Post;
 857            var uri = new RawRequestUriBuilder();
 858            uri.AppendRaw(endpoint, false);
 859            uri.AppendPath("/indexes", false);
 860            uri.AppendQuery("api-version", apiVersion, true);
 861            request.Uri = uri;
 862            if (xMsClientRequestId != null)
 63            {
 064                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 65            }
 866            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 867            request.Headers.Add("Content-Type", "application/json");
 868            var content = new Utf8JsonRequestContent();
 869            content.JsonWriter.WriteObjectValue(index);
 870            request.Content = content;
 871            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        {
 480            if (index == null)
 81            {
 182                throw new ArgumentNullException(nameof(index));
 83            }
 84
 385            using var message = CreateCreateRequest(index);
 386            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 387            switch (message.Response.Status)
 88            {
 89                case 201:
 90                    {
 91                        SearchIndex value = default;
 392                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 393                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 394                        return Response.FromValue(value, message.Response);
 95                    }
 96                default:
 097                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 98            }
 399        }
 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        {
 6107            if (index == null)
 108            {
 1109                throw new ArgumentNullException(nameof(index));
 110            }
 111
 5112            using var message = CreateCreateRequest(index);
 5113            _pipeline.Send(message, cancellationToken);
 5114            switch (message.Response.Status)
 115            {
 116                case 201:
 117                    {
 118                        SearchIndex value = default;
 5119                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 5120                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 5121                        return Response.FromValue(value, message.Response);
 122                    }
 123                default:
 0124                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 125            }
 5126        }
 127
 128        internal HttpMessage CreateListRequest(string select)
 129        {
 2130            var message = _pipeline.CreateMessage();
 2131            var request = message.Request;
 2132            request.Method = RequestMethod.Get;
 2133            var uri = new RawRequestUriBuilder();
 2134            uri.AppendRaw(endpoint, false);
 2135            uri.AppendPath("/indexes", false);
 2136            if (select != null)
 137            {
 2138                uri.AppendQuery("$select", select, true);
 139            }
 2140            uri.AppendQuery("api-version", apiVersion, true);
 2141            request.Uri = uri;
 2142            if (xMsClientRequestId != null)
 143            {
 0144                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 145            }
 2146            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2147            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        {
 1155            using var message = CreateListRequest(select);
 1156            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1157            switch (message.Response.Status)
 158            {
 159                case 200:
 160                    {
 161                        ListIndexesResult value = default;
 1162                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1163                        value = ListIndexesResult.DeserializeListIndexesResult(document.RootElement);
 1164                        return Response.FromValue(value, message.Response);
 165                    }
 166                default:
 0167                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 168            }
 1169        }
 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        {
 1176            using var message = CreateListRequest(select);
 1177            _pipeline.Send(message, cancellationToken);
 1178            switch (message.Response.Status)
 179            {
 180                case 200:
 181                    {
 182                        ListIndexesResult value = default;
 1183                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1184                        value = ListIndexesResult.DeserializeListIndexesResult(document.RootElement);
 1185                        return Response.FromValue(value, message.Response);
 186                    }
 187                default:
 0188                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 189            }
 1190        }
 191
 192        internal HttpMessage CreateCreateOrUpdateRequest(string indexName, SearchIndex index, bool? allowIndexDowntime, 
 193        {
 2194            var message = _pipeline.CreateMessage();
 2195            var request = message.Request;
 2196            request.Method = RequestMethod.Put;
 2197            var uri = new RawRequestUriBuilder();
 2198            uri.AppendRaw(endpoint, false);
 2199            uri.AppendPath("/indexes('", false);
 2200            uri.AppendPath(indexName, true);
 2201            uri.AppendPath("')", false);
 2202            if (allowIndexDowntime != null)
 203            {
 2204                uri.AppendQuery("allowIndexDowntime", allowIndexDowntime.Value, true);
 205            }
 2206            uri.AppendQuery("api-version", apiVersion, true);
 2207            request.Uri = uri;
 2208            if (xMsClientRequestId != null)
 209            {
 0210                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 211            }
 2212            if (ifMatch != null)
 213            {
 2214                request.Headers.Add("If-Match", ifMatch);
 215            }
 2216            if (ifNoneMatch != null)
 217            {
 0218                request.Headers.Add("If-None-Match", ifNoneMatch);
 219            }
 2220            request.Headers.Add("Prefer", "return=representation");
 2221            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2222            request.Headers.Add("Content-Type", "application/json");
 2223            var content = new Utf8JsonRequestContent();
 2224            content.JsonWriter.WriteObjectValue(index);
 2225            request.Content = content;
 2226            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        {
 1239            if (indexName == null)
 240            {
 0241                throw new ArgumentNullException(nameof(indexName));
 242            }
 1243            if (index == null)
 244            {
 0245                throw new ArgumentNullException(nameof(index));
 246            }
 247
 1248            using var message = CreateCreateOrUpdateRequest(indexName, index, allowIndexDowntime, ifMatch, ifNoneMatch);
 1249            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1250            switch (message.Response.Status)
 251            {
 252                case 200:
 253                case 201:
 254                    {
 255                        SearchIndex value = default;
 1256                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1257                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 1258                        return Response.FromValue(value, message.Response);
 259                    }
 260                default:
 0261                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 262            }
 1263        }
 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        {
 1275            if (indexName == null)
 276            {
 0277                throw new ArgumentNullException(nameof(indexName));
 278            }
 1279            if (index == null)
 280            {
 0281                throw new ArgumentNullException(nameof(index));
 282            }
 283
 1284            using var message = CreateCreateOrUpdateRequest(indexName, index, allowIndexDowntime, ifMatch, ifNoneMatch);
 1285            _pipeline.Send(message, cancellationToken);
 1286            switch (message.Response.Status)
 287            {
 288                case 200:
 289                case 201:
 290                    {
 291                        SearchIndex value = default;
 1292                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1293                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 1294                        return Response.FromValue(value, message.Response);
 295                    }
 296                default:
 0297                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 298            }
 1299        }
 300
 301        internal HttpMessage CreateDeleteRequest(string indexName, string ifMatch, string ifNoneMatch)
 302        {
 1303            var message = _pipeline.CreateMessage();
 1304            var request = message.Request;
 1305            request.Method = RequestMethod.Delete;
 1306            var uri = new RawRequestUriBuilder();
 1307            uri.AppendRaw(endpoint, false);
 1308            uri.AppendPath("/indexes('", false);
 1309            uri.AppendPath(indexName, true);
 1310            uri.AppendPath("')", false);
 1311            uri.AppendQuery("api-version", apiVersion, true);
 1312            request.Uri = uri;
 1313            if (xMsClientRequestId != null)
 314            {
 0315                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 316            }
 1317            if (ifMatch != null)
 318            {
 0319                request.Headers.Add("If-Match", ifMatch);
 320            }
 1321            if (ifNoneMatch != null)
 322            {
 0323                request.Headers.Add("If-None-Match", ifNoneMatch);
 324            }
 1325            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 1326            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        {
 2337            if (indexName == null)
 338            {
 1339                throw new ArgumentNullException(nameof(indexName));
 340            }
 341
 1342            using var message = CreateDeleteRequest(indexName, ifMatch, ifNoneMatch);
 1343            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1344            switch (message.Response.Status)
 345            {
 346                case 204:
 347                case 404:
 1348                    return message.Response;
 349                default:
 0350                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 351            }
 1352        }
 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        {
 1362            if (indexName == null)
 363            {
 1364                throw new ArgumentNullException(nameof(indexName));
 365            }
 366
 0367            using var message = CreateDeleteRequest(indexName, ifMatch, ifNoneMatch);
 0368            _pipeline.Send(message, cancellationToken);
 0369            switch (message.Response.Status)
 370            {
 371                case 204:
 372                case 404:
 0373                    return message.Response;
 374                default:
 0375                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 376            }
 0377        }
 378
 379        internal HttpMessage CreateGetRequest(string indexName)
 380        {
 2381            var message = _pipeline.CreateMessage();
 2382            var request = message.Request;
 2383            request.Method = RequestMethod.Get;
 2384            var uri = new RawRequestUriBuilder();
 2385            uri.AppendRaw(endpoint, false);
 2386            uri.AppendPath("/indexes('", false);
 2387            uri.AppendPath(indexName, true);
 2388            uri.AppendPath("')", false);
 2389            uri.AppendQuery("api-version", apiVersion, true);
 2390            request.Uri = uri;
 2391            if (xMsClientRequestId != null)
 392            {
 0393                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 394            }
 2395            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2396            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        {
 2405            if (indexName == null)
 406            {
 1407                throw new ArgumentNullException(nameof(indexName));
 408            }
 409
 1410            using var message = CreateGetRequest(indexName);
 1411            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1412            switch (message.Response.Status)
 413            {
 414                case 200:
 415                    {
 416                        SearchIndex value = default;
 1417                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1418                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 1419                        return Response.FromValue(value, message.Response);
 420                    }
 421                default:
 0422                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 423            }
 1424        }
 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        {
 2432            if (indexName == null)
 433            {
 1434                throw new ArgumentNullException(nameof(indexName));
 435            }
 436
 1437            using var message = CreateGetRequest(indexName);
 1438            _pipeline.Send(message, cancellationToken);
 1439            switch (message.Response.Status)
 440            {
 441                case 200:
 442                    {
 443                        SearchIndex value = default;
 1444                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1445                        value = SearchIndex.DeserializeSearchIndex(document.RootElement);
 1446                        return Response.FromValue(value, message.Response);
 447                    }
 448                default:
 0449                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 450            }
 1451        }
 452
 453        internal HttpMessage CreateGetStatisticsRequest(string indexName)
 454        {
 0455            var message = _pipeline.CreateMessage();
 0456            var request = message.Request;
 0457            request.Method = RequestMethod.Get;
 0458            var uri = new RawRequestUriBuilder();
 0459            uri.AppendRaw(endpoint, false);
 0460            uri.AppendPath("/indexes('", false);
 0461            uri.AppendPath(indexName, true);
 0462            uri.AppendPath("')/search.stats", false);
 0463            uri.AppendQuery("api-version", apiVersion, true);
 0464            request.Uri = uri;
 0465            if (xMsClientRequestId != null)
 466            {
 0467                request.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 468            }
 0469            request.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 0470            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        {
 0479            if (indexName == null)
 480            {
 0481                throw new ArgumentNullException(nameof(indexName));
 482            }
 483
 0484            using var message = CreateGetStatisticsRequest(indexName);
 0485            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 0486            switch (message.Response.Status)
 487            {
 488                case 200:
 489                    {
 490                        SearchIndexStatistics value = default;
 0491                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 0492                        value = SearchIndexStatistics.DeserializeSearchIndexStatistics(document.RootElement);
 0493                        return Response.FromValue(value, message.Response);
 494                    }
 495                default:
 0496                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 497            }
 0498        }
 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        {
 0506            if (indexName == null)
 507            {
 0508                throw new ArgumentNullException(nameof(indexName));
 509            }
 510
 0511            using var message = CreateGetStatisticsRequest(indexName);
 0512            _pipeline.Send(message, cancellationToken);
 0513            switch (message.Response.Status)
 514            {
 515                case 200:
 516                    {
 517                        SearchIndexStatistics value = default;
 0518                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 0519                        value = SearchIndexStatistics.DeserializeSearchIndexStatistics(document.RootElement);
 0520                        return Response.FromValue(value, message.Response);
 521                    }
 522                default:
 0523                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 524            }
 0525        }
 526
 527        internal HttpMessage CreateAnalyzeRequest(string indexName, AnalyzeTextOptions request)
 528        {
 2529            var message = _pipeline.CreateMessage();
 2530            var request0 = message.Request;
 2531            request0.Method = RequestMethod.Post;
 2532            var uri = new RawRequestUriBuilder();
 2533            uri.AppendRaw(endpoint, false);
 2534            uri.AppendPath("/indexes('", false);
 2535            uri.AppendPath(indexName, true);
 2536            uri.AppendPath("')/search.analyze", false);
 2537            uri.AppendQuery("api-version", apiVersion, true);
 2538            request0.Uri = uri;
 2539            if (xMsClientRequestId != null)
 540            {
 0541                request0.Headers.Add("x-ms-client-request-id", xMsClientRequestId.Value);
 542            }
 2543            request0.Headers.Add("Accept", "application/json; odata.metadata=minimal");
 2544            request0.Headers.Add("Content-Type", "application/json");
 2545            var content = new Utf8JsonRequestContent();
 2546            content.JsonWriter.WriteObjectValue(request);
 2547            request0.Content = content;
 2548            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        {
 1558            if (indexName == null)
 559            {
 0560                throw new ArgumentNullException(nameof(indexName));
 561            }
 1562            if (request == null)
 563            {
 0564                throw new ArgumentNullException(nameof(request));
 565            }
 566
 1567            using var message = CreateAnalyzeRequest(indexName, request);
 1568            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
 1569            switch (message.Response.Status)
 570            {
 571                case 200:
 572                    {
 573                        AnalyzeResult value = default;
 1574                        using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc
 1575                        value = AnalyzeResult.DeserializeAnalyzeResult(document.RootElement);
 1576                        return Response.FromValue(value, message.Response);
 577                    }
 578                default:
 0579                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa
 580            }
 1581        }
 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        {
 1590            if (indexName == null)
 591            {
 0592                throw new ArgumentNullException(nameof(indexName));
 593            }
 1594            if (request == null)
 595            {
 0596                throw new ArgumentNullException(nameof(request));
 597            }
 598
 1599            using var message = CreateAnalyzeRequest(indexName, request);
 1600            _pipeline.Send(message, cancellationToken);
 1601            switch (message.Response.Status)
 602            {
 603                case 200:
 604                    {
 605                        AnalyzeResult value = default;
 1606                        using var document = JsonDocument.Parse(message.Response.ContentStream);
 1607                        value = AnalyzeResult.DeserializeAnalyzeResult(document.RootElement);
 1608                        return Response.FromValue(value, message.Response);
 609                    }
 610                default:
 0611                    throw _clientDiagnostics.CreateRequestFailedException(message.Response);
 612            }
 1613        }
 614    }
 615}