From 7dd617d860dea8c6e7ddf6178176a0f7ee806c50 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Fri, 8 May 2020 16:56:10 -0700 Subject: [PATCH] Add Get{Resource}Names methods and remove $select support (#11929) * Add Get{Resource}Names methods and remove $select support Fixes #11393. For now, there's very little practical value for passing $select given restrictions in which fields can even be specified (limited) and that they may be cased differently than models (Search is case-sensitive). But the server does have an optimized code path for returning just names, so we expose those methods instead. --- .../Azure.Search.Documents.netstandard2.0.cs | 30 +- .../src/Models/SynonymMap.cs | 39 --- .../src/SearchServiceClient.cs | 272 +++++++++++++++--- .../src/Utilities/Constants.cs | 5 + .../tests/Models/SynonymMapTests.cs | 33 --- .../tests/SearchServiceClientTests.cs | 8 +- 6 files changed, 266 insertions(+), 121 deletions(-) diff --git a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs index fe218345d480..08590ab34303 100644 --- a/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs +++ b/sdk/search/Azure.Search.Documents/api/Azure.Search.Documents.netstandard2.0.cs @@ -138,18 +138,24 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent public virtual System.Threading.Tasks.Task DeleteSynonymMapAsync(Azure.Search.Documents.Models.SynonymMap synonymMap, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetDataSource(string dataSourceName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetDataSourceAsync(string dataSourceName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response> GetDataSources(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> GetDataSourcesAsync(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetDataSourceNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetDataSourceNamesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetDataSources(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetDataSourcesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetIndex(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetIndexAsync(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetIndexer(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetIndexerAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response> GetIndexers(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> GetIndexersAsync(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetIndexerNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetIndexerNamesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetIndexers(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetIndexersAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetIndexerStatus(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetIndexerStatusAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Pageable GetIndexes(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.AsyncPageable GetIndexesAsync(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Pageable GetIndexes(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.AsyncPageable GetIndexesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Pageable GetIndexNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.AsyncPageable GetIndexNamesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetIndexStatistics(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetIndexStatisticsAsync(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Search.Documents.SearchClient GetSearchClient(string indexName) { throw null; } @@ -157,12 +163,16 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent public virtual System.Threading.Tasks.Task> GetServiceStatisticsAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSkillset(string skillsetName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSkillsetAsync(string skillsetName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response> GetSkillsets(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> GetSkillsetsAsync(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetSkillsetNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetSkillsetNamesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetSkillsets(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetSkillsetsAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetSynonymMap(string synonymMapName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetSynonymMapAsync(string synonymMapName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response> GetSynonymMaps(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task>> GetSynonymMapsAsync(System.Collections.Generic.IEnumerable selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetSynonymMapNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetSynonymMapNamesAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response> GetSynonymMaps(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task>> GetSynonymMapsAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response ResetIndexer(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task ResetIndexerAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RunIndexer(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/search/Azure.Search.Documents/src/Models/SynonymMap.cs b/sdk/search/Azure.Search.Documents/src/Models/SynonymMap.cs index 5d7e3142056b..1ea3da55e2b9 100644 --- a/sdk/search/Azure.Search.Documents/src/Models/SynonymMap.cs +++ b/sdk/search/Azure.Search.Documents/src/Models/SynonymMap.cs @@ -2,9 +2,7 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using Azure.Core; namespace Azure.Search.Documents.Models @@ -67,42 +65,5 @@ public ETag? ETag get => _etag is null ? (ETag?)null : new ETag(_etag); set => _etag = value?.ToString(); } - - /// - /// Canonicalizes property names from how they appear on to those expected by the Search service. - /// - /// The given property names. - /// Canonicalized property names expected by the Search service, or null if is null. - internal static IEnumerable CanonicalizePropertyNames(IEnumerable names) => - // TODO: Replace when https://github.com/Azure/azure-sdk-for-net/issues/11393 is resolved. - names?.Select(name => - { - if (string.Equals("name", name, StringComparison.InvariantCultureIgnoreCase)) - { - return "name"; - } - - if (string.Equals("format", name, StringComparison.InvariantCultureIgnoreCase)) - { - return "format"; - } - - if (string.Equals("synonyms", name, StringComparison.InvariantCultureIgnoreCase)) - { - return "synonyms"; - } - - if (string.Equals("encryptionKey", name, StringComparison.InvariantCultureIgnoreCase)) - { - return "encryptionKey"; - } - - if (string.Equals("etag", name, StringComparison.InvariantCultureIgnoreCase)) - { - return "@odata.etag"; - } - - return name; - }); } } diff --git a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs b/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs index 5693073c3dff..24fd186a2b7c 100644 --- a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs +++ b/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs @@ -8,6 +8,7 @@ using Azure.Core; using Azure.Core.Pipeline; using System.Collections.Generic; +using System.Linq; namespace Azure.Search.Documents { @@ -438,19 +439,17 @@ await DataSourcesClient.GetAsync( /// /// Gets a list of all data sources. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual Response> GetDataSources( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = DataSourcesClient.List( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken); @@ -460,25 +459,66 @@ public virtual Response> GetDataSources( /// /// Gets a list of all data sources. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual async Task>> GetDataSourcesAsync( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = await DataSourcesClient.ListAsync( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken) .ConfigureAwait(false); return Response.FromValue(result.Value.DataSources, result.GetRawResponse()); } + + /// + /// Gets a list of all data source names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual Response> GetDataSourceNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = DataSourcesClient.List( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken); + + IReadOnlyList names = result.Value.DataSources.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } + + /// + /// Gets a list of all data source names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual async Task>> GetDataSourceNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = await DataSourcesClient.ListAsync( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + IReadOnlyList names = result.Value.DataSources.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } #endregion #region Index operations @@ -734,14 +774,12 @@ await IndexesClient.GetAsync( /// /// Gets a list of all indexes. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual Pageable GetIndexes( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateEnumerable((continuationToken) => { @@ -751,7 +789,7 @@ public virtual Pageable GetIndexes( } Response result = IndexesClient.List( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken); @@ -761,14 +799,12 @@ public virtual Pageable GetIndexes( /// /// Gets a list of all indexes. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual AsyncPageable GetIndexesAsync( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => { @@ -778,7 +814,7 @@ public virtual AsyncPageable GetIndexesAsync( } Response result = await IndexesClient.ListAsync( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken) .ConfigureAwait(false); @@ -786,13 +822,66 @@ public virtual AsyncPageable GetIndexesAsync( return Page.FromValues(result.Value.Indexes, null, result.GetRawResponse()); }); + /// + /// Gets a list of all index names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual Pageable GetIndexNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateEnumerable((continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unexpected and unsupported at this time."); + } + + Response result = IndexesClient.List( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken); + + IReadOnlyList names = result.Value.Indexes.Select(value => value.Name).ToArray(); + return Page.FromValues(names, null, result.GetRawResponse()); + }); + + /// + /// Gets a list of all index names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual AsyncPageable GetIndexNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unexpected and unsupported at this time."); + } + + Response result = await IndexesClient.ListAsync( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + IReadOnlyList names = result.Value.Indexes.Select(value => value.Name).ToArray(); + return Page.FromValues(names, null, result.GetRawResponse()); + }); + /// /// Gets for the given index, including a document count and storage usage. /// /// Required. The name of the index. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing . + /// The from the server containing names. /// Thrown when is null. /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] @@ -1008,19 +1097,17 @@ await IndexersClient.GetAsync( /// /// Gets a list of all indexers. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual Response> GetIndexers( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = IndexersClient.List( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken); @@ -1030,19 +1117,17 @@ public virtual Response> GetIndexers( /// /// Gets a list of all indexers. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual async Task>> GetIndexersAsync( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = await IndexersClient.ListAsync( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken) .ConfigureAwait(false); @@ -1050,6 +1135,49 @@ public virtual async Task>> GetIndexersAsy return Response.FromValue(result.Value.Indexers, result.GetRawResponse()); } + /// + /// Gets a list of all indexer names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual Response> GetIndexerNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = IndexersClient.List( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken); + + IReadOnlyList names = result.Value.Indexers.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } + + /// + /// Gets a list of all indexer names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual async Task>> GetIndexerNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = await IndexersClient.ListAsync( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + IReadOnlyList names = result.Value.Indexers.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } + /// /// Gets the current status and execution history of an indexer. /// @@ -1350,19 +1478,17 @@ await SkillsetsClient.GetAsync( /// /// Gets a list of all skillsets. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual Response> GetSkillsets( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = SkillsetsClient.List( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken); @@ -1372,25 +1498,66 @@ public virtual Response> GetSkillsets( /// /// Gets a list of all skillsets. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual async Task>> GetSkillsetsAsync( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { Response result = await SkillsetsClient.ListAsync( - selectProperties.CommaJoin() ?? Constants.All, + Constants.All, options?.ClientRequestId, cancellationToken) .ConfigureAwait(false); return Response.FromValue(result.Value.Skillsets, result.GetRawResponse()); } + + /// + /// Gets a list of all skillset names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual Response> GetSkillsetNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = SkillsetsClient.List( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken); + + IReadOnlyList names = result.Value.Skillsets.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } + + /// + /// Gets a list of all skillset names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual async Task>> GetSkillsetNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = await SkillsetsClient.ListAsync( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + IReadOnlyList names = result.Value.Skillsets.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } #endregion #region SynonymMaps operations @@ -1595,21 +1762,17 @@ await SynonymMapsClient.GetAsync( /// /// Gets a list of all synonym maps. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual Response> GetSynonymMaps( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { - string select = SynonymMap.CanonicalizePropertyNames(selectProperties).CommaJoin() ?? Constants.All; - Response result = SynonymMapsClient.List( - select, + Constants.All, options?.ClientRequestId, cancellationToken); @@ -1619,27 +1782,66 @@ public virtual Response> GetSynonymMaps( /// /// Gets a list of all synonym maps. /// - /// Optional property names to select. The default is all properties. /// Optional to customize the operation's behavior. /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing a list of . /// Thrown when a failure is returned by the Search service. [ForwardsClientCalls] public virtual async Task>> GetSynonymMapsAsync( - IEnumerable selectProperties = null, SearchRequestOptions options = null, CancellationToken cancellationToken = default) { - string select = SynonymMap.CanonicalizePropertyNames(selectProperties).CommaJoin() ?? Constants.All; - Response result = await SynonymMapsClient.ListAsync( - select, + Constants.All, options?.ClientRequestId, cancellationToken) .ConfigureAwait(false); return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); } + + /// + /// Gets a list of all synonym map names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual Response> GetSynonymMapNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = SynonymMapsClient.List( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken); + + IReadOnlyList names = result.Value.SynonymMaps.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } + + /// + /// Gets a list of all synonym map names. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing a list of names. + /// Thrown when a failure is returned by the Search service. + [ForwardsClientCalls] + public virtual async Task>> GetSynonymMapNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + Response result = await SynonymMapsClient.ListAsync( + Constants.NameKey, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + IReadOnlyList names = result.Value.SynonymMaps.Select(value => value.Name).ToArray(); + return Response.FromValue(names, result.GetRawResponse()); + } #endregion } } diff --git a/sdk/search/Azure.Search.Documents/src/Utilities/Constants.cs b/sdk/search/Azure.Search.Documents/src/Utilities/Constants.cs index 8fc0a34e28a9..7ff64ebabc4f 100644 --- a/sdk/search/Azure.Search.Documents/src/Utilities/Constants.cs +++ b/sdk/search/Azure.Search.Documents/src/Utilities/Constants.cs @@ -87,6 +87,11 @@ internal static class Constants /// public const string ODataNextLinkKey = "@odata.nextLink"; + /// + /// The name key. + /// + public const string NameKey = "name"; + /// /// The value key. /// diff --git a/sdk/search/Azure.Search.Documents/tests/Models/SynonymMapTests.cs b/sdk/search/Azure.Search.Documents/tests/Models/SynonymMapTests.cs index af4d80a7782e..bfe784649a71 100644 --- a/sdk/search/Azure.Search.Documents/tests/Models/SynonymMapTests.cs +++ b/sdk/search/Azure.Search.Documents/tests/Models/SynonymMapTests.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.IO; using Azure.Search.Documents.Models; using NUnit.Framework; @@ -49,38 +48,6 @@ public void SynonymsFromTextReader() Assert.AreEqual("ms,msft=>Microsoft\naz=>Azure", map.Synonyms); } - [Test] - public void CanonicalizesNullPropertyNames() - { - Assert.IsNull(SynonymMap.CanonicalizePropertyNames(null)); - } - - [Test] - public void CanonicalizesPropertyNames() - { - IEnumerable actual = SynonymMap.CanonicalizePropertyNames(new[] - { - nameof(SynonymMap.Name), - nameof(SynonymMap.Format), - nameof(SynonymMap.Synonyms), - nameof(SynonymMap.EncryptionKey), - nameof(SynonymMap.ETag), - "Other", - }); - - IEnumerable expected = new[] - { - "name", - "format", - "synonyms", - "encryptionKey", - "@odata.etag", - "Other", - }; - - CollectionAssert.AreEqual(expected, actual); - } - [TestCase(null, null)] [TestCase("*", "*")] [TestCase("\"0123abcd\"", "\"0123abcd\"")] diff --git a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs index 03212b5e7c70..646e876f556f 100644 --- a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs +++ b/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs @@ -370,12 +370,12 @@ await client.CreateOrUpdateSynonymMapAsync( onlyIfUnchanged: true)); Assert.AreEqual((int)HttpStatusCode.PreconditionFailed, ex.Status); - Response> mapsResponse = await client.GetSynonymMapsAsync(new[] { nameof(SynonymMap.Name) }); - foreach (SynonymMap namedMap in mapsResponse.Value) + Response> names = await client.GetSynonymMapNamesAsync(); + foreach (string name in names.Value) { - if (string.Equals(updatedMap.Name, namedMap.Name, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(updatedMap.Name, name, StringComparison.OrdinalIgnoreCase)) { - SynonymMap fetchedMap = await client.GetSynonymMapAsync(namedMap.Name); + SynonymMap fetchedMap = await client.GetSynonymMapAsync(name); Assert.AreEqual(updatedMap.Synonyms, fetchedMap.Synonyms); } }