< Summary

Class:Azure.Search.Documents.Indexes.SearchIndexClient
Assembly:Azure.Search.Documents
File(s):C:\Git\azure-sdk-for-net\sdk\search\Azure.Search.Documents\src\Indexes\SearchIndexClient.cs
Covered lines:336
Uncovered lines:125
Coverable lines:461
Total lines:1295
Line coverage:72.8% (336 of 461)
Covered branches:33
Total branches:72
Branch coverage:45.8% (33 of 72)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor()-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Endpoint()-100%100%
get_ServiceName()-100%100%
get_ServiceClient()-100%100%
get_IndexesClient()-100%100%
get_SynonymMapsClient()-100%100%
GetSearchClient(...)-100%100%
GetServiceStatistics(...)-62.5%100%
GetServiceStatisticsAsync()-66.67%100%
AnalyzeText(...)-72.73%100%
AnalyzeTextAsync()-75%100%
CreateIndex(...)-100%100%
CreateIndexAsync()-100%100%
CreateOrUpdateIndex(...)-78.57%50%
CreateOrUpdateIndexAsync()-80%50%
DeleteIndex(...)-100%100%
DeleteIndexAsync()-100%100%
DeleteIndex(...)-16.67%0%
DeleteIndexAsync()-12.5%0%
DeleteIndex(...)-90.91%25%
DeleteIndexAsync()-100%25%
GetIndex(...)-100%100%
GetIndexAsync()-100%100%
GetIndexes(...)-78.95%50%
GetIndexesAsync(...)-85%100%
GetIndexNames(...)-0%0%
GetIndexNamesAsync(...)-0%100%
GetIndexStatistics(...)-0%100%
GetIndexStatisticsAsync()-0%100%
CreateSynonymMap(...)-100%100%
CreateSynonymMapAsync()-100%100%
CreateOrUpdateSynonymMap(...)-100%50%
CreateOrUpdateSynonymMapAsync()-100%50%
DeleteSynonymMap(...)-100%100%
DeleteSynonymMapAsync()-100%100%
DeleteSynonymMap(...)-100%50%
DeleteSynonymMapAsync()-100%50%
DeleteSynonymMap(...)-100%75%
DeleteSynonymMapAsync()-100%75%
GetSynonymMap(...)-100%100%
GetSynonymMapAsync()-100%100%
GetSynonymMaps(...)-0%100%
GetSynonymMapsAsync()-0%100%
GetSynonymMapNames(...)-72.73%100%
GetSynonymMapNamesAsync()-75%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Threading;
 8using System.Threading.Tasks;
 9using Azure.Core;
 10using Azure.Core.Pipeline;
 11#if EXPERIMENTAL_SERIALIZER
 12using Azure.Core.Serialization;
 13#endif
 14using Azure.Search.Documents.Indexes.Models;
 15
 16namespace Azure.Search.Documents.Indexes
 17{
 18    /// <summary>
 19    /// Azure Cognitive Search client that can be used to manage indexes on a Search service.
 20    /// </summary>
 21    public class SearchIndexClient
 22    {
 23        private readonly HttpPipeline _pipeline;
 24        private readonly ClientDiagnostics _clientDiagnostics;
 25        private readonly SearchClientOptions.ServiceVersion _version;
 26#if EXPERIMENTAL_SERIALIZER
 27        private readonly ObjectSerializer _serializer;
 28#endif
 29
 30        private ServiceRestClient _serviceClient;
 31        private IndexesRestClient _indexesClient;
 32        private SynonymMapsRestClient _synonymMapsClient;
 33        private string _serviceName;
 34
 35        /// <summary>
 36        /// Initializes a new instance of the <see cref="SearchIndexClient"/> class for mocking.
 37        /// </summary>
 19838        protected SearchIndexClient() { }
 39
 40        /// <summary>
 41        /// Initializes a new instance of the <see cref="SearchIndexClient"/> class.
 42        /// </summary>
 43        /// <param name="endpoint">Required. The URI endpoint of the Search service. This is likely to be similar to "ht
 44        /// <param name="credential">
 45        /// Required. The API key credential used to authenticate requests against the Search service.
 46        /// You need to use an admin key to perform any operations on the SearchIndexClient.
 47        /// See <see href="https://docs.microsoft.com/azure/search/search-security-api-keys">Create and manage api-keys 
 48        /// </param>
 49        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="endpoint"/> or <paramref name="crede
 50        /// <exception cref="ArgumentException">Thrown when the <paramref name="endpoint"/> is not using HTTPS.</excepti
 51        public SearchIndexClient(Uri endpoint, AzureKeyCredential credential) :
 2452            this(endpoint, credential, null)
 53        {
 1854        }
 55
 56        /// <summary>
 57        /// Initializes a new instance of the <see cref="SearchIndexClient"/> class.
 58        /// </summary>
 59        /// <param name="endpoint">Required. The URI endpoint of the Search service. This is likely to be similar to "ht
 60        /// <param name="credential">
 61        /// Required. The API key credential used to authenticate requests against the Search service.
 62        /// You need to use an admin key to perform any operations on the SearchIndexClient.
 63        /// See <see href="https://docs.microsoft.com/azure/search/search-security-api-keys">Create and manage api-keys 
 64        /// </param>
 65        /// <param name="options">Client configuration options for connecting to Azure Cognitive Search.</param>
 66        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="endpoint"/> or <paramref name="crede
 67        /// <exception cref="ArgumentException">Thrown when the <paramref name="endpoint"/> is not using HTTPS.</excepti
 12468        public SearchIndexClient(
 12469            Uri endpoint,
 12470            AzureKeyCredential credential,
 12471            SearchClientOptions options)
 72        {
 12473            Argument.AssertNotNull(endpoint, nameof(endpoint));
 12274            endpoint.AssertHttpsScheme(nameof(endpoint));
 12075            Argument.AssertNotNull(credential, nameof(credential));
 76
 11877            options ??= new SearchClientOptions();
 11878            Endpoint = endpoint;
 79#if EXPERIMENTAL_SERIALIZER
 11880            _serializer = options.Serializer;
 81#endif
 11882            _clientDiagnostics = new ClientDiagnostics(options);
 11883            _pipeline = options.Build(credential);
 11884            _version = options.Version;
 11885        }
 86
 87        /// <summary>
 88        /// Gets the URI endpoint of the Search service.  This is likely
 89        /// to be similar to "https://{search_service}.search.windows.net".
 90        /// </summary>
 11391        public virtual Uri Endpoint { get; }
 92
 93        /// <summary>
 94        /// Gets the name of the Search service.
 95        /// </summary>
 96        public virtual string ServiceName =>
 297            _serviceName ??= Endpoint.GetSearchServiceName();
 98
 99        /// <summary>
 100        /// Gets the generated <see cref="ServiceRestClient"/> to make requests.
 101        /// </summary>
 12102        private ServiceRestClient ServiceClient => LazyInitializer.EnsureInitialized(ref _serviceClient, () => new Servi
 12103            _clientDiagnostics,
 12104            _pipeline,
 12105            Endpoint.ToString(),
 12106            null,
 12107            _version.ToVersionString())
 6108        );
 109
 110        /// <summary>
 111        /// Gets the generated <see cref="IndexesRestClient"/> to make requests.
 112        /// </summary>
 40113        private IndexesRestClient IndexesClient => LazyInitializer.EnsureInitialized(ref _indexesClient, () => new Index
 40114            _clientDiagnostics,
 40115            _pipeline,
 40116            Endpoint.ToString(),
 40117            null,
 40118            _version.ToVersionString())
 23119        );
 120
 121        /// <summary>
 122        /// Gets the generated <see cref="SynonymMapsRestClient"/> to make requests.
 123        /// </summary>
 26124        private SynonymMapsRestClient SynonymMapsClient => LazyInitializer.EnsureInitialized(ref _synonymMapsClient, () 
 26125            _clientDiagnostics,
 26126            _pipeline,
 26127            Endpoint.ToString(),
 26128            null,
 26129            _version.ToVersionString())
 20130        );
 131
 132        /// <summary>
 133        /// Get a <see cref="SearchClient"/> for the given <paramref name="indexName"/> to use for document operations l
 134        /// </summary>
 135        /// <param name="indexName">The name of the desired Search Index.</param>
 136        /// <returns>A SearchClient for the desired Search Index.</returns>
 137        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="indexName"/> is null.</exception>
 138        /// <exception cref="ArgumentException">Thrown when the <paramref name="indexName"/> is empty.</exception>
 139        /// <remarks>
 140        /// The same request <see cref="HttpPipeline"/> (including authentication and any other configuration) will be u
 141        /// <see cref="SearchClient"/>.
 142        /// </remarks>
 143        public virtual SearchClient GetSearchClient(string indexName)
 144        {
 84145            Argument.AssertNotNullOrEmpty(indexName, nameof(indexName));
 80146            return new SearchClient(
 80147                Endpoint,
 80148                indexName,
 80149#if EXPERIMENTAL_SERIALIZER
 80150                _serializer,
 80151#endif
 80152                _pipeline,
 80153                _clientDiagnostics,
 80154                _version);
 155        }
 156
 157        #region Service operations
 158
 159        /// <summary>
 160        /// <para>
 161        /// Gets service level statistics for a Search service.
 162        /// </para>
 163        /// <para>
 164        /// This operation returns the number and type of objects in your
 165        /// service, the maximum allowed for each object type given the service
 166        /// tier, actual and maximum storage, and other limits that vary by
 167        /// tier. This request pulls information from the service so that you
 168        /// don't have to look up or calculate service limits.
 169        /// </para>
 170        /// <para>
 171        /// Statistics on document count and storage size are collected every
 172        /// few minutes, not in real time. Therefore, the statistics returned
 173        /// by this API may not reflect changes caused by recent indexing
 174        /// operations.
 175        /// </para>
 176        /// </summary>
 177        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 178        /// <returns>The <see cref="Response{T}"/> from the server containing <see cref="SearchServiceStatistics"/>.</re
 179        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 180        public virtual Response<SearchServiceStatistics> GetServiceStatistics(
 181            CancellationToken cancellationToken = default)
 182        {
 3183            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServic
 3184            scope.Start();
 185            try
 186            {
 3187                return ServiceClient.GetServiceStatistics(
 3188                    cancellationToken);
 189            }
 0190            catch (Exception ex)
 191            {
 0192                scope.Failed(ex);
 0193                throw;
 194            }
 3195        }
 196
 197        /// <summary>
 198        /// <para>
 199        /// Gets service level statistics for a Search service.
 200        /// </para>
 201        /// <para>
 202        /// This operation returns the number and type of objects in your
 203        /// service, the maximum allowed for each object type given the service
 204        /// tier, actual and maximum storage, and other limits that vary by
 205        /// tier. This request pulls information from the service so that you
 206        /// don't have to look up or calculate service limits.
 207        /// </para>
 208        /// <para>
 209        /// Statistics on document count and storage size are collected every
 210        /// few minutes, not in real time. Therefore, the statistics returned
 211        /// by this API may not reflect changes caused by recent indexing
 212        /// operations.
 213        /// </para>
 214        /// </summary>
 215        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 216        /// <returns>The <see cref="Response{T}"/> from the server containing <see cref="SearchServiceStatistics"/>.</re
 217        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 218        public virtual async Task<Response<SearchServiceStatistics>> GetServiceStatisticsAsync(
 219            CancellationToken cancellationToken = default)
 220        {
 3221            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServic
 3222            scope.Start();
 223            try
 224            {
 3225                return await ServiceClient.GetServiceStatisticsAsync(
 3226                    cancellationToken)
 3227                    .ConfigureAwait(false);
 228            }
 0229            catch (Exception ex)
 230            {
 0231                scope.Failed(ex);
 0232                throw;
 233            }
 3234        }
 235        #endregion
 236
 237        #region Index operations
 238        /// <summary>
 239        /// Shows how an analyzer breaks text into tokens.
 240        /// </summary>
 241        /// <param name="indexName">The name of the index used to test an analyzer.</param>
 242        /// <param name="options">The <see cref="AnalyzeTextOptions"/> containing the text and analyzer or analyzer comp
 243        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 244        /// <returns>
 245        /// The <see cref="Response{T}"/> from the server containing a list of <see cref="AnalyzedTokenInfo"/> for analy
 246        /// </returns>
 247        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="options"
 248        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 249        public virtual Response<IReadOnlyList<AnalyzedTokenInfo>> AnalyzeText(
 250            string indexName,
 251            AnalyzeTextOptions options,
 252            CancellationToken cancellationToken = default)
 253        {
 1254            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeTe
 1255            scope.Start();
 256            try
 257            {
 1258                Response<AnalyzeResult> result = IndexesClient.Analyze(
 1259                    indexName,
 1260                    options,
 1261                    cancellationToken);
 262
 1263                return Response.FromValue(result.Value.Tokens, result.GetRawResponse());
 264            }
 0265            catch (Exception ex)
 266            {
 0267                scope.Failed(ex);
 0268                throw;
 269            }
 1270        }
 271
 272        /// <summary>
 273        /// Shows how an analyzer breaks text into tokens.
 274        /// </summary>
 275        /// <param name="indexName">The name of the index used to test an analyzer.</param>
 276        /// <param name="options">The <see cref="AnalyzeTextOptions"/> containing the text and analyzer or analyzer comp
 277        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 278        /// <returns>
 279        /// The <see cref="Response{T}"/> from the server containing a list of <see cref="AnalyzedTokenInfo"/> for analy
 280        /// </returns>
 281        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> or <paramref name="options"
 282        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 283        public virtual async Task<Response<IReadOnlyList<AnalyzedTokenInfo>>> AnalyzeTextAsync(
 284            string indexName,
 285            AnalyzeTextOptions options,
 286            CancellationToken cancellationToken = default)
 287        {
 1288            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeTe
 1289            scope.Start();
 290            try
 291            {
 1292                Response<AnalyzeResult> result = await IndexesClient.AnalyzeAsync(
 1293                    indexName,
 1294                    options,
 1295                    cancellationToken)
 1296                    .ConfigureAwait(false);
 297
 1298                return Response.FromValue(result.Value.Tokens, result.GetRawResponse());
 299            }
 0300            catch (Exception ex)
 301            {
 0302                scope.Failed(ex);
 0303                throw;
 304            }
 1305        }
 306
 307        /// <summary>
 308        /// Creates a new search index.
 309        /// </summary>
 310        /// <param name="index">Required. The <see cref="SearchIndex"/> to create.</param>
 311        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 312        /// <returns>
 313        /// The <see cref="Response{T}"/> from the server containing the <see cref="SearchIndex"/> that was created.
 314        /// This may differ slightly from what was passed in since the service may return back fields set to their defau
 315        /// </returns>
 316        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 317        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 318        public virtual Response<SearchIndex> CreateIndex(
 319            SearchIndex index,
 320            CancellationToken cancellationToken = default)
 321        {
 6322            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateInd
 6323            scope.Start();
 324            try
 325            {
 6326                return IndexesClient.Create(
 6327                    index,
 6328                    cancellationToken);
 329            }
 1330            catch (Exception ex)
 331            {
 1332                scope.Failed(ex);
 1333                throw;
 334            }
 5335        }
 336
 337        /// <summary>
 338        /// Creates a new search index.
 339        /// </summary>
 340        /// <param name="index">Required. The <see cref="SearchIndex"/> to create.</param>
 341        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 342        /// <returns>
 343        /// The <see cref="Response{T}"/> from the server containing the <see cref="SearchIndex"/> that was created.
 344        /// This may differ slightly from what was passed in since the service may return back fields set to their defau
 345        /// </returns>
 346        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 347        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 348        public virtual async Task<Response<SearchIndex>> CreateIndexAsync(
 349            SearchIndex index,
 350            CancellationToken cancellationToken = default)
 351        {
 4352            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateInd
 4353            scope.Start();
 354            try
 355            {
 4356                return await IndexesClient.CreateAsync(
 4357                    index,
 4358                    cancellationToken)
 4359                    .ConfigureAwait(false);
 360            }
 1361            catch (Exception ex)
 362            {
 1363                scope.Failed(ex);
 1364                throw;
 365            }
 3366        }
 367
 368        /// <summary>
 369        /// Creates a new search index or updates an existing index.
 370        /// </summary>
 371        /// <param name="index">Required. The <see cref="SearchIndex"/> to create or update.</param>
 372        /// <param name="allowIndexDowntime">
 373        /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be 
 374        /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail.
 375        /// Performance and write availability of the index can be impaired for several minutes after the index is updat
 376        /// </param>
 377        /// <param name="onlyIfUnchanged">
 378        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SearchIndex.ETag"/> does not match th
 379        /// otherwise, the current service version will be overwritten.
 380        /// </param>
 381        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 382        /// <returns>
 383        /// The <see cref="Response{T}"/> from the server containing the <see cref="SearchIndex"/> that was created or u
 384        /// This may differ slightly from what was passed in since the service may return back fields set to their defau
 385        /// </returns>
 386        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 387        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 388        public virtual Response<SearchIndex> CreateOrUpdateIndex(
 389            SearchIndex index,
 390            bool allowIndexDowntime = false,
 391            bool onlyIfUnchanged = false,
 392            CancellationToken cancellationToken = default)
 393        {
 394            // Generated client validates indexName parameter first, which is not a parameter of this method.
 2395            Argument.AssertNotNull(index, nameof(index));
 396
 1397            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU
 1398            scope.Start();
 399            try
 400            {
 1401                return IndexesClient.CreateOrUpdate(
 1402                    index?.Name,
 1403                    index,
 1404                    allowIndexDowntime,
 1405                    onlyIfUnchanged ? index?.ETag?.ToString() : null,
 1406                    null,
 1407                    cancellationToken);
 408            }
 0409            catch (Exception ex)
 410            {
 0411                scope.Failed(ex);
 0412                throw;
 413            }
 1414        }
 415
 416        /// <summary>
 417        /// Creates a new search index or updates an existing index.
 418        /// </summary>
 419        /// <param name="index">Required. The <see cref="SearchIndex"/> to create or update.</param>
 420        /// <param name="allowIndexDowntime">
 421        /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be 
 422        /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail.
 423        /// Performance and write availability of the index can be impaired for several minutes after the index is updat
 424        /// </param>
 425        /// <param name="onlyIfUnchanged">
 426        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SearchIndex.ETag"/> does not match th
 427        /// otherwise, the current service version will be overwritten.
 428        /// </param>
 429        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 430        /// <returns>
 431        /// The <see cref="Response{T}"/> from the server containing the <see cref="SearchIndex"/> that was created or u
 432        /// This may differ slightly from what was passed in since the service may return back fields set to their defau
 433        /// </returns>
 434        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 435        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 436        public virtual async Task<Response<SearchIndex>> CreateOrUpdateIndexAsync(
 437            SearchIndex index,
 438            bool allowIndexDowntime = false,
 439            bool onlyIfUnchanged = false,
 440            CancellationToken cancellationToken = default)
 441        {
 442            // Generated client validates indexName parameter first, which is not a parameter of this method.
 2443            Argument.AssertNotNull(index, nameof(index));
 444
 1445            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU
 1446            scope.Start();
 447            try
 448            {
 1449                return await IndexesClient.CreateOrUpdateAsync(
 1450                    index?.Name,
 1451                    index,
 1452                    allowIndexDowntime,
 1453                    onlyIfUnchanged ? index?.ETag?.ToString() : null,
 1454                    null,
 1455                    cancellationToken)
 1456                    .ConfigureAwait(false);
 457            }
 0458            catch (Exception ex)
 459            {
 0460                scope.Failed(ex);
 0461                throw;
 462            }
 1463        }
 464
 465        /// <summary>
 466        /// Deletes a search index and all the documents it contains.
 467        /// </summary>
 468        /// <param name="indexName">Required. The name of the <see cref="SearchIndex"/> to delete.</param>
 469        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 470        /// <returns>The <see cref="Response"/> from the server.</returns>
 471        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 472        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 473        public virtual Response DeleteIndex(
 474            string indexName,
 1475            CancellationToken cancellationToken = default) => DeleteIndex(
 1476                indexName,
 1477                null,
 1478                false,
 1479                cancellationToken);
 480
 481        /// <summary>
 482        /// Deletes a search index and all the documents it contains.
 483        /// </summary>
 484        /// <param name="indexName">Required. The name of the <see cref="SearchIndex"/> to delete.</param>
 485        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 486        /// <returns>The <see cref="Response"/> from the server.</returns>
 487        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 488        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 489        public virtual async Task<Response> DeleteIndexAsync(
 490            string indexName,
 2491            CancellationToken cancellationToken = default) => await DeleteIndexAsync(
 2492                indexName,
 2493                null,
 2494                false,
 2495                cancellationToken)
 2496                .ConfigureAwait(false);
 497
 498        /// <summary>
 499        /// Deletes a search index and all the documents it contains.
 500        /// </summary>
 501        /// <param name="index">Required. The <see cref="SearchIndex"/> to delete.</param>
 502        /// <param name="onlyIfUnchanged">
 503        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SearchIndex.ETag"/> does not match th
 504        /// otherwise, the current service version will be overwritten.
 505        /// </param>
 506        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 507        /// <returns>The <see cref="Response"/> from the server.</returns>
 508        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 509        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 510        public virtual Response DeleteIndex(
 511            SearchIndex index,
 512            bool onlyIfUnchanged = false,
 513            CancellationToken cancellationToken = default)
 514        {
 515            // Generated client validates indexName parameter first, which is not a parameter of this method.
 1516            Argument.AssertNotNull(index, nameof(index));
 517
 0518            return DeleteIndex(
 0519                index?.Name,
 0520                index?.ETag,
 0521                onlyIfUnchanged,
 0522                cancellationToken);
 523        }
 524
 525        /// <summary>
 526        /// Deletes a search index and all the documents it contains.
 527        /// </summary>
 528        /// <param name="index">Required. The <see cref="SearchIndex"/> to delete.</param>
 529        /// <param name="onlyIfUnchanged">
 530        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SearchIndex.ETag"/> does not match th
 531        /// otherwise, the current service version will be overwritten.
 532        /// </param>
 533        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 534        /// <returns>The <see cref="Response"/> from the server.</returns>
 535        /// <exception cref="ArgumentNullException">Thrown when <paramref name="index"/> is null.</exception>
 536        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 537        public virtual async Task<Response> DeleteIndexAsync(
 538            SearchIndex index,
 539            bool onlyIfUnchanged = false,
 540            CancellationToken cancellationToken = default)
 541        {
 542            // Generated client validates indexName parameter first, which is not a parameter of this method.
 1543            Argument.AssertNotNull(index, nameof(index));
 544
 0545            return await DeleteIndexAsync(
 0546                index?.Name,
 0547                index?.ETag,
 0548                onlyIfUnchanged,
 0549                cancellationToken)
 0550                .ConfigureAwait(false);
 0551        }
 552
 553        private Response DeleteIndex(
 554            string indexName,
 555            ETag? etag,
 556            bool onlyIfUnchanged,
 557            CancellationToken cancellationToken)
 558        {
 1559            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteInd
 1560            scope.Start();
 561            try
 562            {
 1563                return IndexesClient.Delete(
 1564                    indexName,
 1565                    onlyIfUnchanged ? etag?.ToString() : null,
 1566                    null,
 1567                    cancellationToken);
 568            }
 1569            catch (Exception ex)
 570            {
 1571                scope.Failed(ex);
 1572                throw;
 573            }
 0574        }
 575
 576        private async Task<Response> DeleteIndexAsync(
 577            string indexName,
 578            ETag? etag,
 579            bool onlyIfUnchanged,
 580            CancellationToken cancellationToken)
 581        {
 2582            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteInd
 2583            scope.Start();
 584            try
 585            {
 2586                return await IndexesClient.DeleteAsync(
 2587                    indexName,
 2588                    onlyIfUnchanged ? etag?.ToString() : null,
 2589                    null,
 2590                    cancellationToken)
 2591                    .ConfigureAwait(false);
 592            }
 1593            catch (Exception ex)
 594            {
 1595                scope.Failed(ex);
 1596                throw;
 597            }
 1598        }
 599
 600        /// <summary>
 601        /// Gets a specific <see cref="SearchIndex"/>.
 602        /// </summary>
 603        /// <param name="indexName">Required. The name of the index to get.</param>
 604        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 605        /// <returns>The <see cref="Response{T}"/> from the server containing the requested <see cref="SearchIndex"/>.</
 606        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 607        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 608        public virtual Response<SearchIndex> GetIndex(
 609            string indexName,
 610            CancellationToken cancellationToken = default)
 611        {
 2612            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndex)
 2613            scope.Start();
 614            try
 615            {
 2616                return IndexesClient.Get(
 2617                    indexName,
 2618                    cancellationToken);
 619            }
 1620            catch (Exception ex)
 621            {
 1622                scope.Failed(ex);
 1623                throw;
 624            }
 1625        }
 626
 627        /// <summary>
 628        /// Gets a specific <see cref="SearchIndex"/>.
 629        /// </summary>
 630        /// <param name="indexName">Required. The name of the index to get.</param>
 631        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 632        /// <returns>The <see cref="Response{T}"/> from the server containing the requested <see cref="SearchIndex"/>.</
 633        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 634        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 635        public virtual async Task<Response<SearchIndex>> GetIndexAsync(
 636            string indexName,
 637            CancellationToken cancellationToken = default)
 638        {
 2639            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndex)
 2640            scope.Start();
 641            try
 642            {
 2643                return await IndexesClient.GetAsync(
 2644                    indexName,
 2645                    cancellationToken)
 2646                    .ConfigureAwait(false);
 647            }
 1648            catch (Exception ex)
 649            {
 1650                scope.Failed(ex);
 1651                throw;
 652            }
 1653        }
 654
 655        /// <summary>
 656        /// Gets a list of all indexes.
 657        /// </summary>
 658        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 659        /// <returns>The <see cref="Pageable{T}"/> from the server containing a list of <see cref="SearchIndex"/>.</retu
 660        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 661        public virtual Pageable<SearchIndex> GetIndexes(
 662            CancellationToken cancellationToken = default)
 663        {
 1664            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexe
 1665            scope.Start();
 666            try
 667            {
 1668                return PageResponseEnumerator.CreateEnumerable((continuationToken) =>
 1669                {
 2670                    if (continuationToken != null)
 1671                    {
 0672                        throw new NotSupportedException("A continuation token is unsupported.");
 1673                    }
 1674
 2675                    Response<ListIndexesResult> result = IndexesClient.List(
 2676                        Constants.All,
 2677                        cancellationToken);
 1678
 2679                    return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse());
 1680                });
 681            }
 0682            catch (Exception ex)
 683            {
 0684                scope.Failed(ex);
 0685                throw;
 686            }
 1687        }
 688
 689        /// <summary>
 690        /// Gets a list of all indexes.
 691        /// </summary>
 692        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 693        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SearchIndex"/>.</retu
 694        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 695        public virtual AsyncPageable<SearchIndex> GetIndexesAsync(
 696            CancellationToken cancellationToken = default)
 697        {
 2698            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexe
 2699            scope.Start();
 700            try
 701            {
 2702                return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) =>
 2703                {
 4704                    if (continuationToken != null)
 2705                    {
 3706                        throw new NotSupportedException("A continuation token is unsupported.");
 2707                    }
 2708
 3709                    Response<ListIndexesResult> result = await IndexesClient.ListAsync(
 3710                        Constants.All,
 3711                        cancellationToken)
 3712                        .ConfigureAwait(false);
 2713
 3714                    return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse());
 3715                });
 716            }
 0717            catch (Exception ex)
 718            {
 0719                scope.Failed(ex);
 0720                throw;
 721            }
 2722        }
 723
 724        /// <summary>
 725        /// Gets a list of all index names.
 726        /// </summary>
 727        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 728        /// <returns>The <see cref="Pageable{T}"/> from the server containing a list of <see cref="SearchIndex"/> names.
 729        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 730        public virtual Pageable<string> GetIndexNames(
 731            CancellationToken cancellationToken = default)
 732        {
 0733            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexN
 0734            scope.Start();
 735            try
 736            {
 0737                return PageResponseEnumerator.CreateEnumerable((continuationToken) =>
 0738                {
 0739                    if (continuationToken != null)
 0740                    {
 0741                        throw new NotSupportedException("A continuation token is unsupported.");
 0742                    }
 0743
 0744                    Response<ListIndexesResult> result = IndexesClient.List(
 0745                        Constants.NameKey,
 0746                        cancellationToken);
 0747
 0748                    IReadOnlyList<string> names = result.Value.Indexes.Select(value => value.Name).ToArray();
 0749                    return Page<string>.FromValues(names, null, result.GetRawResponse());
 0750                });
 751            }
 0752            catch (Exception ex)
 753            {
 0754                scope.Failed(ex);
 0755                throw;
 756            }
 0757        }
 758
 759        /// <summary>
 760        /// Gets a list of all index names.
 761        /// </summary>
 762        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 763        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SearchIndex"/> names.
 764        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 765        public virtual AsyncPageable<string> GetIndexNamesAsync(
 766            CancellationToken cancellationToken = default)
 767        {
 0768            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexN
 0769            scope.Start();
 770            try
 771            {
 0772                return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) =>
 0773                {
 0774                    if (continuationToken != null)
 0775                    {
 0776                        throw new NotSupportedException("A continuation token is unsupported.");
 0777                    }
 0778
 0779                    Response<ListIndexesResult> result = await IndexesClient.ListAsync(
 0780                        Constants.NameKey,
 0781                        cancellationToken)
 0782                        .ConfigureAwait(false);
 0783
 0784                    IReadOnlyList<string> names = result.Value.Indexes.Select(value => value.Name).ToArray();
 0785                    return Page<string>.FromValues(names, null, result.GetRawResponse());
 0786                });
 787            }
 0788            catch (Exception ex)
 789            {
 0790                scope.Failed(ex);
 0791                throw;
 792            }
 0793        }
 794
 795        /// <summary>
 796        /// Gets <see cref="SearchIndexStatistics"/> for the given index, including a document count and storage usage.
 797        /// </summary>
 798        /// <param name="indexName">Required. The name of the index.</param>
 799        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 800        /// <returns>The <see cref="Response{T}"/> from the server containing <see cref="SearchIndexStatistics"/> names.
 801        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 802        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 803        public virtual Response<SearchIndexStatistics> GetIndexStatistics(
 804            string indexName,
 805            CancellationToken cancellationToken = default)
 806        {
 0807            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexS
 0808            scope.Start();
 809            try
 810            {
 0811                return IndexesClient.GetStatistics(
 0812                    indexName,
 0813                    cancellationToken);
 814            }
 0815            catch (Exception ex)
 816            {
 0817                scope.Failed(ex);
 0818                throw;
 819            }
 0820        }
 821
 822        /// <summary>
 823        /// Gets <see cref="SearchIndexStatistics"/> for the given index, including a document count and storage usage.
 824        /// </summary>
 825        /// <param name="indexName">Required. The name of the index.</param>
 826        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 827        /// <returns>The <see cref="Response{T}"/> from the server containing <see cref="SearchIndexStatistics"/>.</retu
 828        /// <exception cref="ArgumentNullException">Thrown when <paramref name="indexName"/> is null.</exception>
 829        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 830        public virtual async Task<Response<SearchIndexStatistics>> GetIndexStatisticsAsync(
 831            string indexName,
 832            CancellationToken cancellationToken = default)
 833        {
 0834            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexS
 0835            scope.Start();
 836            try
 837            {
 0838                return await IndexesClient.GetStatisticsAsync(
 0839                    indexName,
 0840                    cancellationToken)
 0841                    .ConfigureAwait(false);
 842            }
 0843            catch (Exception ex)
 844            {
 0845                scope.Failed(ex);
 0846                throw;
 847            }
 0848        }
 849        #endregion
 850
 851        #region SynonymMaps operations
 852        /// <summary>
 853        /// Creates a new synonym map.
 854        /// </summary>
 855        /// <param name="synonymMap">Required. The <see cref="SynonymMap"/> to create.</param>
 856        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 857        /// <returns>
 858        /// The <see cref="Response{T}"/> from the server containing the <see cref="SynonymMap"/> that was created.
 859        /// This may differ slightly from what was passed in since the service may return back properties set to their d
 860        /// </returns>
 861        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> is null.</exception>
 862        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 863        public virtual Response<SynonymMap> CreateSynonymMap(
 864            SynonymMap synonymMap,
 865            CancellationToken cancellationToken = default)
 866        {
 2867            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateSyn
 2868            scope.Start();
 869            try
 870            {
 2871                return SynonymMapsClient.Create(
 2872                    synonymMap,
 2873                    cancellationToken);
 874            }
 1875            catch (Exception ex)
 876            {
 1877                scope.Failed(ex);
 1878                throw;
 879            }
 1880        }
 881
 882        /// <summary>
 883        /// Creates a new synonym map.
 884        /// </summary>
 885        /// <param name="synonymMap">Required. The <see cref="SynonymMap"/> to create.</param>
 886        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 887        /// <returns>
 888        /// The <see cref="Response{T}"/> from the server containing the <see cref="SynonymMap"/> that was created.
 889        /// This may differ slightly from what was passed in since the service may return back properties set to their d
 890        /// </returns>
 891        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> is null.</exception>
 892        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 893        public virtual async Task<Response<SynonymMap>> CreateSynonymMapAsync(
 894            SynonymMap synonymMap,
 895            CancellationToken cancellationToken = default)
 896        {
 3897            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateSyn
 3898            scope.Start();
 899            try
 900            {
 3901                return await SynonymMapsClient.CreateAsync(
 3902                    synonymMap,
 3903                    cancellationToken)
 3904                    .ConfigureAwait(false);
 905            }
 1906            catch (Exception ex)
 907            {
 1908                scope.Failed(ex);
 1909                throw;
 910            }
 2911        }
 912
 913        /// <summary>
 914        /// Creates a new synonym map or updates an existing synonym map.
 915        /// </summary>
 916        /// <param name="synonymMap">Required. The <see cref="SynonymMap"/> to create or update.</param>
 917        /// <param name="onlyIfUnchanged">
 918        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SynonymMap.ETag"/> does not match the
 919        /// otherwise, the current service version will be overwritten.
 920        /// </param>
 921        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 922        /// <returns>
 923        /// The <see cref="Response{T}"/> from the server containing the <see cref="SynonymMap"/> that was created.
 924        /// This may differ slightly from what was passed in since the service may return back properties set to their d
 925        /// </returns>
 926        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> is null.</exception>
 927        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 928        public virtual Response<SynonymMap> CreateOrUpdateSynonymMap(
 929            SynonymMap synonymMap,
 930            bool onlyIfUnchanged = false,
 931            CancellationToken cancellationToken = default)
 932        {
 933            // Generated client validates indexName parameter first, which is not a parameter of this method.
 3934            Argument.AssertNotNull(synonymMap, nameof(synonymMap));
 935
 2936            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU
 2937            scope.Start();
 938            try
 939            {
 2940                return SynonymMapsClient.CreateOrUpdate(
 2941                    synonymMap?.Name,
 2942                    synonymMap,
 2943                    onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null,
 2944                    null,
 2945                    cancellationToken);
 946            }
 1947            catch (Exception ex)
 948            {
 1949                scope.Failed(ex);
 1950                throw;
 951            }
 1952        }
 953
 954        /// <summary>
 955        /// Creates a new synonym map or updates an existing synonym map.
 956        /// </summary>
 957        /// <param name="synonymMap">Required. The <see cref="SynonymMap"/> to create or update.</param>
 958        /// <param name="onlyIfUnchanged">
 959        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SynonymMap.ETag"/> does not match the
 960        /// otherwise, the current service version will be overwritten.
 961        /// </param>
 962        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 963        /// <returns>
 964        /// The <see cref="Response{T}"/> from the server containing the <see cref="SynonymMap"/> that was created.
 965        /// This may differ slightly from what was passed in since the service may return back properties set to their d
 966        /// </returns>
 967        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> is null.</exception>
 968        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 969        public virtual async Task<Response<SynonymMap>> CreateOrUpdateSynonymMapAsync(
 970            SynonymMap synonymMap,
 971            bool onlyIfUnchanged = false,
 972            CancellationToken cancellationToken = default)
 973        {
 974            // Generated client validates indexName parameter first, which is not a parameter of this method.
 3975            Argument.AssertNotNull(synonymMap, nameof(synonymMap));
 976
 2977            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU
 2978            scope.Start();
 979            try
 980            {
 2981                return await SynonymMapsClient.CreateOrUpdateAsync(
 2982                    synonymMap?.Name,
 2983                    synonymMap,
 2984                    onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null,
 2985                    null,
 2986                    cancellationToken)
 2987                    .ConfigureAwait(false);
 988            }
 1989            catch (Exception ex)
 990            {
 1991                scope.Failed(ex);
 1992                throw;
 993            }
 1994        }
 995
 996        /// <summary>
 997        /// Deletes a synonym map.
 998        /// </summary>
 999        /// <param name="synonymMapName">The name of a <see cref="SynonymMap"/> to delete.</param>
 1000        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1001        /// <returns>The <see cref="Response"/> from the server.</returns>
 1002        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMapName"/> or <see cref="SynonymM
 1003        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1004        public virtual Response DeleteSynonymMap(
 1005            string synonymMapName,
 11006            CancellationToken cancellationToken = default) => DeleteSynonymMap(
 11007                synonymMapName,
 11008                null,
 11009                false,
 11010                cancellationToken);
 1011
 1012        /// <summary>
 1013        /// Deletes a synonym map.
 1014        /// </summary>
 1015        /// <param name="synonymMapName">The name of a <see cref="SynonymMap"/> to delete.</param>
 1016        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1017        /// <returns>The <see cref="Response"/> from the server.</returns>
 1018        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMapName"/> or <see cref="SynonymM
 1019        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1020        public virtual async Task<Response> DeleteSynonymMapAsync(
 1021            string synonymMapName,
 21022            CancellationToken cancellationToken = default) => await DeleteSynonymMapAsync(
 21023                synonymMapName,
 21024                null,
 21025                false,
 21026                cancellationToken)
 21027                .ConfigureAwait(false);
 1028
 1029        /// <summary>
 1030        /// Deletes a synonym map.
 1031        /// </summary>
 1032        /// <param name="synonymMap">The <see cref="SynonymMap"/> to delete.</param>
 1033        /// <param name="onlyIfUnchanged">
 1034        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SynonymMap.ETag"/> does not match the
 1035        /// otherwise, the current service version will be overwritten.
 1036        /// </param>
 1037        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1038        /// <returns>The <see cref="Response"/> from the server.</returns>
 1039        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> or <see cref="SynonymMap.N
 1040        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1041        public virtual Response DeleteSynonymMap(
 1042            SynonymMap synonymMap,
 1043            bool onlyIfUnchanged = false,
 1044            CancellationToken cancellationToken = default)
 1045        {
 1046            // Generated client validates indexName parameter first, which is not a parameter of this method.
 21047            Argument.AssertNotNull(synonymMap, nameof(synonymMap));
 1048
 11049            return DeleteSynonymMap(
 11050                synonymMap?.Name,
 11051                synonymMap?.ETag,
 11052                onlyIfUnchanged,
 11053                cancellationToken);
 1054        }
 1055
 1056        /// <summary>
 1057        /// Deletes a synonym map.
 1058        /// </summary>
 1059        /// <param name="synonymMap">The <see cref="SynonymMap"/> to delete.</param>
 1060        /// <param name="onlyIfUnchanged">
 1061        /// True to throw a <see cref="RequestFailedException"/> if the <see cref="SynonymMap.ETag"/> does not match the
 1062        /// otherwise, the current service version will be overwritten.
 1063        /// </param>
 1064        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1065        /// <returns>The <see cref="Response"/> from the server.</returns>
 1066        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMap"/> or <see cref="SynonymMap.N
 1067        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1068        public virtual async Task<Response> DeleteSynonymMapAsync(
 1069            SynonymMap synonymMap,
 1070            bool onlyIfUnchanged = false,
 1071            CancellationToken cancellationToken = default)
 1072        {
 1073            // Generated client validates indexName parameter first, which is not a parameter of this method.
 21074            Argument.AssertNotNull(synonymMap, nameof(synonymMap));
 1075
 11076            return await DeleteSynonymMapAsync(
 11077                synonymMap?.Name,
 11078                synonymMap?.ETag,
 11079                onlyIfUnchanged,
 11080                cancellationToken)
 11081                .ConfigureAwait(false);
 11082        }
 1083
 1084        private Response DeleteSynonymMap(
 1085            string synonymMapName,
 1086            ETag? etag,
 1087            bool onlyIfUnchanged,
 1088            CancellationToken cancellationToken)
 1089        {
 21090            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSyn
 21091            scope.Start();
 1092            try
 1093            {
 21094                return SynonymMapsClient.Delete(
 21095                    synonymMapName,
 21096                    onlyIfUnchanged ? etag?.ToString() : null,
 21097                    null,
 21098                    cancellationToken);
 1099            }
 11100            catch (Exception ex)
 1101            {
 11102                scope.Failed(ex);
 11103                throw;
 1104            }
 11105        }
 1106
 1107        private async Task<Response> DeleteSynonymMapAsync(
 1108            string synonymMapName,
 1109            ETag? etag,
 1110            bool onlyIfUnchanged,
 1111            CancellationToken cancellationToken)
 1112        {
 31113            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSyn
 31114            scope.Start();
 1115            try
 1116            {
 31117                return await SynonymMapsClient.DeleteAsync(
 31118                    synonymMapName,
 31119                    onlyIfUnchanged ? etag?.ToString() : null,
 31120                    null,
 31121                    cancellationToken)
 31122                    .ConfigureAwait(false);
 1123            }
 11124            catch (Exception ex)
 1125            {
 11126                scope.Failed(ex);
 11127                throw;
 1128            }
 21129        }
 1130
 1131        /// <summary>
 1132        /// Gets a specific <see cref="SynonymMap"/>.
 1133        /// </summary>
 1134        /// <param name="synonymMapName">Required. The name of the <see cref="SynonymMap"/> to get.</param>
 1135        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1136        /// <returns>The <see cref="Response{T}"/> from the server containing the requested <see cref="SynonymMap"/>.</r
 1137        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMapName"/> is null.</exception>
 1138        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1139        public virtual Response<SynonymMap> GetSynonymMap(
 1140            string synonymMapName,
 1141            CancellationToken cancellationToken = default)
 1142        {
 21143            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 21144            scope.Start();
 1145            try
 1146            {
 21147                return SynonymMapsClient.Get(
 21148                    synonymMapName,
 21149                    cancellationToken);
 1150            }
 11151            catch (Exception ex)
 1152            {
 11153                scope.Failed(ex);
 11154                throw;
 1155            }
 11156        }
 1157
 1158        /// <summary>
 1159        /// Gets a specific <see cref="SynonymMap"/>.
 1160        /// </summary>
 1161        /// <param name="synonymMapName">Required. The name of the <see cref="SynonymMap"/> to get.</param>
 1162        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1163        /// <returns>The <see cref="Response{T}"/> from the server containing the requested <see cref="SynonymMap"/>.</r
 1164        /// <exception cref="ArgumentNullException">Thrown when <paramref name="synonymMapName"/> is null.</exception>
 1165        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1166        public virtual async Task<Response<SynonymMap>> GetSynonymMapAsync(
 1167            string synonymMapName,
 1168            CancellationToken cancellationToken = default)
 1169        {
 21170            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 21171            scope.Start();
 1172            try
 1173            {
 21174                return await SynonymMapsClient.GetAsync(
 21175                    synonymMapName,
 21176                    cancellationToken)
 21177                    .ConfigureAwait(false);
 1178            }
 11179            catch (Exception ex)
 1180            {
 11181                scope.Failed(ex);
 11182                throw;
 1183            }
 11184        }
 1185
 1186        /// <summary>
 1187        /// Gets a list of all synonym maps.
 1188        /// </summary>
 1189        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1190        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SynonymMap"/>.</retur
 1191        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1192        public virtual Response<IReadOnlyList<SynonymMap>> GetSynonymMaps(
 1193            CancellationToken cancellationToken = default)
 1194        {
 01195            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 01196            scope.Start();
 1197            try
 1198            {
 01199                Response<ListSynonymMapsResult> result = SynonymMapsClient.List(
 01200                    Constants.All,
 01201                    cancellationToken);
 1202
 01203                return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse());
 1204            }
 01205            catch (Exception ex)
 1206            {
 01207                scope.Failed(ex);
 01208                throw;
 1209            }
 01210        }
 1211
 1212        /// <summary>
 1213        /// Gets a list of all synonym maps.
 1214        /// </summary>
 1215        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1216        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SynonymMap"/>.</retur
 1217        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1218        public virtual async Task<Response<IReadOnlyList<SynonymMap>>> GetSynonymMapsAsync(
 1219            CancellationToken cancellationToken = default)
 1220        {
 01221            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 01222            scope.Start();
 1223            try
 1224            {
 01225                Response<ListSynonymMapsResult> result = await SynonymMapsClient.ListAsync(
 01226                    Constants.All,
 01227                    cancellationToken)
 01228                    .ConfigureAwait(false);
 1229
 01230                return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse());
 1231            }
 01232            catch (Exception ex)
 1233            {
 01234                scope.Failed(ex);
 01235                throw;
 1236            }
 01237        }
 1238
 1239        /// <summary>
 1240        /// Gets a list of all synonym map names.
 1241        /// </summary>
 1242        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1243        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SynonymMap"/> names.<
 1244        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1245        public virtual Response<IReadOnlyList<string>> GetSynonymMapNames(
 1246            CancellationToken cancellationToken = default)
 1247        {
 11248            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 11249            scope.Start();
 1250            try
 1251            {
 11252                Response<ListSynonymMapsResult> result = SynonymMapsClient.List(
 11253                    Constants.NameKey,
 11254                    cancellationToken);
 1255
 21256                IReadOnlyList<string> names = result.Value.SynonymMaps.Select(value => value.Name).ToArray();
 11257                return Response.FromValue(names, result.GetRawResponse());
 1258            }
 01259            catch (Exception ex)
 1260            {
 01261                scope.Failed(ex);
 01262                throw;
 1263            }
 11264        }
 1265
 1266        /// <summary>
 1267        /// Gets a list of all synonym map names.
 1268        /// </summary>
 1269        /// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the
 1270        /// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SynonymMap"/> names.<
 1271        /// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception
 1272        public virtual async Task<Response<IReadOnlyList<string>>> GetSynonymMapNamesAsync(
 1273            CancellationToken cancellationToken = default)
 1274        {
 11275            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony
 11276            scope.Start();
 1277            try
 1278            {
 11279                Response<ListSynonymMapsResult> result = await SynonymMapsClient.ListAsync(
 11280                    Constants.NameKey,
 11281                    cancellationToken)
 11282                    .ConfigureAwait(false);
 1283
 21284                IReadOnlyList<string> names = result.Value.SynonymMaps.Select(value => value.Name).ToArray();
 11285                return Response.FromValue(names, result.GetRawResponse());
 1286            }
 01287            catch (Exception ex)
 1288            {
 01289                scope.Failed(ex);
 01290                throw;
 1291            }
 11292        }
 1293        #endregion
 1294    }
 1295}