| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using Azure.Core; |
| | | 10 | | using Azure.Core.Pipeline; |
| | | 11 | | #if EXPERIMENTAL_SERIALIZER |
| | | 12 | | using Azure.Core.Serialization; |
| | | 13 | | #endif |
| | | 14 | | using Azure.Search.Documents.Indexes.Models; |
| | | 15 | | |
| | | 16 | | namespace 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> |
| | 198 | 38 | | 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) : |
| | 24 | 52 | | this(endpoint, credential, null) |
| | | 53 | | { |
| | 18 | 54 | | } |
| | | 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 |
| | 124 | 68 | | public SearchIndexClient( |
| | 124 | 69 | | Uri endpoint, |
| | 124 | 70 | | AzureKeyCredential credential, |
| | 124 | 71 | | SearchClientOptions options) |
| | | 72 | | { |
| | 124 | 73 | | Argument.AssertNotNull(endpoint, nameof(endpoint)); |
| | 122 | 74 | | endpoint.AssertHttpsScheme(nameof(endpoint)); |
| | 120 | 75 | | Argument.AssertNotNull(credential, nameof(credential)); |
| | | 76 | | |
| | 118 | 77 | | options ??= new SearchClientOptions(); |
| | 118 | 78 | | Endpoint = endpoint; |
| | | 79 | | #if EXPERIMENTAL_SERIALIZER |
| | 118 | 80 | | _serializer = options.Serializer; |
| | | 81 | | #endif |
| | 118 | 82 | | _clientDiagnostics = new ClientDiagnostics(options); |
| | 118 | 83 | | _pipeline = options.Build(credential); |
| | 118 | 84 | | _version = options.Version; |
| | 118 | 85 | | } |
| | | 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> |
| | 113 | 91 | | public virtual Uri Endpoint { get; } |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Gets the name of the Search service. |
| | | 95 | | /// </summary> |
| | | 96 | | public virtual string ServiceName => |
| | 2 | 97 | | _serviceName ??= Endpoint.GetSearchServiceName(); |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Gets the generated <see cref="ServiceRestClient"/> to make requests. |
| | | 101 | | /// </summary> |
| | 12 | 102 | | private ServiceRestClient ServiceClient => LazyInitializer.EnsureInitialized(ref _serviceClient, () => new Servi |
| | 12 | 103 | | _clientDiagnostics, |
| | 12 | 104 | | _pipeline, |
| | 12 | 105 | | Endpoint.ToString(), |
| | 12 | 106 | | null, |
| | 12 | 107 | | _version.ToVersionString()) |
| | 6 | 108 | | ); |
| | | 109 | | |
| | | 110 | | /// <summary> |
| | | 111 | | /// Gets the generated <see cref="IndexesRestClient"/> to make requests. |
| | | 112 | | /// </summary> |
| | 40 | 113 | | private IndexesRestClient IndexesClient => LazyInitializer.EnsureInitialized(ref _indexesClient, () => new Index |
| | 40 | 114 | | _clientDiagnostics, |
| | 40 | 115 | | _pipeline, |
| | 40 | 116 | | Endpoint.ToString(), |
| | 40 | 117 | | null, |
| | 40 | 118 | | _version.ToVersionString()) |
| | 23 | 119 | | ); |
| | | 120 | | |
| | | 121 | | /// <summary> |
| | | 122 | | /// Gets the generated <see cref="SynonymMapsRestClient"/> to make requests. |
| | | 123 | | /// </summary> |
| | 26 | 124 | | private SynonymMapsRestClient SynonymMapsClient => LazyInitializer.EnsureInitialized(ref _synonymMapsClient, () |
| | 26 | 125 | | _clientDiagnostics, |
| | 26 | 126 | | _pipeline, |
| | 26 | 127 | | Endpoint.ToString(), |
| | 26 | 128 | | null, |
| | 26 | 129 | | _version.ToVersionString()) |
| | 20 | 130 | | ); |
| | | 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 | | { |
| | 84 | 145 | | Argument.AssertNotNullOrEmpty(indexName, nameof(indexName)); |
| | 80 | 146 | | return new SearchClient( |
| | 80 | 147 | | Endpoint, |
| | 80 | 148 | | indexName, |
| | 80 | 149 | | #if EXPERIMENTAL_SERIALIZER |
| | 80 | 150 | | _serializer, |
| | 80 | 151 | | #endif |
| | 80 | 152 | | _pipeline, |
| | 80 | 153 | | _clientDiagnostics, |
| | 80 | 154 | | _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 | | { |
| | 3 | 183 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServic |
| | 3 | 184 | | scope.Start(); |
| | | 185 | | try |
| | | 186 | | { |
| | 3 | 187 | | return ServiceClient.GetServiceStatistics( |
| | 3 | 188 | | cancellationToken); |
| | | 189 | | } |
| | 0 | 190 | | catch (Exception ex) |
| | | 191 | | { |
| | 0 | 192 | | scope.Failed(ex); |
| | 0 | 193 | | throw; |
| | | 194 | | } |
| | 3 | 195 | | } |
| | | 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 | | { |
| | 3 | 221 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServic |
| | 3 | 222 | | scope.Start(); |
| | | 223 | | try |
| | | 224 | | { |
| | 3 | 225 | | return await ServiceClient.GetServiceStatisticsAsync( |
| | 3 | 226 | | cancellationToken) |
| | 3 | 227 | | .ConfigureAwait(false); |
| | | 228 | | } |
| | 0 | 229 | | catch (Exception ex) |
| | | 230 | | { |
| | 0 | 231 | | scope.Failed(ex); |
| | 0 | 232 | | throw; |
| | | 233 | | } |
| | 3 | 234 | | } |
| | | 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 | | { |
| | 1 | 254 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeTe |
| | 1 | 255 | | scope.Start(); |
| | | 256 | | try |
| | | 257 | | { |
| | 1 | 258 | | Response<AnalyzeResult> result = IndexesClient.Analyze( |
| | 1 | 259 | | indexName, |
| | 1 | 260 | | options, |
| | 1 | 261 | | cancellationToken); |
| | | 262 | | |
| | 1 | 263 | | return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); |
| | | 264 | | } |
| | 0 | 265 | | catch (Exception ex) |
| | | 266 | | { |
| | 0 | 267 | | scope.Failed(ex); |
| | 0 | 268 | | throw; |
| | | 269 | | } |
| | 1 | 270 | | } |
| | | 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 | | { |
| | 1 | 288 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(AnalyzeTe |
| | 1 | 289 | | scope.Start(); |
| | | 290 | | try |
| | | 291 | | { |
| | 1 | 292 | | Response<AnalyzeResult> result = await IndexesClient.AnalyzeAsync( |
| | 1 | 293 | | indexName, |
| | 1 | 294 | | options, |
| | 1 | 295 | | cancellationToken) |
| | 1 | 296 | | .ConfigureAwait(false); |
| | | 297 | | |
| | 1 | 298 | | return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); |
| | | 299 | | } |
| | 0 | 300 | | catch (Exception ex) |
| | | 301 | | { |
| | 0 | 302 | | scope.Failed(ex); |
| | 0 | 303 | | throw; |
| | | 304 | | } |
| | 1 | 305 | | } |
| | | 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 | | { |
| | 6 | 322 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateInd |
| | 6 | 323 | | scope.Start(); |
| | | 324 | | try |
| | | 325 | | { |
| | 6 | 326 | | return IndexesClient.Create( |
| | 6 | 327 | | index, |
| | 6 | 328 | | cancellationToken); |
| | | 329 | | } |
| | 1 | 330 | | catch (Exception ex) |
| | | 331 | | { |
| | 1 | 332 | | scope.Failed(ex); |
| | 1 | 333 | | throw; |
| | | 334 | | } |
| | 5 | 335 | | } |
| | | 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 | | { |
| | 4 | 352 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateInd |
| | 4 | 353 | | scope.Start(); |
| | | 354 | | try |
| | | 355 | | { |
| | 4 | 356 | | return await IndexesClient.CreateAsync( |
| | 4 | 357 | | index, |
| | 4 | 358 | | cancellationToken) |
| | 4 | 359 | | .ConfigureAwait(false); |
| | | 360 | | } |
| | 1 | 361 | | catch (Exception ex) |
| | | 362 | | { |
| | 1 | 363 | | scope.Failed(ex); |
| | 1 | 364 | | throw; |
| | | 365 | | } |
| | 3 | 366 | | } |
| | | 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. |
| | 2 | 395 | | Argument.AssertNotNull(index, nameof(index)); |
| | | 396 | | |
| | 1 | 397 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU |
| | 1 | 398 | | scope.Start(); |
| | | 399 | | try |
| | | 400 | | { |
| | 1 | 401 | | return IndexesClient.CreateOrUpdate( |
| | 1 | 402 | | index?.Name, |
| | 1 | 403 | | index, |
| | 1 | 404 | | allowIndexDowntime, |
| | 1 | 405 | | onlyIfUnchanged ? index?.ETag?.ToString() : null, |
| | 1 | 406 | | null, |
| | 1 | 407 | | cancellationToken); |
| | | 408 | | } |
| | 0 | 409 | | catch (Exception ex) |
| | | 410 | | { |
| | 0 | 411 | | scope.Failed(ex); |
| | 0 | 412 | | throw; |
| | | 413 | | } |
| | 1 | 414 | | } |
| | | 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. |
| | 2 | 443 | | Argument.AssertNotNull(index, nameof(index)); |
| | | 444 | | |
| | 1 | 445 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU |
| | 1 | 446 | | scope.Start(); |
| | | 447 | | try |
| | | 448 | | { |
| | 1 | 449 | | return await IndexesClient.CreateOrUpdateAsync( |
| | 1 | 450 | | index?.Name, |
| | 1 | 451 | | index, |
| | 1 | 452 | | allowIndexDowntime, |
| | 1 | 453 | | onlyIfUnchanged ? index?.ETag?.ToString() : null, |
| | 1 | 454 | | null, |
| | 1 | 455 | | cancellationToken) |
| | 1 | 456 | | .ConfigureAwait(false); |
| | | 457 | | } |
| | 0 | 458 | | catch (Exception ex) |
| | | 459 | | { |
| | 0 | 460 | | scope.Failed(ex); |
| | 0 | 461 | | throw; |
| | | 462 | | } |
| | 1 | 463 | | } |
| | | 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, |
| | 1 | 475 | | CancellationToken cancellationToken = default) => DeleteIndex( |
| | 1 | 476 | | indexName, |
| | 1 | 477 | | null, |
| | 1 | 478 | | false, |
| | 1 | 479 | | 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, |
| | 2 | 491 | | CancellationToken cancellationToken = default) => await DeleteIndexAsync( |
| | 2 | 492 | | indexName, |
| | 2 | 493 | | null, |
| | 2 | 494 | | false, |
| | 2 | 495 | | cancellationToken) |
| | 2 | 496 | | .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. |
| | 1 | 516 | | Argument.AssertNotNull(index, nameof(index)); |
| | | 517 | | |
| | 0 | 518 | | return DeleteIndex( |
| | 0 | 519 | | index?.Name, |
| | 0 | 520 | | index?.ETag, |
| | 0 | 521 | | onlyIfUnchanged, |
| | 0 | 522 | | 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. |
| | 1 | 543 | | Argument.AssertNotNull(index, nameof(index)); |
| | | 544 | | |
| | 0 | 545 | | return await DeleteIndexAsync( |
| | 0 | 546 | | index?.Name, |
| | 0 | 547 | | index?.ETag, |
| | 0 | 548 | | onlyIfUnchanged, |
| | 0 | 549 | | cancellationToken) |
| | 0 | 550 | | .ConfigureAwait(false); |
| | 0 | 551 | | } |
| | | 552 | | |
| | | 553 | | private Response DeleteIndex( |
| | | 554 | | string indexName, |
| | | 555 | | ETag? etag, |
| | | 556 | | bool onlyIfUnchanged, |
| | | 557 | | CancellationToken cancellationToken) |
| | | 558 | | { |
| | 1 | 559 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteInd |
| | 1 | 560 | | scope.Start(); |
| | | 561 | | try |
| | | 562 | | { |
| | 1 | 563 | | return IndexesClient.Delete( |
| | 1 | 564 | | indexName, |
| | 1 | 565 | | onlyIfUnchanged ? etag?.ToString() : null, |
| | 1 | 566 | | null, |
| | 1 | 567 | | cancellationToken); |
| | | 568 | | } |
| | 1 | 569 | | catch (Exception ex) |
| | | 570 | | { |
| | 1 | 571 | | scope.Failed(ex); |
| | 1 | 572 | | throw; |
| | | 573 | | } |
| | 0 | 574 | | } |
| | | 575 | | |
| | | 576 | | private async Task<Response> DeleteIndexAsync( |
| | | 577 | | string indexName, |
| | | 578 | | ETag? etag, |
| | | 579 | | bool onlyIfUnchanged, |
| | | 580 | | CancellationToken cancellationToken) |
| | | 581 | | { |
| | 2 | 582 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteInd |
| | 2 | 583 | | scope.Start(); |
| | | 584 | | try |
| | | 585 | | { |
| | 2 | 586 | | return await IndexesClient.DeleteAsync( |
| | 2 | 587 | | indexName, |
| | 2 | 588 | | onlyIfUnchanged ? etag?.ToString() : null, |
| | 2 | 589 | | null, |
| | 2 | 590 | | cancellationToken) |
| | 2 | 591 | | .ConfigureAwait(false); |
| | | 592 | | } |
| | 1 | 593 | | catch (Exception ex) |
| | | 594 | | { |
| | 1 | 595 | | scope.Failed(ex); |
| | 1 | 596 | | throw; |
| | | 597 | | } |
| | 1 | 598 | | } |
| | | 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 | | { |
| | 2 | 612 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndex) |
| | 2 | 613 | | scope.Start(); |
| | | 614 | | try |
| | | 615 | | { |
| | 2 | 616 | | return IndexesClient.Get( |
| | 2 | 617 | | indexName, |
| | 2 | 618 | | cancellationToken); |
| | | 619 | | } |
| | 1 | 620 | | catch (Exception ex) |
| | | 621 | | { |
| | 1 | 622 | | scope.Failed(ex); |
| | 1 | 623 | | throw; |
| | | 624 | | } |
| | 1 | 625 | | } |
| | | 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 | | { |
| | 2 | 639 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndex) |
| | 2 | 640 | | scope.Start(); |
| | | 641 | | try |
| | | 642 | | { |
| | 2 | 643 | | return await IndexesClient.GetAsync( |
| | 2 | 644 | | indexName, |
| | 2 | 645 | | cancellationToken) |
| | 2 | 646 | | .ConfigureAwait(false); |
| | | 647 | | } |
| | 1 | 648 | | catch (Exception ex) |
| | | 649 | | { |
| | 1 | 650 | | scope.Failed(ex); |
| | 1 | 651 | | throw; |
| | | 652 | | } |
| | 1 | 653 | | } |
| | | 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 | | { |
| | 1 | 664 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexe |
| | 1 | 665 | | scope.Start(); |
| | | 666 | | try |
| | | 667 | | { |
| | 1 | 668 | | return PageResponseEnumerator.CreateEnumerable((continuationToken) => |
| | 1 | 669 | | { |
| | 2 | 670 | | if (continuationToken != null) |
| | 1 | 671 | | { |
| | 0 | 672 | | throw new NotSupportedException("A continuation token is unsupported."); |
| | 1 | 673 | | } |
| | 1 | 674 | | |
| | 2 | 675 | | Response<ListIndexesResult> result = IndexesClient.List( |
| | 2 | 676 | | Constants.All, |
| | 2 | 677 | | cancellationToken); |
| | 1 | 678 | | |
| | 2 | 679 | | return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse()); |
| | 1 | 680 | | }); |
| | | 681 | | } |
| | 0 | 682 | | catch (Exception ex) |
| | | 683 | | { |
| | 0 | 684 | | scope.Failed(ex); |
| | 0 | 685 | | throw; |
| | | 686 | | } |
| | 1 | 687 | | } |
| | | 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 | | { |
| | 2 | 698 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexe |
| | 2 | 699 | | scope.Start(); |
| | | 700 | | try |
| | | 701 | | { |
| | 2 | 702 | | return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => |
| | 2 | 703 | | { |
| | 4 | 704 | | if (continuationToken != null) |
| | 2 | 705 | | { |
| | 3 | 706 | | throw new NotSupportedException("A continuation token is unsupported."); |
| | 2 | 707 | | } |
| | 2 | 708 | | |
| | 3 | 709 | | Response<ListIndexesResult> result = await IndexesClient.ListAsync( |
| | 3 | 710 | | Constants.All, |
| | 3 | 711 | | cancellationToken) |
| | 3 | 712 | | .ConfigureAwait(false); |
| | 2 | 713 | | |
| | 3 | 714 | | return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse()); |
| | 3 | 715 | | }); |
| | | 716 | | } |
| | 0 | 717 | | catch (Exception ex) |
| | | 718 | | { |
| | 0 | 719 | | scope.Failed(ex); |
| | 0 | 720 | | throw; |
| | | 721 | | } |
| | 2 | 722 | | } |
| | | 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 | | { |
| | 0 | 733 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexN |
| | 0 | 734 | | scope.Start(); |
| | | 735 | | try |
| | | 736 | | { |
| | 0 | 737 | | return PageResponseEnumerator.CreateEnumerable((continuationToken) => |
| | 0 | 738 | | { |
| | 0 | 739 | | if (continuationToken != null) |
| | 0 | 740 | | { |
| | 0 | 741 | | throw new NotSupportedException("A continuation token is unsupported."); |
| | 0 | 742 | | } |
| | 0 | 743 | | |
| | 0 | 744 | | Response<ListIndexesResult> result = IndexesClient.List( |
| | 0 | 745 | | Constants.NameKey, |
| | 0 | 746 | | cancellationToken); |
| | 0 | 747 | | |
| | 0 | 748 | | IReadOnlyList<string> names = result.Value.Indexes.Select(value => value.Name).ToArray(); |
| | 0 | 749 | | return Page<string>.FromValues(names, null, result.GetRawResponse()); |
| | 0 | 750 | | }); |
| | | 751 | | } |
| | 0 | 752 | | catch (Exception ex) |
| | | 753 | | { |
| | 0 | 754 | | scope.Failed(ex); |
| | 0 | 755 | | throw; |
| | | 756 | | } |
| | 0 | 757 | | } |
| | | 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 | | { |
| | 0 | 768 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexN |
| | 0 | 769 | | scope.Start(); |
| | | 770 | | try |
| | | 771 | | { |
| | 0 | 772 | | return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => |
| | 0 | 773 | | { |
| | 0 | 774 | | if (continuationToken != null) |
| | 0 | 775 | | { |
| | 0 | 776 | | throw new NotSupportedException("A continuation token is unsupported."); |
| | 0 | 777 | | } |
| | 0 | 778 | | |
| | 0 | 779 | | Response<ListIndexesResult> result = await IndexesClient.ListAsync( |
| | 0 | 780 | | Constants.NameKey, |
| | 0 | 781 | | cancellationToken) |
| | 0 | 782 | | .ConfigureAwait(false); |
| | 0 | 783 | | |
| | 0 | 784 | | IReadOnlyList<string> names = result.Value.Indexes.Select(value => value.Name).ToArray(); |
| | 0 | 785 | | return Page<string>.FromValues(names, null, result.GetRawResponse()); |
| | 0 | 786 | | }); |
| | | 787 | | } |
| | 0 | 788 | | catch (Exception ex) |
| | | 789 | | { |
| | 0 | 790 | | scope.Failed(ex); |
| | 0 | 791 | | throw; |
| | | 792 | | } |
| | 0 | 793 | | } |
| | | 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 | | { |
| | 0 | 807 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexS |
| | 0 | 808 | | scope.Start(); |
| | | 809 | | try |
| | | 810 | | { |
| | 0 | 811 | | return IndexesClient.GetStatistics( |
| | 0 | 812 | | indexName, |
| | 0 | 813 | | cancellationToken); |
| | | 814 | | } |
| | 0 | 815 | | catch (Exception ex) |
| | | 816 | | { |
| | 0 | 817 | | scope.Failed(ex); |
| | 0 | 818 | | throw; |
| | | 819 | | } |
| | 0 | 820 | | } |
| | | 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 | | { |
| | 0 | 834 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetIndexS |
| | 0 | 835 | | scope.Start(); |
| | | 836 | | try |
| | | 837 | | { |
| | 0 | 838 | | return await IndexesClient.GetStatisticsAsync( |
| | 0 | 839 | | indexName, |
| | 0 | 840 | | cancellationToken) |
| | 0 | 841 | | .ConfigureAwait(false); |
| | | 842 | | } |
| | 0 | 843 | | catch (Exception ex) |
| | | 844 | | { |
| | 0 | 845 | | scope.Failed(ex); |
| | 0 | 846 | | throw; |
| | | 847 | | } |
| | 0 | 848 | | } |
| | | 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 | | { |
| | 2 | 867 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateSyn |
| | 2 | 868 | | scope.Start(); |
| | | 869 | | try |
| | | 870 | | { |
| | 2 | 871 | | return SynonymMapsClient.Create( |
| | 2 | 872 | | synonymMap, |
| | 2 | 873 | | cancellationToken); |
| | | 874 | | } |
| | 1 | 875 | | catch (Exception ex) |
| | | 876 | | { |
| | 1 | 877 | | scope.Failed(ex); |
| | 1 | 878 | | throw; |
| | | 879 | | } |
| | 1 | 880 | | } |
| | | 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 | | { |
| | 3 | 897 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateSyn |
| | 3 | 898 | | scope.Start(); |
| | | 899 | | try |
| | | 900 | | { |
| | 3 | 901 | | return await SynonymMapsClient.CreateAsync( |
| | 3 | 902 | | synonymMap, |
| | 3 | 903 | | cancellationToken) |
| | 3 | 904 | | .ConfigureAwait(false); |
| | | 905 | | } |
| | 1 | 906 | | catch (Exception ex) |
| | | 907 | | { |
| | 1 | 908 | | scope.Failed(ex); |
| | 1 | 909 | | throw; |
| | | 910 | | } |
| | 2 | 911 | | } |
| | | 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. |
| | 3 | 934 | | Argument.AssertNotNull(synonymMap, nameof(synonymMap)); |
| | | 935 | | |
| | 2 | 936 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU |
| | 2 | 937 | | scope.Start(); |
| | | 938 | | try |
| | | 939 | | { |
| | 2 | 940 | | return SynonymMapsClient.CreateOrUpdate( |
| | 2 | 941 | | synonymMap?.Name, |
| | 2 | 942 | | synonymMap, |
| | 2 | 943 | | onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, |
| | 2 | 944 | | null, |
| | 2 | 945 | | cancellationToken); |
| | | 946 | | } |
| | 1 | 947 | | catch (Exception ex) |
| | | 948 | | { |
| | 1 | 949 | | scope.Failed(ex); |
| | 1 | 950 | | throw; |
| | | 951 | | } |
| | 1 | 952 | | } |
| | | 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. |
| | 3 | 975 | | Argument.AssertNotNull(synonymMap, nameof(synonymMap)); |
| | | 976 | | |
| | 2 | 977 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(CreateOrU |
| | 2 | 978 | | scope.Start(); |
| | | 979 | | try |
| | | 980 | | { |
| | 2 | 981 | | return await SynonymMapsClient.CreateOrUpdateAsync( |
| | 2 | 982 | | synonymMap?.Name, |
| | 2 | 983 | | synonymMap, |
| | 2 | 984 | | onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, |
| | 2 | 985 | | null, |
| | 2 | 986 | | cancellationToken) |
| | 2 | 987 | | .ConfigureAwait(false); |
| | | 988 | | } |
| | 1 | 989 | | catch (Exception ex) |
| | | 990 | | { |
| | 1 | 991 | | scope.Failed(ex); |
| | 1 | 992 | | throw; |
| | | 993 | | } |
| | 1 | 994 | | } |
| | | 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, |
| | 1 | 1006 | | CancellationToken cancellationToken = default) => DeleteSynonymMap( |
| | 1 | 1007 | | synonymMapName, |
| | 1 | 1008 | | null, |
| | 1 | 1009 | | false, |
| | 1 | 1010 | | 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, |
| | 2 | 1022 | | CancellationToken cancellationToken = default) => await DeleteSynonymMapAsync( |
| | 2 | 1023 | | synonymMapName, |
| | 2 | 1024 | | null, |
| | 2 | 1025 | | false, |
| | 2 | 1026 | | cancellationToken) |
| | 2 | 1027 | | .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. |
| | 2 | 1047 | | Argument.AssertNotNull(synonymMap, nameof(synonymMap)); |
| | | 1048 | | |
| | 1 | 1049 | | return DeleteSynonymMap( |
| | 1 | 1050 | | synonymMap?.Name, |
| | 1 | 1051 | | synonymMap?.ETag, |
| | 1 | 1052 | | onlyIfUnchanged, |
| | 1 | 1053 | | 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. |
| | 2 | 1074 | | Argument.AssertNotNull(synonymMap, nameof(synonymMap)); |
| | | 1075 | | |
| | 1 | 1076 | | return await DeleteSynonymMapAsync( |
| | 1 | 1077 | | synonymMap?.Name, |
| | 1 | 1078 | | synonymMap?.ETag, |
| | 1 | 1079 | | onlyIfUnchanged, |
| | 1 | 1080 | | cancellationToken) |
| | 1 | 1081 | | .ConfigureAwait(false); |
| | 1 | 1082 | | } |
| | | 1083 | | |
| | | 1084 | | private Response DeleteSynonymMap( |
| | | 1085 | | string synonymMapName, |
| | | 1086 | | ETag? etag, |
| | | 1087 | | bool onlyIfUnchanged, |
| | | 1088 | | CancellationToken cancellationToken) |
| | | 1089 | | { |
| | 2 | 1090 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSyn |
| | 2 | 1091 | | scope.Start(); |
| | | 1092 | | try |
| | | 1093 | | { |
| | 2 | 1094 | | return SynonymMapsClient.Delete( |
| | 2 | 1095 | | synonymMapName, |
| | 2 | 1096 | | onlyIfUnchanged ? etag?.ToString() : null, |
| | 2 | 1097 | | null, |
| | 2 | 1098 | | cancellationToken); |
| | | 1099 | | } |
| | 1 | 1100 | | catch (Exception ex) |
| | | 1101 | | { |
| | 1 | 1102 | | scope.Failed(ex); |
| | 1 | 1103 | | throw; |
| | | 1104 | | } |
| | 1 | 1105 | | } |
| | | 1106 | | |
| | | 1107 | | private async Task<Response> DeleteSynonymMapAsync( |
| | | 1108 | | string synonymMapName, |
| | | 1109 | | ETag? etag, |
| | | 1110 | | bool onlyIfUnchanged, |
| | | 1111 | | CancellationToken cancellationToken) |
| | | 1112 | | { |
| | 3 | 1113 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSyn |
| | 3 | 1114 | | scope.Start(); |
| | | 1115 | | try |
| | | 1116 | | { |
| | 3 | 1117 | | return await SynonymMapsClient.DeleteAsync( |
| | 3 | 1118 | | synonymMapName, |
| | 3 | 1119 | | onlyIfUnchanged ? etag?.ToString() : null, |
| | 3 | 1120 | | null, |
| | 3 | 1121 | | cancellationToken) |
| | 3 | 1122 | | .ConfigureAwait(false); |
| | | 1123 | | } |
| | 1 | 1124 | | catch (Exception ex) |
| | | 1125 | | { |
| | 1 | 1126 | | scope.Failed(ex); |
| | 1 | 1127 | | throw; |
| | | 1128 | | } |
| | 2 | 1129 | | } |
| | | 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 | | { |
| | 2 | 1143 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 2 | 1144 | | scope.Start(); |
| | | 1145 | | try |
| | | 1146 | | { |
| | 2 | 1147 | | return SynonymMapsClient.Get( |
| | 2 | 1148 | | synonymMapName, |
| | 2 | 1149 | | cancellationToken); |
| | | 1150 | | } |
| | 1 | 1151 | | catch (Exception ex) |
| | | 1152 | | { |
| | 1 | 1153 | | scope.Failed(ex); |
| | 1 | 1154 | | throw; |
| | | 1155 | | } |
| | 1 | 1156 | | } |
| | | 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 | | { |
| | 2 | 1170 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 2 | 1171 | | scope.Start(); |
| | | 1172 | | try |
| | | 1173 | | { |
| | 2 | 1174 | | return await SynonymMapsClient.GetAsync( |
| | 2 | 1175 | | synonymMapName, |
| | 2 | 1176 | | cancellationToken) |
| | 2 | 1177 | | .ConfigureAwait(false); |
| | | 1178 | | } |
| | 1 | 1179 | | catch (Exception ex) |
| | | 1180 | | { |
| | 1 | 1181 | | scope.Failed(ex); |
| | 1 | 1182 | | throw; |
| | | 1183 | | } |
| | 1 | 1184 | | } |
| | | 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 | | { |
| | 0 | 1195 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 0 | 1196 | | scope.Start(); |
| | | 1197 | | try |
| | | 1198 | | { |
| | 0 | 1199 | | Response<ListSynonymMapsResult> result = SynonymMapsClient.List( |
| | 0 | 1200 | | Constants.All, |
| | 0 | 1201 | | cancellationToken); |
| | | 1202 | | |
| | 0 | 1203 | | return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); |
| | | 1204 | | } |
| | 0 | 1205 | | catch (Exception ex) |
| | | 1206 | | { |
| | 0 | 1207 | | scope.Failed(ex); |
| | 0 | 1208 | | throw; |
| | | 1209 | | } |
| | 0 | 1210 | | } |
| | | 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 | | { |
| | 0 | 1221 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 0 | 1222 | | scope.Start(); |
| | | 1223 | | try |
| | | 1224 | | { |
| | 0 | 1225 | | Response<ListSynonymMapsResult> result = await SynonymMapsClient.ListAsync( |
| | 0 | 1226 | | Constants.All, |
| | 0 | 1227 | | cancellationToken) |
| | 0 | 1228 | | .ConfigureAwait(false); |
| | | 1229 | | |
| | 0 | 1230 | | return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); |
| | | 1231 | | } |
| | 0 | 1232 | | catch (Exception ex) |
| | | 1233 | | { |
| | 0 | 1234 | | scope.Failed(ex); |
| | 0 | 1235 | | throw; |
| | | 1236 | | } |
| | 0 | 1237 | | } |
| | | 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 | | { |
| | 1 | 1248 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 1 | 1249 | | scope.Start(); |
| | | 1250 | | try |
| | | 1251 | | { |
| | 1 | 1252 | | Response<ListSynonymMapsResult> result = SynonymMapsClient.List( |
| | 1 | 1253 | | Constants.NameKey, |
| | 1 | 1254 | | cancellationToken); |
| | | 1255 | | |
| | 2 | 1256 | | IReadOnlyList<string> names = result.Value.SynonymMaps.Select(value => value.Name).ToArray(); |
| | 1 | 1257 | | return Response.FromValue(names, result.GetRawResponse()); |
| | | 1258 | | } |
| | 0 | 1259 | | catch (Exception ex) |
| | | 1260 | | { |
| | 0 | 1261 | | scope.Failed(ex); |
| | 0 | 1262 | | throw; |
| | | 1263 | | } |
| | 1 | 1264 | | } |
| | | 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 | | { |
| | 1 | 1275 | | using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetSynony |
| | 1 | 1276 | | scope.Start(); |
| | | 1277 | | try |
| | | 1278 | | { |
| | 1 | 1279 | | Response<ListSynonymMapsResult> result = await SynonymMapsClient.ListAsync( |
| | 1 | 1280 | | Constants.NameKey, |
| | 1 | 1281 | | cancellationToken) |
| | 1 | 1282 | | .ConfigureAwait(false); |
| | | 1283 | | |
| | 2 | 1284 | | IReadOnlyList<string> names = result.Value.SynonymMaps.Select(value => value.Name).ToArray(); |
| | 1 | 1285 | | return Response.FromValue(names, result.GetRawResponse()); |
| | | 1286 | | } |
| | 0 | 1287 | | catch (Exception ex) |
| | | 1288 | | { |
| | 0 | 1289 | | scope.Failed(ex); |
| | 0 | 1290 | | throw; |
| | | 1291 | | } |
| | 1 | 1292 | | } |
| | | 1293 | | #endregion |
| | | 1294 | | } |
| | | 1295 | | } |