diff --git a/sdk/search/Azure.Search.Documents/CHANGELOG.md b/sdk/search/Azure.Search.Documents/CHANGELOG.md index 198026a5cf7c..f21037ad527e 100644 --- a/sdk/search/Azure.Search.Documents/CHANGELOG.md +++ b/sdk/search/Azure.Search.Documents/CHANGELOG.md @@ -2,6 +2,10 @@ ## 1.0.0-preview.4 (Unreleased) +### Breaking Changes + +- Moved data source, index, indexer, skillset, and synonym map operations to separate clients obtained from `SearchServiceClient`. +- Renamed `SearchServiceClient.GetServiceStatistics` and `SearchServiceClient.GetServiceStatisticsAsync` to `SearchServiceClient.GetStatistics` and `SearchServiceClient.GetStatisticsAsync`, respectively. ## 1.0.0-preview.3 (2020-05-05) diff --git a/sdk/search/Azure.Search.Documents/README.md b/sdk/search/Azure.Search.Documents/README.md index 1a9ba052e4c1..96e969940aa7 100644 --- a/sdk/search/Azure.Search.Documents/README.md +++ b/sdk/search/Azure.Search.Documents/README.md @@ -310,7 +310,7 @@ SearchIndex index = new SearchIndex("hotels") } }; -client.CreateIndex(index); +client.GetSearchIndexClient().CreateIndex(index); ``` ### Adding documents to your index 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 e0956cae1c04..de3a12595185 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 @@ -98,56 +98,68 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credential, Azure.Search.Documents.SearchClientOptions options) { } public virtual System.Uri Endpoint { get { throw null; } } public virtual string ServiceName { get { throw null; } } + public virtual Azure.Search.Documents.SearchClient GetSearchClient(string indexName) { throw null; } + public virtual Azure.Search.Documents.Indexes.SearchIndexClient GetSearchIndexClient() { throw null; } + public virtual Azure.Search.Documents.Indexes.SearchIndexerClient GetSearchIndexerClient() { throw null; } + public virtual Azure.Search.Documents.Indexes.SearchIndexerDataSourceClient GetSearchIndexerDataSourceClient() { throw null; } + public virtual Azure.Search.Documents.Indexes.SearchIndexerSkillsetClient GetSearchIndexerSkillsetCllient() { throw null; } + public virtual Azure.Response GetStatistics(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetStatisticsAsync(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Search.Documents.Indexes.SynonymMapClient GetSynonymMapClient() { throw null; } + } + public partial class SuggestOptions : Azure.Search.Documents.SearchRequestOptions + { + public SuggestOptions() { } + public string Filter { get { throw null; } set { } } + public string HighlightPostTag { get { throw null; } set { } } + public string HighlightPreTag { get { throw null; } set { } } + public double? MinimumCoverage { get { throw null; } set { } } + public System.Collections.Generic.IList OrderBy { get { throw null; } } + public System.Collections.Generic.IList SearchFields { get { throw null; } } + public System.Collections.Generic.IList Select { get { throw null; } } + public int? Size { get { throw null; } set { } } + public bool? UseFuzzyMatching { get { throw null; } set { } } + } +} +namespace Azure.Search.Documents.Indexes +{ + public partial class SearchIndexClient + { + protected SearchIndexClient() { } + public virtual System.Uri Endpoint { get { throw null; } } + public virtual string ServiceName { get { throw null; } } public virtual Azure.Response> AnalyzeText(string indexName, Azure.Search.Documents.Models.AnalyzeRequest analyzeRequest, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task>> AnalyzeTextAsync(string indexName, Azure.Search.Documents.Models.AnalyzeRequest analyzeRequest, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateIndex(Azure.Search.Documents.Models.SearchIndex index, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateIndexAsync(Azure.Search.Documents.Models.SearchIndex index, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateIndexer(Azure.Search.Documents.Models.SearchIndexer indexer, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateIndexerAsync(Azure.Search.Documents.Models.SearchIndexer indexer, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateOrUpdateDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateOrUpdateDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateOrUpdateIndex(Azure.Search.Documents.Models.SearchIndex index, bool allowIndexDowntime = false, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> CreateOrUpdateIndexAsync(Azure.Search.Documents.Models.SearchIndex index, bool allowIndexDowntime = false, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateOrUpdateIndexer(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateOrUpdateIndexerAsync(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateOrUpdateSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateOrUpdateSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateOrUpdateSynonymMap(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 System.Threading.Tasks.Task> CreateOrUpdateSynonymMapAsync(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 CreateSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response CreateSynonymMap(Azure.Search.Documents.Models.SynonymMap synonymMap, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> CreateSynonymMapAsync(Azure.Search.Documents.Models.SynonymMap synonymMap, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response DeleteDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response DeleteDataSource(string dataSourceName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DeleteDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DeleteDataSourceAsync(string dataSourceName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteIndex(Azure.Search.Documents.Models.SearchIndex index, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteIndex(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteIndexAsync(Azure.Search.Documents.Models.SearchIndex index, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteIndexAsync(string indexName, 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.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 partial class SearchIndexerClient + { + protected SearchIndexerClient() { } + public virtual System.Uri Endpoint { get { throw null; } } + public virtual string ServiceName { get { throw null; } } + public virtual Azure.Response CreateIndexer(Azure.Search.Documents.Models.SearchIndexer indexer, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateIndexerAsync(Azure.Search.Documents.Models.SearchIndexer indexer, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateOrUpdateIndexer(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateOrUpdateIndexerAsync(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteIndexer(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response DeleteIndexer(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteIndexerAsync(Azure.Search.Documents.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DeleteIndexerAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response DeleteSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response DeleteSkillset(string skillsetName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DeleteSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DeleteSkillsetAsync(string skillsetName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response DeleteSynonymMap(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 DeleteSynonymMap(string synonymMapName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - 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 System.Threading.Tasks.Task DeleteSynonymMapAsync(string synonymMapName, 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> 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> GetIndexerNames(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -156,44 +168,70 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent 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(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; } - public virtual Azure.Response GetServiceStatistics(Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - 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 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; } + public virtual System.Threading.Tasks.Task RunIndexerAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } + public partial class SearchIndexerDataSourceClient + { + protected SearchIndexerDataSourceClient() { } + public virtual System.Uri Endpoint { get { throw null; } } + public virtual string ServiceName { get { throw null; } } + public virtual Azure.Response CreateDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateOrUpdateDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateOrUpdateDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteDataSource(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteDataSource(string dataSourceName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteDataSourceAsync(Azure.Search.Documents.Models.SearchIndexerDataSource dataSource, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteDataSourceAsync(string dataSourceName, 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> 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 partial class SearchIndexerSkillsetClient + { + protected SearchIndexerSkillsetClient() { } + public virtual System.Uri Endpoint { get { throw null; } } + public virtual string ServiceName { get { throw null; } } + public virtual Azure.Response CreateOrUpdateSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateOrUpdateSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteSkillset(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteSkillset(string skillsetName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteSkillsetAsync(Azure.Search.Documents.Models.SearchIndexerSkillset skillset, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteSkillsetAsync(string skillsetName, 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> 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 partial class SynonymMapClient + { + protected SynonymMapClient() { } + public virtual System.Uri Endpoint { get { throw null; } } + public virtual string ServiceName { get { throw null; } } + public virtual Azure.Response CreateOrUpdateSynonymMap(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 System.Threading.Tasks.Task> CreateOrUpdateSynonymMapAsync(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 CreateSynonymMap(Azure.Search.Documents.Models.SynonymMap synonymMap, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateSynonymMapAsync(Azure.Search.Documents.Models.SynonymMap synonymMap, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteSynonymMap(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 DeleteSynonymMap(string synonymMapName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + 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 System.Threading.Tasks.Task DeleteSynonymMapAsync(string synonymMapName, 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> 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; } - public virtual System.Threading.Tasks.Task RunIndexerAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - } - public partial class SuggestOptions : Azure.Search.Documents.SearchRequestOptions - { - public SuggestOptions() { } - public string Filter { get { throw null; } set { } } - public string HighlightPostTag { get { throw null; } set { } } - public string HighlightPreTag { get { throw null; } set { } } - public double? MinimumCoverage { get { throw null; } set { } } - public System.Collections.Generic.IList OrderBy { get { throw null; } } - public System.Collections.Generic.IList SearchFields { get { throw null; } } - public System.Collections.Generic.IList Select { get { throw null; } } - public int? Size { get { throw null; } set { } } - public bool? UseFuzzyMatching { get { throw null; } set { } } } } namespace Azure.Search.Documents.Models diff --git a/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md b/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md index eec45338a58d..109d06251ea6 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md @@ -18,7 +18,7 @@ AzureKeyCredential credential = new AzureKeyCredential( SearchServiceClient search = new SearchServiceClient(endpoint, credential); // Perform an operation -Response stats = search.GetServiceStatistics(); +Response stats = search.GetStatistics(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} indexes."); ``` diff --git a/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md b/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md index 83bd1379c508..b4d8f8191dc0 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md @@ -18,7 +18,7 @@ AzureKeyCredential credential = new AzureKeyCredential( SearchServiceClient search = new SearchServiceClient(endpoint, credential); // Perform an operation -Response stats = await search.GetServiceStatisticsAsync(); +Response stats = await search.GetStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} indexes."); ``` diff --git a/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md b/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md index 2b62ef36064e..779526630b1a 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md @@ -20,6 +20,6 @@ AzureKeyCredential credential = new AzureKeyCredential( SearchServiceClient search = new SearchServiceClient(endpoint, credential); // Get and report the Search Service statistics -Response stats = await search.GetServiceStatisticsAsync(); +Response stats = await search.GetStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} of {stats.Value.Counters.IndexCounter.Quota} indexes."); ``` diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs new file mode 100644 index 000000000000..1be1d2b2e67b --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs @@ -0,0 +1,712 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Models; + +namespace Azure.Search.Documents.Indexes +{ + /// + /// Azure Cognitive Search client that can be used to manage Search indexes. + /// + public class SearchIndexClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly IndexesRestClient _indexesClient; + + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexClient() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The that created this instance. + internal SearchIndexClient(SearchServiceClient serviceClient) + { + Debug.Assert(serviceClient != null); + + _clientDiagnostics = serviceClient.ClientDiagnostics; + Endpoint = serviceClient.Endpoint; + + _indexesClient = new IndexesRestClient(_clientDiagnostics, serviceClient.Pipeline, Endpoint.ToString(), serviceClient.Version.ToVersionString()); + } + + /// + /// Gets the URI endpoint of the Search service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// + public virtual Uri Endpoint { get; } + + /// + /// Gets the name of the Search service. + /// + public virtual string ServiceName => + _serviceName ??= Endpoint.GetSearchServiceName(); + + /// + /// Shows how an analyzer breaks text into tokens. + /// + /// The name of the index used to test an analyzer. + /// The containing the text and analyzer or analyzer components to test. + /// 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 for analyzed text. + /// + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response> AnalyzeText( + string indexName, + AnalyzeRequest analyzeRequest, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(AnalyzeText)}"); + scope.Start(); + try + { + Response result = _indexesClient.Analyze( + indexName, + analyzeRequest, + options?.ClientRequestId, + cancellationToken); + + return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Shows how an analyzer breaks text into tokens. + /// + /// The name of the index used to test an analyzer. + /// The containing the text and analyzer or analyzer components to test. + /// 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 for analyzed text. + /// + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task>> AnalyzeTextAsync( + string indexName, + AnalyzeRequest analyzeRequest, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(AnalyzeText)}"); + scope.Start(); + try + { + Response result = await _indexesClient.AnalyzeAsync( + indexName, + analyzeRequest, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new search index. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateIndex( + SearchIndex index, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndex)}"); + scope.Start(); + try + { + return _indexesClient.Create( + index, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new search index. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateIndexAsync( + SearchIndex index, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndex)}"); + scope.Start(); + try + { + return await _indexesClient.CreateAsync( + index, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new search index or updates an existing index. + /// + /// Required. The to create or update. + /// + /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be added to the index by temporarily taking the index + /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail. + /// Performance and write availability of the index can be impaired for several minutes after the index is updated, or longer for very large indexes. + /// + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created or updated. + /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateOrUpdateIndex( + SearchIndex index, + bool allowIndexDowntime = false, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndex)}"); + scope.Start(); + try + { + return _indexesClient.CreateOrUpdate( + index?.Name, + index, + allowIndexDowntime, + options?.ClientRequestId, + onlyIfUnchanged ? index?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new search index or updates an existing index. + /// + /// Required. The to create or update. + /// + /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be added to the index by temporarily taking the index + /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail. + /// Performance and write availability of the index can be impaired for several minutes after the index is updated, or longer for very large indexes. + /// + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created or updated. + /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateOrUpdateIndexAsync( + SearchIndex index, + bool allowIndexDowntime = false, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndex)}"); + scope.Start(); + try + { + return await _indexesClient.CreateOrUpdateAsync( + index?.Name, + index, + allowIndexDowntime, + options?.ClientRequestId, + onlyIfUnchanged ? index?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a search index and all the documents it contains. + /// + /// Required. The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteIndex( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return _indexesClient.Delete( + indexName, + options?.ClientRequestId, + null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a search index and all the documents it contains. + /// + /// Required. The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteIndexAsync( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return await _indexesClient.DeleteAsync( + indexName, + options?.ClientRequestId, + null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a search index and all the documents it contains. + /// + /// Required. The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteIndex( + SearchIndex index, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return _indexesClient.Delete( + index?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? index?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a search index and all the documents it contains. + /// + /// Required. The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteIndexAsync( + SearchIndex index, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return await _indexesClient.DeleteAsync( + index?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? index?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the index to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetIndex( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndex)}"); + scope.Start(); + try + { + return _indexesClient.Get( + indexName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the index to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetIndexAsync( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndex)}"); + scope.Start(); + try + { + return await _indexesClient.GetAsync( + indexName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all indexes. + /// + /// 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. + public virtual Pageable GetIndexes( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexes)}"); + scope.Start(); + try + { + return PageResponseEnumerator.CreateEnumerable((continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unsupported."); + } + + Response result = _indexesClient.List( + Constants.All, + options?.ClientRequestId, + cancellationToken); + + return Page.FromValues(result.Value.Indexes, null, result.GetRawResponse()); + }); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all indexes. + /// + /// 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. + public virtual AsyncPageable GetIndexesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexes)}"); + scope.Start(); + try + { + return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unsupported."); + } + + Response result = await _indexesClient.ListAsync( + Constants.All, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Page.FromValues(result.Value.Indexes, null, result.GetRawResponse()); + }); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual Pageable GetIndexNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexNames)}"); + scope.Start(); + try + { + return PageResponseEnumerator.CreateEnumerable((continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unsupported."); + } + + 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()); + }); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual AsyncPageable GetIndexNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexNames)}"); + scope.Start(); + try + { + return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => + { + if (continuationToken != null) + { + throw new NotSupportedException("A continuation token is unsupported."); + } + + 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()); + }); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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 names. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetIndexStatistics( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexStatistics)}"); + scope.Start(); + try + { + return _indexesClient.GetStatistics( + indexName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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 . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetIndexStatisticsAsync( + string indexName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexStatistics)}"); + scope.Start(); + try + { + return await _indexesClient.GetStatisticsAsync( + indexName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs new file mode 100644 index 000000000000..92da6abd2ade --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs @@ -0,0 +1,712 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Models; + +namespace Azure.Search.Documents.Indexes +{ + /// + /// Azure Cognitive Search client that can be used to manage Search indexers. + /// + public class SearchIndexerClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly IndexersRestClient _indexersClient; + + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexerClient() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The that created this instance. + internal SearchIndexerClient(SearchServiceClient serviceClient) + { + Debug.Assert(serviceClient != null); + + _clientDiagnostics = serviceClient.ClientDiagnostics; + Endpoint = serviceClient.Endpoint; + + _indexersClient = new IndexersRestClient(_clientDiagnostics, serviceClient.Pipeline, Endpoint.ToString(), serviceClient.Version.ToVersionString()); + } + + /// + /// Gets the URI endpoint of the Search service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// + public virtual Uri Endpoint { get; } + + /// + /// Gets the name of the Search service. + /// + public virtual string ServiceName => + _serviceName ??= Endpoint.GetSearchServiceName(); + + /// + /// Creates a new indexer. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the created. + /// This may differ slightly from what was passed into the service. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateIndexer( + SearchIndexer indexer, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Create( + indexer, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new indexer. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the created. + /// This may differ slightly from what was passed into the service. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateIndexerAsync( + SearchIndexer indexer, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.CreateAsync( + indexer, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new indexer or updates an existing indexer. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the created. + /// This may differ slightly from what was passed into the service. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateOrUpdateIndexer( + SearchIndexer indexer, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndexer)}"); + scope.Start(); + try + { + return _indexersClient.CreateOrUpdate( + indexer?.Name, + indexer, + options?.ClientRequestId, + onlyIfUnchanged ? indexer?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new indexer or updates an existing indexer. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the created. + /// This may differ slightly from what was passed into the service. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateOrUpdateIndexerAsync( + SearchIndexer indexer, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.CreateOrUpdateAsync( + indexer?.Name, + indexer, + options?.ClientRequestId, + onlyIfUnchanged ? indexer?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes an indexer. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteIndexer( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Delete( + indexerName, + options?.ClientRequestId, + null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes an indexer. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteIndexerAsync( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.DeleteAsync( + indexerName, + options?.ClientRequestId, + null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes an indexer. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteIndexer( + SearchIndexer indexer, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Delete( + indexer?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? indexer?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes an indexer. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteIndexerAsync( + SearchIndexer indexer, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.DeleteAsync( + indexer?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? indexer?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetIndexer( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Get( + indexerName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetIndexerAsync( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.GetAsync( + indexerName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all indexers. + /// + /// 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. + public virtual Response> GetIndexers( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexers)}"); + scope.Start(); + try + { + Response result = _indexersClient.List( + Constants.All, + options?.ClientRequestId, + cancellationToken); + + return Response.FromValue(result.Value.Indexers, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all indexers. + /// + /// 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. + public virtual async Task>> GetIndexersAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexers)}"); + scope.Start(); + try + { + Response result = await _indexersClient.ListAsync( + Constants.All, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue(result.Value.Indexers, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual Response> GetIndexerNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual async Task>> GetIndexerNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets the current status and execution history of an indexer. + /// + /// Required. The name of the indexer for which to retrieve status. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetIndexerStatus( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerStatus)}"); + scope.Start(); + try + { + return _indexersClient.GetStatus( + indexerName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets the current status and execution history of an indexer. + /// + /// Required. The name of the indexer for which to retrieve status. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetIndexerStatusAsync( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerStatus)}"); + scope.Start(); + try + { + return await _indexersClient.GetStatusAsync( + indexerName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Resets the change tracking state associated with an indexer. + /// + /// Required. The name of the indexer to reset. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response ResetIndexer( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(ResetIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Reset( + indexerName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Resets the change tracking state associated with an indexer. + /// + /// Required. The name of the indexer to reset. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task ResetIndexerAsync( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(ResetIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.ResetAsync( + indexerName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Run an indexer now. + /// + /// Required. The name of the indexer to run. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response RunIndexer( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(RunIndexer)}"); + scope.Start(); + try + { + return _indexersClient.Run( + indexerName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Run an indexer now. + /// + /// Required. The name of the indexer to run. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task RunIndexerAsync( + string indexerName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(RunIndexer)}"); + scope.Start(); + try + { + return await _indexersClient.RunAsync( + indexerName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerDataSourceClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerDataSourceClient.cs new file mode 100644 index 000000000000..fcd6285ddb61 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerDataSourceClient.cs @@ -0,0 +1,529 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Models; + +namespace Azure.Search.Documents.Indexes +{ + /// + /// Azure Cognitive Search client that can be used to manage Search indexer data sources. + /// + public class SearchIndexerDataSourceClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly DataSourcesRestClient _dataSourcesClient; + + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexerDataSourceClient() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The that created this instance. + internal SearchIndexerDataSourceClient(SearchServiceClient serviceClient) + { + Debug.Assert(serviceClient != null); + + _clientDiagnostics = serviceClient.ClientDiagnostics; + Endpoint = serviceClient.Endpoint; + + _dataSourcesClient = new DataSourcesRestClient(_clientDiagnostics, serviceClient.Pipeline, Endpoint.ToString(), serviceClient.Version.ToVersionString()); + } + + /// + /// Gets the URI endpoint of the Search service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// + public virtual Uri Endpoint { get; } + + /// + /// Gets the name of the Search service. + /// + public virtual string ServiceName => + _serviceName ??= Endpoint.GetSearchServiceName(); + + /// + /// Creates a new data source. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateDataSource( + SearchIndexerDataSource dataSource, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateDataSource)}"); + scope.Start(); + try + { + return _dataSourcesClient.Create( + dataSource, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new data source. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateDataSourceAsync( + SearchIndexerDataSource dataSource, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateDataSource)}"); + scope.Start(); + try + { + return await _dataSourcesClient.CreateAsync( + dataSource, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new data source or updates an existing data source. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateOrUpdateDataSource( + SearchIndexerDataSource dataSource, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateDataSource)}"); + scope.Start(); + try + { + return _dataSourcesClient.CreateOrUpdate( + dataSource?.Name, + dataSource, + options?.ClientRequestId, + onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new data source or updates an existing data source. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateOrUpdateDataSourceAsync( + SearchIndexerDataSource dataSource, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateDataSource)}"); + scope.Start(); + try + { + return await _dataSourcesClient.CreateOrUpdateAsync( + dataSource?.Name, + dataSource, + options?.ClientRequestId, + onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a data source. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteDataSource( + string dataSourceName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return _dataSourcesClient.Delete( + dataSourceName, + options?.ClientRequestId, + null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a data source. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteDataSourceAsync( + string dataSourceName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return await _dataSourcesClient.DeleteAsync( + dataSourceName, + options?.ClientRequestId, + null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a data source. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteDataSource( + SearchIndexerDataSource dataSource, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return _dataSourcesClient.Delete( + dataSource?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a data source. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteDataSourceAsync( + SearchIndexerDataSource dataSource, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return await _dataSourcesClient.DeleteAsync( + dataSource?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetDataSource( + string dataSourceName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSource)}"); + scope.Start(); + try + { + return _dataSourcesClient.Get( + dataSourceName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetDataSourceAsync( + string dataSourceName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSource)}"); + scope.Start(); + try + { + return await _dataSourcesClient.GetAsync( + dataSourceName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all data sources. + /// + /// 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. + public virtual Response> GetDataSources( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSources)}"); + scope.Start(); + try + { + Response result = _dataSourcesClient.List( + Constants.All, + options?.ClientRequestId, + cancellationToken); + + return Response.FromValue(result.Value.DataSources, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all data sources. + /// + /// 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. + public virtual async Task>> GetDataSourcesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSources)}"); + scope.Start(); + try + { + Response result = await _dataSourcesClient.ListAsync( + Constants.All, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue(result.Value.DataSources, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual Response> GetDataSourceNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSourceNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual async Task>> GetDataSourceNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSourceNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerSkillsetClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerSkillsetClient.cs new file mode 100644 index 000000000000..e9fff4d86ca3 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerSkillsetClient.cs @@ -0,0 +1,529 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Models; + +namespace Azure.Search.Documents.Indexes +{ + /// + /// Azure Cognitive Search client that can be used to manage Search indexer skillsets. + /// + public class SearchIndexerSkillsetClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly SkillsetsRestClient _skillsetsClient; + + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexerSkillsetClient() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The that created this instance. + internal SearchIndexerSkillsetClient(SearchServiceClient serviceClient) + { + Debug.Assert(serviceClient != null); + + _clientDiagnostics = serviceClient.ClientDiagnostics; + Endpoint = serviceClient.Endpoint; + + _skillsetsClient = new SkillsetsRestClient(_clientDiagnostics, serviceClient.Pipeline, Endpoint.ToString(), serviceClient.Version.ToVersionString()); + } + + /// + /// Gets the URI endpoint of the Search service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// + public virtual Uri Endpoint { get; } + + /// + /// Gets the name of the Search service. + /// + public virtual string ServiceName => + _serviceName ??= Endpoint.GetSearchServiceName(); + + /// + /// Creates a new skillset. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateSkillset( + SearchIndexerSkillset skillset, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSkillset)}"); + scope.Start(); + try + { + return _skillsetsClient.Create( + skillset, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new skillset. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateSkillsetAsync( + SearchIndexerSkillset skillset, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSkillset)}"); + scope.Start(); + try + { + return await _skillsetsClient.CreateAsync( + skillset, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new skillset or updates an existing skillset. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateOrUpdateSkillset( + SearchIndexerSkillset skillset, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSkillset)}"); + scope.Start(); + try + { + return _skillsetsClient.CreateOrUpdate( + skillset?.Name, + skillset, + options?.ClientRequestId, + onlyIfUnchanged ? skillset?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new skillset or updates an existing skillset. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateOrUpdateSkillsetAsync( + SearchIndexerSkillset skillset, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSkillset)}"); + scope.Start(); + try + { + return await _skillsetsClient.CreateOrUpdateAsync( + skillset?.Name, + skillset, + options?.ClientRequestId, + onlyIfUnchanged ? skillset?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a skillset. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteSkillset( + string skillsetName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return _skillsetsClient.Delete( + skillsetName, + options?.ClientRequestId, + null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a skillset. + /// + /// The name of the to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteSkillsetAsync( + string skillsetName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return await _skillsetsClient.DeleteAsync( + skillsetName, + options?.ClientRequestId, + null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a skillset. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteSkillset( + SearchIndexerSkillset skillset, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return _skillsetsClient.Delete( + skillset?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? skillset?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a skillset. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteSkillsetAsync( + SearchIndexerSkillset skillset, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return await _skillsetsClient.DeleteAsync( + skillset?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? skillset?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetSkillset( + string skillsetName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillset)}"); + scope.Start(); + try + { + return _skillsetsClient.Get( + skillsetName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetSkillsetAsync( + string skillsetName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillset)}"); + scope.Start(); + try + { + return await _skillsetsClient.GetAsync( + skillsetName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all skillsets. + /// + /// 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. + public virtual Response> GetSkillsets( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsets)}"); + scope.Start(); + try + { + Response result = _skillsetsClient.List( + Constants.All, + options?.ClientRequestId, + cancellationToken); + + return Response.FromValue(result.Value.Skillsets, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all skillsets. + /// + /// 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. + public virtual async Task>> GetSkillsetsAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsets)}"); + scope.Start(); + try + { + Response result = await _skillsetsClient.ListAsync( + Constants.All, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue(result.Value.Skillsets, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual Response> GetSkillsetNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsetNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual async Task>> GetSkillsetNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsetNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/Indexes/SynonymMapClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SynonymMapClient.cs new file mode 100644 index 000000000000..7e86820e3b9b --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SynonymMapClient.cs @@ -0,0 +1,529 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Models; + +namespace Azure.Search.Documents.Indexes +{ + /// + /// Azure Cognitive Search client that can be used to manage synonym maps. + /// + public class SynonymMapClient + { + private readonly ClientDiagnostics _clientDiagnostics; + private readonly SynonymMapsRestClient _synonymMapsClient; + + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SynonymMapClient() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The that created this instance. + internal SynonymMapClient(SearchServiceClient serviceClient) + { + Debug.Assert(serviceClient != null); + + _clientDiagnostics = serviceClient.ClientDiagnostics; + Endpoint = serviceClient.Endpoint; + + _synonymMapsClient = new SynonymMapsRestClient(_clientDiagnostics, serviceClient.Pipeline, Endpoint.ToString(), serviceClient.Version.ToVersionString()); + } + + /// + /// Gets the URI endpoint of the Search service. This is likely + /// to be similar to "https://{search_service}.search.windows.net". + /// + public virtual Uri Endpoint { get; } + + /// + /// Gets the name of the Search service. + /// + public virtual string ServiceName => + _serviceName ??= Endpoint.GetSearchServiceName(); + + /// + /// Creates a new synonym map. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateSynonymMap( + SynonymMap synonymMap, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSynonymMap)}"); + scope.Start(); + try + { + return _synonymMapsClient.Create( + synonymMap, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new synonym map. + /// + /// Required. The to create. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateSynonymMapAsync( + SynonymMap synonymMap, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSynonymMap)}"); + scope.Start(); + try + { + return await _synonymMapsClient.CreateAsync( + synonymMap, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new synonym map or updates an existing synonym map. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response CreateOrUpdateSynonymMap( + SynonymMap synonymMap, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSynonymMap)}"); + scope.Start(); + try + { + return _synonymMapsClient.CreateOrUpdate( + synonymMap?.Name, + synonymMap, + options?.ClientRequestId, + onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Creates a new synonym map or updates an existing synonym map. + /// + /// Required. The to create or update. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// + /// The from the server containing the that was created. + /// This may differ slightly from what was passed in since the service may return back properties set to their default values. + /// + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> CreateOrUpdateSynonymMapAsync( + SynonymMap synonymMap, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSynonymMap)}"); + scope.Start(); + try + { + return await _synonymMapsClient.CreateOrUpdateAsync( + synonymMap?.Name, + synonymMap, + options?.ClientRequestId, + onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a synonym map. + /// + /// The name of a to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteSynonymMap( + string synonymMapName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return _synonymMapsClient.Delete( + synonymMapName, + options?.ClientRequestId, + null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a synonym map. + /// + /// The name of a to delete. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteSynonymMapAsync( + string synonymMapName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return await _synonymMapsClient.DeleteAsync( + synonymMapName, + options?.ClientRequestId, + null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a synonym map. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response DeleteSynonymMap( + SynonymMap synonymMap, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return _synonymMapsClient.Delete( + synonymMap?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Deletes a synonym map. + /// + /// The to delete. + /// + /// True to throw a if the does not match the current service version; + /// otherwise, the current service version will be overwritten. + /// + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server. + /// Thrown when or is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task DeleteSynonymMapAsync( + SynonymMap synonymMap, + bool onlyIfUnchanged = false, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return await _synonymMapsClient.DeleteAsync( + synonymMap?.Name, + options?.ClientRequestId, + onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, + null, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual Response GetSynonymMap( + string synonymMapName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMap)}"); + scope.Start(); + try + { + return _synonymMapsClient.Get( + synonymMapName, + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a specific . + /// + /// Required. The name of the to get. + /// Optional to customize the operation's behavior. + /// Optional to propagate notifications that the operation should be canceled. + /// The from the server containing the requested . + /// Thrown when is null. + /// Thrown when a failure is returned by the Search service. + public virtual async Task> GetSynonymMapAsync( + string synonymMapName, + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMap)}"); + scope.Start(); + try + { + return await _synonymMapsClient.GetAsync( + synonymMapName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all synonym maps. + /// + /// 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. + public virtual Response> GetSynonymMaps( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMaps)}"); + scope.Start(); + try + { + Response result = _synonymMapsClient.List( + Constants.All, + options?.ClientRequestId, + cancellationToken); + + return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Gets a list of all synonym maps. + /// + /// 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. + public virtual async Task>> GetSynonymMapsAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMaps)}"); + scope.Start(); + try + { + Response result = await _synonymMapsClient.ListAsync( + Constants.All, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual Response> GetSynonymMapNames( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMapNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// 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. + public virtual async Task>> GetSynonymMapNamesAsync( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMapNames)}"); + scope.Start(); + try + { + 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()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs b/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs index ba6ed4021fa4..0543b4f151ec 100644 --- a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs +++ b/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs @@ -7,8 +7,7 @@ using Azure.Search.Documents.Models; using Azure.Core; using Azure.Core.Pipeline; -using System.Collections.Generic; -using System.Linq; +using Azure.Search.Documents.Indexes; namespace Azure.Search.Documents { @@ -20,11 +19,6 @@ namespace Azure.Search.Documents public class SearchServiceClient { private ServiceRestClient _serviceClient; - private DataSourcesRestClient _dataSourcesClient; - private IndexesRestClient _indexesClient; - private IndexersRestClient _indexersClient; - private SkillsetsRestClient _skillsetsClient; - private SynonymMapsRestClient _synonymMapsClient; /// /// Gets the URI endpoint of the Search service. This is likely @@ -48,19 +42,19 @@ public class SearchServiceClient /// Gets the authenticated used for sending /// requests to the Search service. /// - private HttpPipeline Pipeline { get; } + internal HttpPipeline Pipeline { get; } /// /// Gets the used /// to provide tracing support for the client library. /// - private ClientDiagnostics ClientDiagnostics { get; } + internal ClientDiagnostics ClientDiagnostics { get; } /// /// Gets the REST API version of the Search service to use when making /// requests. /// - private SearchClientOptions.ServiceVersion Version { get; } + internal SearchClientOptions.ServiceVersion Version { get; } /// /// Gets the generated to make requests. @@ -72,56 +66,6 @@ public class SearchServiceClient Version.ToVersionString()) ); - /// - /// Gets the generated to make requests. - /// - private DataSourcesRestClient DataSourcesClient => LazyInitializer.EnsureInitialized(ref _dataSourcesClient, () => new DataSourcesRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - Version.ToVersionString()) - ); - - /// - /// Gets the generated to make requests. - /// - private IndexesRestClient IndexesClient => LazyInitializer.EnsureInitialized(ref _indexesClient, () => new IndexesRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - Version.ToVersionString()) - ); - - /// - /// Gets the generated to make requests. - /// - private IndexersRestClient IndexersClient => LazyInitializer.EnsureInitialized(ref _indexersClient, () => new IndexersRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - Version.ToVersionString()) - ); - - /// - /// Gets the generated to make requests. - /// - private SkillsetsRestClient SkillsetsClient => LazyInitializer.EnsureInitialized(ref _skillsetsClient, () => new SkillsetsRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - Version.ToVersionString()) - ); - - /// - /// Gets the generated to make requests. - /// - private SynonymMapsRestClient SynonymMapsClient => LazyInitializer.EnsureInitialized(ref _synonymMapsClient, () => new SynonymMapsRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - Version.ToVersionString()) - ); - /// /// Initializes a new instance of the SearchServiceClient class for /// mocking. @@ -129,7 +73,7 @@ public class SearchServiceClient protected SearchServiceClient() { } /// - /// Initializes a new instance of the SearchServiceClient class. + /// Initializes a new instance of the class. /// /// Required. The URI endpoint of the Search service. This is likely to be similar to "https://{search_service}.search.windows.net". The URI must use HTTPS. /// @@ -145,7 +89,7 @@ public SearchServiceClient(Uri endpoint, AzureKeyCredential credential) : } /// - /// Initializes a new instance of the SearchServiceClient class. + /// Initializes a new instance of the class. /// /// Required. The URI endpoint of the Search service. This is likely to be similar to "https://{search_service}.search.windows.net". The URI must use HTTPS. /// @@ -173,15 +117,14 @@ public SearchServiceClient( } /// - /// Get a for the given to use for document operations like querying or adding documents to a Search Index. + /// Gets a for the given to use for document operations like querying or adding documents to a Search Index. /// /// The name of the desired Search Index. /// A SearchClient for the desired Search Index. /// Thrown when the is null. /// Thrown when the is empty. /// - /// The same request (including authentication and any other configuration) will be used for the - /// . + /// The same request (including authentication and any other configuration) will be used for the . /// public virtual SearchClient GetSearchClient(string indexName) { @@ -194,7 +137,50 @@ public virtual SearchClient GetSearchClient(string indexName) Version); } - #region Service operations + /// + /// Gets a to manage Search indexes using the same . + /// + /// A to manage Search indexes using the same . + /// + /// The same request (including authentication and any other configuration) will be used for the . + /// + public virtual SearchIndexClient GetSearchIndexClient() => new SearchIndexClient(this); + + /// + /// Gets a to manage Search indexers using the same . + /// + /// A to manage Search indexers using the same . + /// + /// The same request (including authentication and any other configuration) will be used for the . + /// + public virtual SearchIndexerClient GetSearchIndexerClient() => new SearchIndexerClient(this); + + /// + /// Gets a to manage Search indexer data sources using the same . + /// + /// A to manage Search indexer data sources using the same . + /// + /// The same request (including authentication and any other configuration) will be used for the . + /// + public virtual SearchIndexerDataSourceClient GetSearchIndexerDataSourceClient() => new SearchIndexerDataSourceClient(this); + + /// + /// Gets a to manage Search indexer skillsets using the same . + /// + /// A to manage Search indexer skillsets using the same . + /// + /// The same request (including authentication and any other configuration) will be used for the . + /// + public virtual SearchIndexerSkillsetClient GetSearchIndexerSkillsetCllient() => new SearchIndexerSkillsetClient(this); + + /// + /// Gets a to manage synonym maps using the same . + /// + /// A to manage synonym maps using the same . + /// + /// The same request (including authentication and any other configuration) will be used for the . + /// + public virtual SynonymMapClient GetSynonymMapClient() => new SynonymMapClient(this); /// /// @@ -218,11 +204,11 @@ public virtual SearchClient GetSearchClient(string indexName) /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing . /// Thrown when a failure is returned by the Search service. - public virtual Response GetServiceStatistics( + public virtual Response GetStatistics( SearchRequestOptions options = null, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetServiceStatistics)}"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetStatistics)}"); scope.Start(); try { @@ -259,11 +245,11 @@ public virtual Response GetServiceStatistics( /// Optional to propagate notifications that the operation should be canceled. /// The from the server containing . /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetServiceStatisticsAsync( + public virtual async Task> GetStatisticsAsync( SearchRequestOptions options = null, CancellationToken cancellationToken = default) { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetServiceStatistics)}"); + using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetStatistics)}"); scope.Start(); try { @@ -278,2736 +264,5 @@ public virtual async Task> GetServiceStatistic throw; } } - #endregion - - #region Data Sources operations - /// - /// Creates a new data source. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateDataSource( - SearchIndexerDataSource dataSource, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateDataSource)}"); - scope.Start(); - try - { - return DataSourcesClient.Create( - dataSource, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new data source. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateDataSourceAsync( - SearchIndexerDataSource dataSource, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateDataSource)}"); - scope.Start(); - try - { - return await DataSourcesClient.CreateAsync( - dataSource, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new data source or updates an existing data source. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateOrUpdateDataSource( - SearchIndexerDataSource dataSource, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateDataSource)}"); - scope.Start(); - try - { - return DataSourcesClient.CreateOrUpdate( - dataSource?.Name, - dataSource, - options?.ClientRequestId, - onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new data source or updates an existing data source. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateOrUpdateDataSourceAsync( - SearchIndexerDataSource dataSource, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateDataSource)}"); - scope.Start(); - try - { - return await DataSourcesClient.CreateOrUpdateAsync( - dataSource?.Name, - dataSource, - options?.ClientRequestId, - onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a data source. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteDataSource( - string dataSourceName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); - scope.Start(); - try - { - return DataSourcesClient.Delete( - dataSourceName, - options?.ClientRequestId, - null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a data source. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteDataSourceAsync( - string dataSourceName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); - scope.Start(); - try - { - return await DataSourcesClient.DeleteAsync( - dataSourceName, - options?.ClientRequestId, - null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a data source. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteDataSource( - SearchIndexerDataSource dataSource, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); - scope.Start(); - try - { - return DataSourcesClient.Delete( - dataSource?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a data source. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteDataSourceAsync( - SearchIndexerDataSource dataSource, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteDataSource)}"); - scope.Start(); - try - { - return await DataSourcesClient.DeleteAsync( - dataSource?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? dataSource?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetDataSource( - string dataSourceName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSource)}"); - scope.Start(); - try - { - return DataSourcesClient.Get( - dataSourceName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetDataSourceAsync( - string dataSourceName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSource)}"); - scope.Start(); - try - { - return await DataSourcesClient.GetAsync( - dataSourceName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all data sources. - /// - /// 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. - public virtual Response> GetDataSources( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSources)}"); - scope.Start(); - try - { - Response result = DataSourcesClient.List( - Constants.All, - options?.ClientRequestId, - cancellationToken); - - return Response.FromValue(result.Value.DataSources, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all data sources. - /// - /// 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. - public virtual async Task>> GetDataSourcesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSources)}"); - scope.Start(); - try - { - Response result = await DataSourcesClient.ListAsync( - Constants.All, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Response.FromValue(result.Value.DataSources, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual Response> GetDataSourceNames( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSourceNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual async Task>> GetDataSourceNamesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetDataSourceNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - #endregion - - #region Index operations - /// - /// Shows how an analyzer breaks text into tokens. - /// - /// The name of the index used to test an analyzer. - /// The containing the text and analyzer or analyzer components to test. - /// 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 for analyzed text. - /// - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response> AnalyzeText( - string indexName, - AnalyzeRequest analyzeRequest, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(AnalyzeText)}"); - scope.Start(); - try - { - Response result = IndexesClient.Analyze( - indexName, - analyzeRequest, - options?.ClientRequestId, - cancellationToken); - - return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Shows how an analyzer breaks text into tokens. - /// - /// The name of the index used to test an analyzer. - /// The containing the text and analyzer or analyzer components to test. - /// 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 for analyzed text. - /// - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task>> AnalyzeTextAsync( - string indexName, - AnalyzeRequest analyzeRequest, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(AnalyzeText)}"); - scope.Start(); - try - { - Response result = await IndexesClient.AnalyzeAsync( - indexName, - analyzeRequest, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Response.FromValue(result.Value.Tokens, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new search index. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateIndex( - SearchIndex index, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndex)}"); - scope.Start(); - try - { - return IndexesClient.Create( - index, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new search index. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateIndexAsync( - SearchIndex index, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndex)}"); - scope.Start(); - try - { - return await IndexesClient.CreateAsync( - index, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new search index or updates an existing index. - /// - /// Required. The to create or update. - /// - /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be added to the index by temporarily taking the index - /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail. - /// Performance and write availability of the index can be impaired for several minutes after the index is updated, or longer for very large indexes. - /// - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created or updated. - /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateOrUpdateIndex( - SearchIndex index, - bool allowIndexDowntime = false, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndex)}"); - scope.Start(); - try - { - return IndexesClient.CreateOrUpdate( - index?.Name, - index, - allowIndexDowntime, - options?.ClientRequestId, - onlyIfUnchanged ? index?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new search index or updates an existing index. - /// - /// Required. The to create or update. - /// - /// Optional value indicating whether to allow analyzers, tokenizers, token filters, or character filters to be added to the index by temporarily taking the index - /// offline for a few seconds. The default is false. This temporarily causes indexing and queries to fail. - /// Performance and write availability of the index can be impaired for several minutes after the index is updated, or longer for very large indexes. - /// - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created or updated. - /// This may differ slightly from what was passed in since the service may return back fields set to their default values depending on the field type and other properties. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateOrUpdateIndexAsync( - SearchIndex index, - bool allowIndexDowntime = false, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndex)}"); - scope.Start(); - try - { - return await IndexesClient.CreateOrUpdateAsync( - index?.Name, - index, - allowIndexDowntime, - options?.ClientRequestId, - onlyIfUnchanged ? index?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a search index and all the documents it contains. - /// - /// Required. The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteIndex( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); - scope.Start(); - try - { - return IndexesClient.Delete( - indexName, - options?.ClientRequestId, - null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a search index and all the documents it contains. - /// - /// Required. The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteIndexAsync( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); - scope.Start(); - try - { - return await IndexesClient.DeleteAsync( - indexName, - options?.ClientRequestId, - null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a search index and all the documents it contains. - /// - /// Required. The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteIndex( - SearchIndex index, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); - scope.Start(); - try - { - return IndexesClient.Delete( - index?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? index?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a search index and all the documents it contains. - /// - /// Required. The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteIndexAsync( - SearchIndex index, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndex)}"); - scope.Start(); - try - { - return await IndexesClient.DeleteAsync( - index?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? index?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the index to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetIndex( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndex)}"); - scope.Start(); - try - { - return IndexesClient.Get( - indexName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the index to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetIndexAsync( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndex)}"); - scope.Start(); - try - { - return await IndexesClient.GetAsync( - indexName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all indexes. - /// - /// 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. - public virtual Pageable GetIndexes( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexes)}"); - scope.Start(); - try - { - return PageResponseEnumerator.CreateEnumerable((continuationToken) => - { - if (continuationToken != null) - { - throw new NotSupportedException("A continuation token is unsupported."); - } - - Response result = IndexesClient.List( - Constants.All, - options?.ClientRequestId, - cancellationToken); - - return Page.FromValues(result.Value.Indexes, null, result.GetRawResponse()); - }); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all indexes. - /// - /// 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. - public virtual AsyncPageable GetIndexesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexes)}"); - scope.Start(); - try - { - return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => - { - if (continuationToken != null) - { - throw new NotSupportedException("A continuation token is unsupported."); - } - - Response result = await IndexesClient.ListAsync( - Constants.All, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Page.FromValues(result.Value.Indexes, null, result.GetRawResponse()); - }); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual Pageable GetIndexNames( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexNames)}"); - scope.Start(); - try - { - return PageResponseEnumerator.CreateEnumerable((continuationToken) => - { - if (continuationToken != null) - { - throw new NotSupportedException("A continuation token is unsupported."); - } - - 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()); - }); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual AsyncPageable GetIndexNamesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexNames)}"); - scope.Start(); - try - { - return PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) => - { - if (continuationToken != null) - { - throw new NotSupportedException("A continuation token is unsupported."); - } - - 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()); - }); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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 names. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetIndexStatistics( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexStatistics)}"); - scope.Start(); - try - { - return IndexesClient.GetStatistics( - indexName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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 . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetIndexStatisticsAsync( - string indexName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexStatistics)}"); - scope.Start(); - try - { - return await IndexesClient.GetStatisticsAsync( - indexName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - #endregion - - #region Indexer operations - /// - /// Creates a new indexer. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the created. - /// This may differ slightly from what was passed into the service. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateIndexer( - SearchIndexer indexer, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Create( - indexer, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new indexer. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the created. - /// This may differ slightly from what was passed into the service. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateIndexerAsync( - SearchIndexer indexer, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.CreateAsync( - indexer, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new indexer or updates an existing indexer. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the created. - /// This may differ slightly from what was passed into the service. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateOrUpdateIndexer( - SearchIndexer indexer, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndexer)}"); - scope.Start(); - try - { - return IndexersClient.CreateOrUpdate( - indexer?.Name, - indexer, - options?.ClientRequestId, - onlyIfUnchanged ? indexer?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new indexer or updates an existing indexer. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the created. - /// This may differ slightly from what was passed into the service. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateOrUpdateIndexerAsync( - SearchIndexer indexer, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.CreateOrUpdateAsync( - indexer?.Name, - indexer, - options?.ClientRequestId, - onlyIfUnchanged ? indexer?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes an indexer. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteIndexer( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Delete( - indexerName, - options?.ClientRequestId, - null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes an indexer. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteIndexerAsync( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.DeleteAsync( - indexerName, - options?.ClientRequestId, - null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes an indexer. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteIndexer( - SearchIndexer indexer, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Delete( - indexer?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? indexer?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes an indexer. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteIndexerAsync( - SearchIndexer indexer, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.DeleteAsync( - indexer?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? indexer?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetIndexer( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Get( - indexerName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetIndexerAsync( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.GetAsync( - indexerName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all indexers. - /// - /// 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. - public virtual Response> GetIndexers( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexers)}"); - scope.Start(); - try - { - Response result = IndexersClient.List( - Constants.All, - options?.ClientRequestId, - cancellationToken); - - return Response.FromValue(result.Value.Indexers, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all indexers. - /// - /// 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. - public virtual async Task>> GetIndexersAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexers)}"); - scope.Start(); - try - { - Response result = await IndexersClient.ListAsync( - Constants.All, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Response.FromValue(result.Value.Indexers, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual Response> GetIndexerNames( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual async Task>> GetIndexerNamesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets the current status and execution history of an indexer. - /// - /// Required. The name of the indexer for which to retrieve status. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetIndexerStatus( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerStatus)}"); - scope.Start(); - try - { - return IndexersClient.GetStatus( - indexerName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets the current status and execution history of an indexer. - /// - /// Required. The name of the indexer for which to retrieve status. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetIndexerStatusAsync( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetIndexerStatus)}"); - scope.Start(); - try - { - return await IndexersClient.GetStatusAsync( - indexerName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Resets the change tracking state associated with an indexer. - /// - /// Required. The name of the indexer to reset. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response ResetIndexer( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(ResetIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Reset( - indexerName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Resets the change tracking state associated with an indexer. - /// - /// Required. The name of the indexer to reset. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task ResetIndexerAsync( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(ResetIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.ResetAsync( - indexerName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Run an indexer now. - /// - /// Required. The name of the indexer to run. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response RunIndexer( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(RunIndexer)}"); - scope.Start(); - try - { - return IndexersClient.Run( - indexerName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Run an indexer now. - /// - /// Required. The name of the indexer to run. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task RunIndexerAsync( - string indexerName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(RunIndexer)}"); - scope.Start(); - try - { - return await IndexersClient.RunAsync( - indexerName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - #endregion - - #region Skillsets operations - /// - /// Creates a new skillset. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateSkillset( - SearchIndexerSkillset skillset, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSkillset)}"); - scope.Start(); - try - { - return SkillsetsClient.Create( - skillset, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new skillset. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateSkillsetAsync( - SearchIndexerSkillset skillset, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSkillset)}"); - scope.Start(); - try - { - return await SkillsetsClient.CreateAsync( - skillset, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new skillset or updates an existing skillset. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateOrUpdateSkillset( - SearchIndexerSkillset skillset, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSkillset)}"); - scope.Start(); - try - { - return SkillsetsClient.CreateOrUpdate( - skillset?.Name, - skillset, - options?.ClientRequestId, - onlyIfUnchanged ? skillset?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new skillset or updates an existing skillset. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateOrUpdateSkillsetAsync( - SearchIndexerSkillset skillset, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSkillset)}"); - scope.Start(); - try - { - return await SkillsetsClient.CreateOrUpdateAsync( - skillset?.Name, - skillset, - options?.ClientRequestId, - onlyIfUnchanged ? skillset?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a skillset. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteSkillset( - string skillsetName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); - scope.Start(); - try - { - return SkillsetsClient.Delete( - skillsetName, - options?.ClientRequestId, - null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a skillset. - /// - /// The name of the to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteSkillsetAsync( - string skillsetName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); - scope.Start(); - try - { - return await SkillsetsClient.DeleteAsync( - skillsetName, - options?.ClientRequestId, - null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a skillset. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteSkillset( - SearchIndexerSkillset skillset, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); - scope.Start(); - try - { - return SkillsetsClient.Delete( - skillset?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? skillset?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a skillset. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteSkillsetAsync( - SearchIndexerSkillset skillset, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSkillset)}"); - scope.Start(); - try - { - return await SkillsetsClient.DeleteAsync( - skillset?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? skillset?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetSkillset( - string skillsetName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillset)}"); - scope.Start(); - try - { - return SkillsetsClient.Get( - skillsetName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetSkillsetAsync( - string skillsetName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillset)}"); - scope.Start(); - try - { - return await SkillsetsClient.GetAsync( - skillsetName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all skillsets. - /// - /// 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. - public virtual Response> GetSkillsets( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsets)}"); - scope.Start(); - try - { - Response result = SkillsetsClient.List( - Constants.All, - options?.ClientRequestId, - cancellationToken); - - return Response.FromValue(result.Value.Skillsets, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all skillsets. - /// - /// 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. - public virtual async Task>> GetSkillsetsAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsets)}"); - scope.Start(); - try - { - Response result = await SkillsetsClient.ListAsync( - Constants.All, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Response.FromValue(result.Value.Skillsets, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual Response> GetSkillsetNames( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsetNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual async Task>> GetSkillsetNamesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSkillsetNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - #endregion - - #region SynonymMaps operations - /// - /// Creates a new synonym map. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateSynonymMap( - SynonymMap synonymMap, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSynonymMap)}"); - scope.Start(); - try - { - return SynonymMapsClient.Create( - synonymMap, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new synonym map. - /// - /// Required. The to create. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateSynonymMapAsync( - SynonymMap synonymMap, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateSynonymMap)}"); - scope.Start(); - try - { - return await SynonymMapsClient.CreateAsync( - synonymMap, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new synonym map or updates an existing synonym map. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response CreateOrUpdateSynonymMap( - SynonymMap synonymMap, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSynonymMap)}"); - scope.Start(); - try - { - return SynonymMapsClient.CreateOrUpdate( - synonymMap?.Name, - synonymMap, - options?.ClientRequestId, - onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Creates a new synonym map or updates an existing synonym map. - /// - /// Required. The to create or update. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// - /// The from the server containing the that was created. - /// This may differ slightly from what was passed in since the service may return back properties set to their default values. - /// - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> CreateOrUpdateSynonymMapAsync( - SynonymMap synonymMap, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(CreateOrUpdateSynonymMap)}"); - scope.Start(); - try - { - return await SynonymMapsClient.CreateOrUpdateAsync( - synonymMap?.Name, - synonymMap, - options?.ClientRequestId, - onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a synonym map. - /// - /// The name of a to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteSynonymMap( - string synonymMapName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); - scope.Start(); - try - { - return SynonymMapsClient.Delete( - synonymMapName, - options?.ClientRequestId, - null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a synonym map. - /// - /// The name of a to delete. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteSynonymMapAsync( - string synonymMapName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); - scope.Start(); - try - { - return await SynonymMapsClient.DeleteAsync( - synonymMapName, - options?.ClientRequestId, - null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a synonym map. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response DeleteSynonymMap( - SynonymMap synonymMap, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); - scope.Start(); - try - { - return SynonymMapsClient.Delete( - synonymMap?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, - null, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Deletes a synonym map. - /// - /// The to delete. - /// - /// True to throw a if the does not match the current service version; - /// otherwise, the current service version will be overwritten. - /// - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server. - /// Thrown when or is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task DeleteSynonymMapAsync( - SynonymMap synonymMap, - bool onlyIfUnchanged = false, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(DeleteSynonymMap)}"); - scope.Start(); - try - { - return await SynonymMapsClient.DeleteAsync( - synonymMap?.Name, - options?.ClientRequestId, - onlyIfUnchanged ? synonymMap?.ETag?.ToString() : null, - null, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual Response GetSynonymMap( - string synonymMapName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMap)}"); - scope.Start(); - try - { - return SynonymMapsClient.Get( - synonymMapName, - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a specific . - /// - /// Required. The name of the to get. - /// Optional to customize the operation's behavior. - /// Optional to propagate notifications that the operation should be canceled. - /// The from the server containing the requested . - /// Thrown when is null. - /// Thrown when a failure is returned by the Search service. - public virtual async Task> GetSynonymMapAsync( - string synonymMapName, - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMap)}"); - scope.Start(); - try - { - return await SynonymMapsClient.GetAsync( - synonymMapName, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all synonym maps. - /// - /// 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. - public virtual Response> GetSynonymMaps( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMaps)}"); - scope.Start(); - try - { - Response result = SynonymMapsClient.List( - Constants.All, - options?.ClientRequestId, - cancellationToken); - - return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Gets a list of all synonym maps. - /// - /// 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. - public virtual async Task>> GetSynonymMapsAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMaps)}"); - scope.Start(); - try - { - Response result = await SynonymMapsClient.ListAsync( - Constants.All, - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - - return Response.FromValue(result.Value.SynonymMaps, result.GetRawResponse()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual Response> GetSynonymMapNames( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMapNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// 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. - public virtual async Task>> GetSynonymMapNamesAsync( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetSynonymMapNames)}"); - scope.Start(); - try - { - 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()); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - #endregion } } diff --git a/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs b/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs index 74004a813c6b..cbfe08481297 100644 --- a/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs +++ b/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs @@ -38,7 +38,7 @@ public async Task CreateClient() /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); // Perform an operation - Response stats = search.GetServiceStatistics(); + Response stats = search.GetStatistics(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} indexes."); #endregion Snippet:Azure_Search_Tests_Samples_CreateClient @@ -64,7 +64,7 @@ public async Task CreateClientAsync() /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); // Perform an operation - Response stats = await search.GetServiceStatisticsAsync(); + Response stats = await search.GetStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} indexes."); #endregion Snippet:Azure_Search_Tests_Samples_CreateClientAsync @@ -143,7 +143,7 @@ public async Task GetStatisticsAsync() /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); // Get and report the Search Service statistics - Response stats = await search.GetServiceStatisticsAsync(); + Response stats = await search.GetStatisticsAsync(); Console.WriteLine($"You are using {stats.Value.Counters.IndexCounter.Usage} of {stats.Value.Counters.IndexCounter.Quota} indexes."); #endregion Snippet:Azure_Search_Tests_Samples_GetStatisticsAsync } diff --git a/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs b/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs index d9eff1c0e5bc..481f563d3c68 100644 --- a/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs +++ b/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs @@ -224,7 +224,7 @@ public async Task CreateIndex() } }; - client.CreateIndex(index); + client.GetSearchIndexClient().CreateIndex(index); #endregion Snippet:Azure_Search_Tests_Samples_Readme_CreateIndex } diff --git a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs index 2400b325b8b1..ad9da5359da2 100644 --- a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs +++ b/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs @@ -9,6 +9,7 @@ using Azure.Core; using Azure.Core.Pipeline; using Azure.Core.TestFramework; +using Azure.Search.Documents.Indexes; using Azure.Search.Documents.Models; using NUnit.Framework; @@ -85,7 +86,7 @@ public async Task ClientRequestIdRountrips() SearchServiceClient client = resources.GetServiceClient(); Guid id = Recording.Random.NewGuid(); Response response = - await client.GetServiceStatisticsAsync( + await client.GetStatisticsAsync( new SearchRequestOptions { ClientRequestId = id }); Assert.AreEqual(id.ToString(), response.GetRawResponse().ClientRequestId); @@ -123,7 +124,7 @@ public async Task GetServiceStatistics() await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchServiceClient client = resources.GetServiceClient(); - Response response = await client.GetServiceStatisticsAsync(); + Response response = await client.GetStatisticsAsync(); Assert.AreEqual(200, response.GetRawResponse().Status); Assert.IsNotNull(response.Value); Assert.IsNotNull(response.Value.Counters); @@ -143,7 +144,7 @@ public async Task GetServiceStatistics() public void CreateIndexParameterValidation() { var endpoint = new Uri($"https://my-svc-name.search.windows.net"); - var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")); + var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")).GetSearchIndexClient(); ArgumentException ex = Assert.Throws(() => service.CreateIndex(null)); Assert.AreEqual("index", ex.ParamName); @@ -161,7 +162,7 @@ public async Task CreateIndex() SearchIndex expectedIndex = SearchResources.GetHotelIndex(resources.IndexName); SearchServiceClient client = resources.GetServiceClient(); - SearchIndex actualIndex = await client.CreateIndexAsync(expectedIndex); + SearchIndex actualIndex = await client.GetSearchIndexClient().CreateIndexAsync(expectedIndex); Assert.AreEqual(expectedIndex.Name, actualIndex.Name); Assert.That(actualIndex.Fields, Is.EqualTo(expectedIndex.Fields).Using(SearchFieldComparer.Shared)); @@ -180,7 +181,7 @@ public async Task UpdateIndex() SearchIndex initialIndex = SearchResources.GetHotelIndex(resources.IndexName); SearchServiceClient client = resources.GetServiceClient(); - SearchIndex createdIndex = await client.CreateIndexAsync(initialIndex); + SearchIndex createdIndex = await client.GetSearchIndexClient().CreateIndexAsync(initialIndex); string analyzerName = "asciiTags"; @@ -209,7 +210,7 @@ public async Task UpdateIndex() IsFilterable = true, }); - SearchIndex updatedIndex = await client.CreateOrUpdateIndexAsync( + SearchIndex updatedIndex = await client.GetSearchIndexClient().CreateOrUpdateIndexAsync( createdIndex, allowIndexDowntime: true, onlyIfUnchanged: true, @@ -229,7 +230,7 @@ public async Task UpdateIndex() public void GetIndexParameterValidation() { var endpoint = new Uri($"https://my-svc-name.search.windows.net"); - var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")); + var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")).GetSearchIndexClient(); ArgumentException ex = Assert.Throws(() => service.GetIndex(null)); Assert.AreEqual("indexName", ex.ParamName); @@ -244,7 +245,7 @@ public async Task GetIndex() await using SearchResources resources = await SearchResources.CreateWithHotelsIndexAsync(this); SearchServiceClient client = resources.GetServiceClient(); - SearchIndex index = await client.GetIndexAsync(resources.IndexName); + SearchIndex index = await client.GetSearchIndexClient().GetIndexAsync(resources.IndexName); // TODO: Replace with comparison of actual SearchIndex once test framework uses Azure.Search.Documents instead. Assert.AreEqual(resources.IndexName, index.Name); @@ -259,7 +260,7 @@ public async Task GetIndexes() SearchServiceClient client = resources.GetServiceClient(); bool found = false; - await foreach (SearchIndex index in client.GetIndexesAsync()) + await foreach (SearchIndex index in client.GetSearchIndexClient().GetIndexesAsync()) { found |= string.Equals(resources.IndexName, index.Name, StringComparison.InvariantCultureIgnoreCase); } @@ -274,7 +275,7 @@ public async Task GetIndexesNextPageThrows() await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); SearchServiceClient client = resources.GetServiceClient(); - AsyncPageable pageable = client.GetIndexesAsync(); + AsyncPageable pageable = client.GetSearchIndexClient().GetIndexesAsync(); string continuationToken = Recording.GenerateId(); IAsyncEnumerator> e = pageable.AsPages(continuationToken).GetAsyncEnumerator(); @@ -297,7 +298,7 @@ public async Task CreateAzureBlobIndexer() resources.StorageAccountConnectionString, new SearchIndexerDataContainer(resources.BlobContainerName)); - SearchIndexerDataSource actualSource = await serviceClient.CreateDataSourceAsync( + SearchIndexerDataSource actualSource = await serviceClient.GetSearchIndexerDataSourceClient().CreateDataSourceAsync( dataSource, new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); @@ -306,13 +307,14 @@ public async Task CreateAzureBlobIndexer() dataSource.Name, resources.IndexName); - SearchIndexer actualIndexer = await serviceClient.CreateIndexerAsync( + SearchIndexerClient indexerClient = serviceClient.GetSearchIndexerClient(); + SearchIndexer actualIndexer = await indexerClient.CreateIndexerAsync( indexer, new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); // Update the indexer. actualIndexer.Description = "Updated description"; - await serviceClient.CreateOrUpdateIndexerAsync( + await indexerClient.CreateOrUpdateIndexerAsync( actualIndexer, onlyIfUnchanged: true, new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); @@ -320,7 +322,7 @@ await serviceClient.CreateOrUpdateIndexerAsync( await WaitForIndexingAsync(serviceClient, actualIndexer.Name); // Run the indexer. - await serviceClient.RunIndexerAsync( + await indexerClient.RunIndexerAsync( indexer.Name, new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); @@ -343,7 +345,7 @@ public async Task CrudSynonymMaps() string synonymMapName = Recording.Random.GetName(); - SearchServiceClient client = resources.GetServiceClient(); + SynonymMapClient client = resources.GetServiceClient().GetSynonymMapClient(); SynonymMap createdMap = await client.CreateSynonymMapAsync(new SynonymMap(synonymMapName, "msft=>Microsoft")); Assert.AreEqual(synonymMapName, createdMap.Name); @@ -403,7 +405,7 @@ private async Task WaitForIndexingAsync( { await DelayAsync(delay, cancellationToken: cts.Token); - SearchIndexerStatus status = await client.GetIndexerStatusAsync( + SearchIndexerStatus status = await client.GetSearchIndexerClient().GetIndexerStatusAsync( indexerName, new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }, cts.Token); diff --git a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs index 036250b4cd47..bf25be5683f3 100644 --- a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs +++ b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs @@ -10,10 +10,10 @@ using System.Threading; using System.Threading.Tasks; using Azure.Core.TestFramework; +using Azure.Search.Documents.Indexes; using Azure.Search.Documents.Models; using Azure.Storage.Blobs; using NUnit.Framework; -using NUnit.Framework.Internal; namespace Azure.Search.Documents.Tests { @@ -283,7 +283,7 @@ private async Task DeleteIndexAsync() { if (RequiresCleanup && !string.IsNullOrEmpty(IndexName)) { - SearchServiceClient client = GetServiceClient(); + SearchIndexClient client = GetServiceClient().GetSearchIndexClient(); await client.DeleteIndexAsync(IndexName); RequiresCleanup = false; } @@ -315,7 +315,7 @@ private async Task CreateSearchServiceAndIndexAsync() // Generate a random Index Name IndexName = Random.GetName(8); - SearchServiceClient client = new SearchServiceClient(Endpoint, new AzureKeyCredential(PrimaryApiKey)); + SearchIndexClient client = new SearchServiceClient(Endpoint, new AzureKeyCredential(PrimaryApiKey)).GetSearchIndexClient(); await client.CreateIndexAsync(GetHotelIndex(IndexName)); RequiresCleanup = true;