diff --git a/sdk/search/Azure.Search.Documents/CHANGELOG.md b/sdk/search/Azure.Search.Documents/CHANGELOG.md index f2682eb2b40f..b813d0fc4096 100644 --- a/sdk/search/Azure.Search.Documents/CHANGELOG.md +++ b/sdk/search/Azure.Search.Documents/CHANGELOG.md @@ -5,6 +5,7 @@ ### Breaking Changes - Moved models for managing indexes, indexers, and skillsets to `Azure.Search.Documents.Indexes.Models`. +- Split `SearchServiceClient` into `SearchIndexClient` for managing indexes, and `SearchIndexerClient` for managing indexers, both of which are now in `Azure.Search.Documents.Indexes`. ## 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 03328b769351..a713928bfc0f 100644 --- a/sdk/search/Azure.Search.Documents/README.md +++ b/sdk/search/Azure.Search.Documents/README.md @@ -89,7 +89,7 @@ string key = Environment.GetEnvironmentVariable("SEARCH_API_KEY"); // Create a client AzureKeyCredential credential = new AzureKeyCredential(key); -SearchServiceClient client = new SearchServiceClient(endpoint, credential); +SearchIndexClient client = new SearchIndexClient(endpoint, credential); ``` ### Send your first search query @@ -280,7 +280,7 @@ string key = Environment.GetEnvironmentVariable("SEARCH_API_KEY"); // Create a service client AzureKeyCredential credential = new AzureKeyCredential(key); -SearchServiceClient client = new SearchServiceClient(endpoint, credential); +SearchIndexClient client = new SearchIndexClient(endpoint, credential); // Create the index SearchIndex index = new SearchIndex("hotels") 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 a6edc6782b36..40317f16c024 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 @@ -65,69 +65,72 @@ public static partial class SearchFilter public static string Create(System.FormattableString filter) { throw null; } public static string Create(System.FormattableString filter, System.IFormatProvider formatProvider) { throw null; } } - public partial class SearchOptions : Azure.Search.Documents.SearchRequestOptions + public partial class SearchIndexClient { - public SearchOptions() { } - public SearchOptions(string continuationToken) { } - public System.Collections.Generic.IList Facets { get { throw null; } } - public string Filter { get { throw null; } set { } } - public System.Collections.Generic.IList HighlightFields { get { throw null; } } - public string HighlightPostTag { get { throw null; } set { } } - public string HighlightPreTag { get { throw null; } set { } } - public bool? IncludeTotalCount { get { throw null; } set { } } - public double? MinimumCoverage { get { throw null; } set { } } - public System.Collections.Generic.IList OrderBy { get { throw null; } } - public Azure.Search.Documents.Models.SearchQueryType? QueryType { get { throw null; } set { } } - public System.Collections.Generic.IList ScoringParameters { get { throw null; } } - public string ScoringProfile { get { throw null; } set { } } - public System.Collections.Generic.IList SearchFields { get { throw null; } } - public Azure.Search.Documents.Models.SearchMode? SearchMode { get { throw null; } set { } } - public System.Collections.Generic.IList Select { get { throw null; } } - public int? Size { get { throw null; } set { } } - public int? Skip { get { throw null; } set { } } - } - public partial class SearchRequestOptions - { - public SearchRequestOptions() { } - public System.Guid? ClientRequestId { get { throw null; } set { } } - } - public partial class SearchServiceClient - { - protected SearchServiceClient() { } - public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credential) { } - public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credential, Azure.Search.Documents.SearchClientOptions options) { } + protected SearchIndexClient() { } + public SearchIndexClient(System.Uri endpoint, Azure.AzureKeyCredential credential) { } + public SearchIndexClient(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.Response> AnalyzeText(string indexName, Azure.Search.Documents.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.Models.SearchIndex index, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response CreateOrUpdateIndex(Azure.Search.Documents.Indexes.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.Indexes.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 CreateOrUpdateSynonymMap(Azure.Search.Documents.Indexes.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.Indexes.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.Indexes.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.Indexes.Models.SynonymMap synonymMap, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response DeleteIndex(Azure.Search.Documents.Indexes.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.Indexes.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 DeleteSynonymMap(Azure.Search.Documents.Indexes.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.Indexes.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 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 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 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 partial class SearchIndexerClient + { + protected SearchIndexerClient() { } + public SearchIndexerClient(System.Uri endpoint, Azure.AzureKeyCredential credential) { } + public SearchIndexerClient(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.Response CreateDataSource(Azure.Search.Documents.Indexes.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.Indexes.Models.SearchIndexerDataSource dataSource, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response CreateIndexer(Azure.Search.Documents.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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.Indexes.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 DeleteIndexer(Azure.Search.Documents.Indexes.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.Indexes.Models.SearchIndexer indexer, bool onlyIfUnchanged = false, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -136,18 +139,12 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent 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.Indexes.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.Indexes.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.Indexes.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,32 +153,43 @@ 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 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 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 SearchOptions : Azure.Search.Documents.SearchRequestOptions + { + public SearchOptions() { } + public SearchOptions(string continuationToken) { } + public System.Collections.Generic.IList Facets { get { throw null; } } + public string Filter { get { throw null; } set { } } + public System.Collections.Generic.IList HighlightFields { get { throw null; } } + public string HighlightPostTag { get { throw null; } set { } } + public string HighlightPreTag { get { throw null; } set { } } + public bool? IncludeTotalCount { get { throw null; } set { } } + public double? MinimumCoverage { get { throw null; } set { } } + public System.Collections.Generic.IList OrderBy { get { throw null; } } + public Azure.Search.Documents.Models.SearchQueryType? QueryType { get { throw null; } set { } } + public System.Collections.Generic.IList ScoringParameters { get { throw null; } } + public string ScoringProfile { get { throw null; } set { } } + public System.Collections.Generic.IList SearchFields { get { throw null; } } + public Azure.Search.Documents.Models.SearchMode? SearchMode { get { throw null; } set { } } + public System.Collections.Generic.IList Select { get { throw null; } } + public int? Size { get { throw null; } set { } } + public int? Skip { get { throw null; } set { } } + } + public partial class SearchRequestOptions + { + public SearchRequestOptions() { } + public System.Guid? ClientRequestId { get { throw null; } set { } } + } public partial class SuggestOptions : Azure.Search.Documents.SearchRequestOptions { public SuggestOptions() { } diff --git a/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md b/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md index dd768955b9d9..31c8ac7bdef3 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample01a_HelloWorld.md @@ -15,7 +15,7 @@ AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create a new SearchServiceClient -SearchServiceClient search = new SearchServiceClient(endpoint, credential); +SearchIndexClient search = new SearchIndexClient(endpoint, credential); // Perform an operation Response stats = search.GetServiceStatistics(); diff --git a/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md b/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md index d576025ebf02..48cb37505f41 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample01b_HelloWorldAsync.md @@ -15,7 +15,7 @@ AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create a new SearchServiceClient -SearchServiceClient search = new SearchServiceClient(endpoint, credential); +SearchIndexClient search = new SearchIndexClient(endpoint, credential); // Perform an operation Response stats = await search.GetServiceStatisticsAsync(); diff --git a/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md b/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md index 2b62ef36064e..bb8d8cfb7c34 100644 --- a/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md +++ b/sdk/search/Azure.Search.Documents/samples/Sample02_Service.md @@ -17,7 +17,7 @@ reflect changes caused by recent indexing operations. Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); -SearchServiceClient search = new SearchServiceClient(endpoint, credential); +SearchIndexClient search = new SearchIndexClient(endpoint, credential); // Get and report the Search Service statistics Response stats = await search.GetServiceStatisticsAsync(); 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..097fef092377 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs @@ -0,0 +1,1354 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.Search.Documents.Indexes.Models; + +namespace Azure.Search.Documents +{ + /// + /// Azure Cognitive Search client that can be used to manage indexes on a Search service. + /// + public class SearchIndexClient + { + private readonly HttpPipeline _pipeline; + private readonly ClientDiagnostics _clientDiagnostics; + private readonly SearchClientOptions.ServiceVersion _version; + + private ServiceRestClient _serviceClient; + private IndexesRestClient _indexesClient; + private SynonymMapsRestClient _synonymMapsClient; + private string _serviceName; + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexClient() { } + + /// + /// 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. + /// + /// Required. The API key credential used to authenticate requests against the Search service. + /// You need to use an admin key to perform any operations on the SearchIndexClient. + /// See for more information about API keys in Azure Cognitive Search. + /// + /// Thrown when the or is null. + /// Thrown when the is not using HTTPS. + public SearchIndexClient(Uri endpoint, AzureKeyCredential credential) : + this(endpoint, credential, null) + { + } + + /// + /// 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. + /// + /// Required. The API key credential used to authenticate requests against the Search service. + /// You need to use an admin key to perform any operations on the SearchIndexClient. + /// See for more information about API keys in Azure Cognitive Search. + /// + /// Client configuration options for connecting to Azure Cognitive Search. + /// Thrown when the or is null. + /// Thrown when the is not using HTTPS. + public SearchIndexClient( + Uri endpoint, + AzureKeyCredential credential, + SearchClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + endpoint.AssertHttpsScheme(nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + + options ??= new SearchClientOptions(); + Endpoint = endpoint; + _clientDiagnostics = new ClientDiagnostics(options); + _pipeline = options.Build(credential); + _version = options.Version; + } + + /// + /// 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(); + + /// + /// Gets the generated to make requests. + /// + private ServiceRestClient ServiceClient => LazyInitializer.EnsureInitialized(ref _serviceClient, () => new ServiceRestClient( + _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 SynonymMapsRestClient SynonymMapsClient => LazyInitializer.EnsureInitialized(ref _synonymMapsClient, () => new SynonymMapsRestClient( + _clientDiagnostics, + _pipeline, + Endpoint.ToString(), + _version.ToVersionString()) + ); + + /// + /// Get 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 + /// . + /// + public virtual SearchClient GetSearchClient(string indexName) + { + Argument.AssertNotNullOrEmpty(indexName, nameof(indexName)); + return new SearchClient( + Endpoint, + indexName, + _pipeline, + _clientDiagnostics, + _version); + } + + #region Service operations + + /// + /// + /// Gets service level statistics for a Search service. + /// + /// + /// This operation returns the number and type of objects in your + /// service, the maximum allowed for each object type given the service + /// tier, actual and maximum storage, and other limits that vary by + /// tier. This request pulls information from the service so that you + /// don't have to look up or calculate service limits. + /// + /// + /// Statistics on document count and storage size are collected every + /// few minutes, not in real time. Therefore, the statistics returned + /// by this API may not reflect changes caused by recent indexing + /// operations. + /// + /// + /// Optional to customize the operation's behavior. + /// 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( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServiceStatistics)}"); + scope.Start(); + try + { + return ServiceClient.GetServiceStatistics( + options?.ClientRequestId, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// + /// Gets service level statistics for a Search service. + /// + /// + /// This operation returns the number and type of objects in your + /// service, the maximum allowed for each object type given the service + /// tier, actual and maximum storage, and other limits that vary by + /// tier. This request pulls information from the service so that you + /// don't have to look up or calculate service limits. + /// + /// + /// Statistics on document count and storage size are collected every + /// few minutes, not in real time. Therefore, the statistics returned + /// by this API may not reflect changes caused by recent indexing + /// operations. + /// + /// + /// Optional to customize the operation's behavior. + /// 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( + SearchRequestOptions options = null, + CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(GetServiceStatistics)}"); + scope.Start(); + try + { + return await ServiceClient.GetServiceStatisticsAsync( + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + 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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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) => DeleteIndex( + indexName, + null, + false, + options, + cancellationToken); + + /// + /// 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) => await DeleteIndexAsync( + indexName, + null, + false, + options, + cancellationToken) + .ConfigureAwait(false); + + /// + /// 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) => DeleteIndex( + index?.Name, + index?.ETag, + onlyIfUnchanged, + options, + cancellationToken); + + /// + /// 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) => await DeleteIndexAsync( + index?.Name, + index?.ETag, + onlyIfUnchanged, + options, + cancellationToken) + .ConfigureAwait(false); + + private Response DeleteIndex( + string indexName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return IndexesClient.Delete( + indexName, + options?.ClientRequestId, + onlyIfUnchanged ? etag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + private async Task DeleteIndexAsync( + string indexName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteIndex)}"); + scope.Start(); + try + { + return await IndexesClient.DeleteAsync( + indexName, + options?.ClientRequestId, + onlyIfUnchanged ? 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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{nameof(GetIndexStatistics)}"); + scope.Start(); + try + { + return await IndexesClient.GetStatisticsAsync( + indexName, + options?.ClientRequestId, + cancellationToken) + .ConfigureAwait(false); + } + 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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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) => DeleteSynonymMap( + synonymMapName, + null, + false, + options, + cancellationToken); + + /// + /// 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) => await DeleteSynonymMapAsync( + synonymMapName, + null, + false, + options, + cancellationToken) + .ConfigureAwait(false); + + /// + /// 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) => DeleteSynonymMap( + synonymMap?.Name, + synonymMap?.ETag, + onlyIfUnchanged, + options, + cancellationToken); + + /// + /// 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) => await DeleteSynonymMapAsync( + synonymMap?.Name, + synonymMap?.ETag, + onlyIfUnchanged, + options, + cancellationToken) + .ConfigureAwait(false); + + private Response DeleteSynonymMap( + string synonymMapName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return SynonymMapsClient.Delete( + synonymMapName, + options?.ClientRequestId, + onlyIfUnchanged ? etag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + private async Task DeleteSynonymMapAsync( + string synonymMapName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexClient)}.{nameof(DeleteSynonymMap)}"); + scope.Start(); + try + { + return await SynonymMapsClient.DeleteAsync( + synonymMapName, + options?.ClientRequestId, + onlyIfUnchanged ? 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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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(SearchIndexClient)}.{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/src/Indexes/SearchIndexerClient.cs b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs new file mode 100644 index 000000000000..8cc0b6d38446 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs @@ -0,0 +1,1722 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using System.Collections.Generic; +using System.Linq; +using Azure.Search.Documents.Indexes.Models; + +namespace Azure.Search.Documents +{ + /// + /// Azure Cognitive Search client that can be used to manage and query + /// indexes and documents, as well as manage other resources, on a Search + /// Service. + /// + public class SearchIndexerClient + { + private readonly HttpPipeline _pipeline; + private readonly ClientDiagnostics _clientDiagnostics; + private readonly SearchClientOptions.ServiceVersion _version; + + private DataSourcesRestClient _dataSourcesClient; + private IndexersRestClient _indexersClient; + private SkillsetsRestClient _skillsetsClient; + private string _serviceName; + + + /// + /// Initializes a new instance of the class for mocking. + /// + protected SearchIndexerClient() { } + + /// + /// 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. + /// + /// Required. The API key credential used to authenticate requests against the Search service. + /// You need to use an admin key to perform any operations on the SearchIndexerClient. + /// See for more information about API keys in Azure Cognitive Search. + /// + /// Thrown when the or is null. + /// Thrown when the is not using HTTPS. + public SearchIndexerClient(Uri endpoint, AzureKeyCredential credential) : + this(endpoint, credential, null) + { + } + + /// + /// 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. + /// + /// Required. The API key credential used to authenticate requests against the Search service. + /// You need to use an admin key to perform any operations on the SearchIndexerClient. + /// See for more information about API keys in Azure Cognitive Search. + /// + /// Client configuration options for connecting to Azure Cognitive Search. + /// Thrown when the or is null. + /// Thrown when the is not using HTTPS. + public SearchIndexerClient( + Uri endpoint, + AzureKeyCredential credential, + SearchClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + endpoint.AssertHttpsScheme(nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + + options ??= new SearchClientOptions(); + Endpoint = endpoint; + _clientDiagnostics = new ClientDiagnostics(options); + _pipeline = options.Build(credential); + _version = options.Version; + } + + /// + /// 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(); + + /// + /// 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 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()) + ); + + #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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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) => DeleteDataSource( + dataSourceName, + null, + false, + options, + cancellationToken); + + /// + /// 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) => await DeleteDataSourceAsync( + dataSourceName, + null, + false, + options, + cancellationToken) + .ConfigureAwait(false); + + /// + /// 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) => DeleteDataSource( + dataSource?.Name, + dataSource?.ETag, + onlyIfUnchanged, + options, + cancellationToken); + + /// + /// 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) => await DeleteDataSourceAsync( + dataSource?.Name, + dataSource?.ETag, + onlyIfUnchanged, + options, + cancellationToken) + .ConfigureAwait(false); + + private Response DeleteDataSource( + string dataSourceName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return DataSourcesClient.Delete( + dataSourceName, + options?.ClientRequestId, + onlyIfUnchanged ? etag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + private async Task DeleteDataSourceAsync( + string dataSourceName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteDataSource)}"); + scope.Start(); + try + { + return await DataSourcesClient.DeleteAsync( + dataSourceName, + options?.ClientRequestId, + onlyIfUnchanged ? 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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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 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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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) => DeleteIndexer( + indexerName, + null, + false, + options, + cancellationToken); + + /// + /// 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) => await DeleteIndexerAsync( + indexerName, + null, + false, + options, + cancellationToken) + .ConfigureAwait(false); + + /// + /// 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) => DeleteIndexer( + indexer?.Name, + indexer?.ETag, + onlyIfUnchanged, + options, + cancellationToken); + + /// + /// 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) => await DeleteIndexerAsync( + indexer?.Name, + indexer?.ETag, + onlyIfUnchanged, + options, + cancellationToken) + .ConfigureAwait(false); + + private Response DeleteIndexer( + string indexerName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return IndexersClient.Delete( + indexerName, + options?.ClientRequestId, + onlyIfUnchanged ? etag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + private async Task DeleteIndexerAsync( + string indexerName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteIndexer)}"); + scope.Start(); + try + { + return await IndexersClient.DeleteAsync( + indexerName, + options?.ClientRequestId, + onlyIfUnchanged ? 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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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) => DeleteSkillset( + skillsetName, + null, + false, + options, + cancellationToken); + + /// + /// 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) => await DeleteSkillsetAsync( + skillsetName, + null, + false, + options, + cancellationToken) + .ConfigureAwait(false); + + /// + /// 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) => DeleteSkillset( + skillset?.Name, + skillset?.ETag, + onlyIfUnchanged, + options, + cancellationToken); + + /// + /// 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) => await DeleteSkillsetAsync( + skillset?.Name, + skillset?.ETag, + onlyIfUnchanged, + options, + cancellationToken) + .ConfigureAwait(false); + + private Response DeleteSkillset( + string skillsetName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return SkillsetsClient.Delete( + skillsetName, + options?.ClientRequestId, + onlyIfUnchanged ? etag?.ToString() : null, + null, + cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + private async Task DeleteSkillsetAsync( + string skillsetName, + ETag? etag, + bool onlyIfUnchanged, + SearchRequestOptions options, + CancellationToken cancellationToken) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SearchIndexerClient)}.{nameof(DeleteSkillset)}"); + scope.Start(); + try + { + return await SkillsetsClient.DeleteAsync( + skillsetName, + options?.ClientRequestId, + onlyIfUnchanged ? 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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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(SearchIndexerClient)}.{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 + } +} diff --git a/sdk/search/Azure.Search.Documents/src/SearchClient.cs b/sdk/search/Azure.Search.Documents/src/SearchClient.cs index 9304ca281e88..5d10807f3829 100644 --- a/sdk/search/Azure.Search.Documents/src/SearchClient.cs +++ b/sdk/search/Azure.Search.Documents/src/SearchClient.cs @@ -171,7 +171,7 @@ public SearchClient( /// /// Initializes a new instance of the SearchClient class from a - /// . + /// . /// /// /// Required. The URI endpoint of the Search Service. This is likely diff --git a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs b/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs deleted file mode 100644 index 6c43f8a027f8..000000000000 --- a/sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs +++ /dev/null @@ -1,3014 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Threading; -using System.Threading.Tasks; -using Azure.Search.Documents.Models; -using Azure.Core; -using Azure.Core.Pipeline; -using System.Collections.Generic; -using System.Linq; -using Azure.Search.Documents.Indexes.Models; - -namespace Azure.Search.Documents -{ - /// - /// Azure Cognitive Search client that can be used to manage and query - /// indexes and documents, as well as manage other resources, on a Search - /// Service. - /// - 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 - /// to be similar to "https://{search_service}.search.windows.net". - /// - public virtual Uri Endpoint { get; } - - /// - /// The name of the Search service, lazily obtained from the - /// . - /// - private string _serviceName = null; - - /// - /// Gets the name of the Search service. - /// - public virtual string ServiceName => - _serviceName ??= Endpoint.GetSearchServiceName(); - - /// - /// Gets the authenticated used for sending - /// requests to the Search service. - /// - private HttpPipeline Pipeline { get; } - - /// - /// Gets the used - /// to provide tracing support for the client library. - /// - private ClientDiagnostics ClientDiagnostics { get; } - - /// - /// Gets the REST API version of the Search service to use when making - /// requests. - /// - private SearchClientOptions.ServiceVersion Version { get; } - - /// - /// Gets the generated to make requests. - /// - private ServiceRestClient ServiceClient => LazyInitializer.EnsureInitialized(ref _serviceClient, () => new ServiceRestClient( - ClientDiagnostics, - Pipeline, - Endpoint.ToString(), - 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. - /// - protected SearchServiceClient() { } - - /// - /// Initializes a new instance of the SearchServiceClient 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. - /// - /// Required. The API key credential used to authenticate requests against the Search service. - /// You need to use an admin key to perform any operations on the SearchServiceClient. - /// See for more information about API keys in Azure Cognitive Search. - /// - /// Thrown when the or is null. - /// Thrown when the is not using HTTPS. - public SearchServiceClient(Uri endpoint, AzureKeyCredential credential) : - this(endpoint, credential, null) - { - } - - /// - /// Initializes a new instance of the SearchServiceClient 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. - /// - /// Required. The API key credential used to authenticate requests against the Search service. - /// You need to use an admin key to perform any operations on the SearchServiceClient. - /// See for more information about API keys in Azure Cognitive Search. - /// - /// Client configuration options for connecting to Azure Cognitive Search. - /// Thrown when the or is null. - /// Thrown when the is not using HTTPS. - public SearchServiceClient( - Uri endpoint, - AzureKeyCredential credential, - SearchClientOptions options) - { - Argument.AssertNotNull(endpoint, nameof(endpoint)); - endpoint.AssertHttpsScheme(nameof(endpoint)); - Argument.AssertNotNull(credential, nameof(credential)); - - options ??= new SearchClientOptions(); - Endpoint = endpoint; - ClientDiagnostics = new ClientDiagnostics(options); - Pipeline = options.Build(credential); - Version = options.Version; - } - - /// - /// Get 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 - /// . - /// - public virtual SearchClient GetSearchClient(string indexName) - { - Argument.AssertNotNullOrEmpty(indexName, nameof(indexName)); - return new SearchClient( - Endpoint, - indexName, - Pipeline, - ClientDiagnostics, - Version); - } - - #region Service operations - - /// - /// - /// Gets service level statistics for a Search service. - /// - /// - /// This operation returns the number and type of objects in your - /// service, the maximum allowed for each object type given the service - /// tier, actual and maximum storage, and other limits that vary by - /// tier. This request pulls information from the service so that you - /// don't have to look up or calculate service limits. - /// - /// - /// Statistics on document count and storage size are collected every - /// few minutes, not in real time. Therefore, the statistics returned - /// by this API may not reflect changes caused by recent indexing - /// operations. - /// - /// - /// Optional to customize the operation's behavior. - /// 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( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetServiceStatistics)}"); - scope.Start(); - try - { - return ServiceClient.GetServiceStatistics( - options?.ClientRequestId, - cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// - /// Gets service level statistics for a Search service. - /// - /// - /// This operation returns the number and type of objects in your - /// service, the maximum allowed for each object type given the service - /// tier, actual and maximum storage, and other limits that vary by - /// tier. This request pulls information from the service so that you - /// don't have to look up or calculate service limits. - /// - /// - /// Statistics on document count and storage size are collected every - /// few minutes, not in real time. Therefore, the statistics returned - /// by this API may not reflect changes caused by recent indexing - /// operations. - /// - /// - /// Optional to customize the operation's behavior. - /// 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( - SearchRequestOptions options = null, - CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(SearchServiceClient)}.{nameof(GetServiceStatistics)}"); - scope.Start(); - try - { - return await ServiceClient.GetServiceStatisticsAsync( - options?.ClientRequestId, - cancellationToken) - .ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - 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 514f1de4026c..1ff972f06d41 100644 --- a/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs +++ b/sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs @@ -34,8 +34,8 @@ public async Task CreateClient() Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create a new SearchServiceClient - SearchServiceClient search = new SearchServiceClient(endpoint, credential); - /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); + SearchIndexClient search = new SearchIndexClient(endpoint, credential); + /*@@*/ search = InstrumentClient(new SearchIndexClient(endpoint, credential, GetSearchClientOptions())); // Perform an operation Response stats = search.GetServiceStatistics(); @@ -60,8 +60,8 @@ public async Task CreateClientAsync() Environment.GetEnvironmentVariable("SEARCH_API_KEY")); // Create a new SearchServiceClient - SearchServiceClient search = new SearchServiceClient(endpoint, credential); - /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); + SearchIndexClient search = new SearchIndexClient(endpoint, credential); + /*@@*/ search = InstrumentClient(new SearchIndexClient(endpoint, credential, GetSearchClientOptions())); // Perform an operation Response stats = await search.GetServiceStatisticsAsync(); @@ -139,8 +139,8 @@ public async Task GetStatisticsAsync() Uri endpoint = new Uri(Environment.GetEnvironmentVariable("SEARCH_ENDPOINT")); AzureKeyCredential credential = new AzureKeyCredential( Environment.GetEnvironmentVariable("SEARCH_API_KEY")); - SearchServiceClient search = new SearchServiceClient(endpoint, credential); - /*@@*/ search = InstrumentClient(new SearchServiceClient(endpoint, credential, GetSearchClientOptions())); + SearchIndexClient search = new SearchIndexClient(endpoint, credential); + /*@@*/ search = InstrumentClient(new SearchIndexClient(endpoint, credential, GetSearchClientOptions())); // Get and report the Search Service statistics Response stats = await search.GetServiceStatisticsAsync(); diff --git a/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs b/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs index c8cd5f914b35..ba8f65aa0423 100644 --- a/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs +++ b/sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs @@ -41,7 +41,7 @@ public async Task Authenticate() // Create a client AzureKeyCredential credential = new AzureKeyCredential(key); - SearchServiceClient client = new SearchServiceClient(endpoint, credential); + SearchIndexClient client = new SearchIndexClient(endpoint, credential); #endregion Snippet:Azure_Search_Tests_Samples_Readme_Authenticate } @@ -193,8 +193,8 @@ public async Task CreateIndex() // Create a service client AzureKeyCredential credential = new AzureKeyCredential(key); - SearchServiceClient client = new SearchServiceClient(endpoint, credential); - /*@@*/ client = resources.GetServiceClient(); + SearchIndexClient client = new SearchIndexClient(endpoint, credential); + /*@@*/ client = resources.GetIndexClient(); // Create the index //@@SearchIndex index = new SearchIndex("hotels") diff --git a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs similarity index 69% rename from sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs rename to sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs index 6b293e97dc8e..c35122113ec5 100644 --- a/sdk/search/Azure.Search.Documents/tests/SearchServiceClientTests.cs +++ b/sdk/search/Azure.Search.Documents/tests/SearchIndexClientTests.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Net; -using System.Text; -using System.Threading; using System.Threading.Tasks; using Azure.Core; using Azure.Core.Pipeline; @@ -15,9 +13,9 @@ namespace Azure.Search.Documents.Tests { - public class SearchServiceClientTests : SearchTestBase + public class SearchIndexClientTests : SearchTestBase { - public SearchServiceClientTests(bool async, SearchClientOptions.ServiceVersion serviceVersion) + public SearchIndexClientTests(bool async, SearchClientOptions.ServiceVersion serviceVersion) : base(async, serviceVersion, null /* RecordedTestMode.Record /* to re-record */) { } @@ -27,14 +25,14 @@ public void Constructor() { var serviceName = "my-svc-name"; var endpoint = new Uri($"https://{serviceName}.search.windows.net"); - var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")); + var service = new SearchIndexClient(endpoint, new AzureKeyCredential("fake")); Assert.NotNull(service); Assert.AreEqual(endpoint, service.Endpoint); Assert.AreEqual(serviceName, service.ServiceName); - Assert.Throws(() => new SearchServiceClient(null, new AzureKeyCredential("fake"))); - Assert.Throws(() => new SearchServiceClient(endpoint, null)); - Assert.Throws(() => new SearchServiceClient(new Uri("http://bing.com"), null)); + Assert.Throws(() => new SearchIndexClient(null, new AzureKeyCredential("fake"))); + Assert.Throws(() => new SearchIndexClient(endpoint, null)); + Assert.Throws(() => new SearchIndexClient(new Uri("http://bing.com"), null)); } [Test] @@ -42,7 +40,7 @@ public void GetSearchClient() { var serviceName = "my-svc-name"; var endpoint = new Uri($"https://{serviceName}.search.windows.net"); - var service = new SearchServiceClient(endpoint, new AzureKeyCredential("fake")); + var service = new SearchIndexClient(endpoint, new AzureKeyCredential("fake")); var indexName = "my-index-name"; var client = service.GetSearchClient(indexName); @@ -71,7 +69,7 @@ public async Task IndexSharesPipeline() SearchClientOptions options = new SearchClientOptions(ServiceVersion); options.AddPolicy(custom, HttpPipelinePosition.PerCall); - SearchServiceClient serviceClient = resources.GetServiceClient(options); + SearchIndexClient serviceClient = resources.GetIndexClient(options); SearchClient client = serviceClient.GetSearchClient(resources.IndexName); _ = await client.GetDocumentCountAsync(); @@ -83,7 +81,7 @@ public async Task IndexSharesPipeline() public async Task ClientRequestIdRountrips() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); Guid id = Recording.Random.NewGuid(); Response response = await client.GetServiceStatisticsAsync( @@ -123,7 +121,7 @@ public async Task GetServiceStatistics() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); Response response = await client.GetServiceStatisticsAsync(); Assert.AreEqual(200, response.GetRawResponse().Status); Assert.IsNotNull(response.Value); @@ -144,7 +142,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 SearchIndexClient(endpoint, new AzureKeyCredential("fake")); ArgumentException ex = Assert.Throws(() => service.CreateIndex(null)); Assert.AreEqual("index", ex.ParamName); @@ -161,7 +159,7 @@ public async Task CreateIndex() resources.IndexName = Recording.Random.GetName(8); SearchIndex expectedIndex = SearchResources.GetHotelIndex(resources.IndexName); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); SearchIndex actualIndex = await client.CreateIndexAsync(expectedIndex); Assert.AreEqual(expectedIndex.Name, actualIndex.Name); @@ -180,7 +178,7 @@ public async Task UpdateIndex() resources.IndexName = Recording.Random.GetName(); SearchIndex initialIndex = SearchResources.GetHotelIndex(resources.IndexName); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); SearchIndex createdIndex = await client.CreateIndexAsync(initialIndex); string analyzerName = "asciiTags"; @@ -230,7 +228,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 SearchIndexClient(endpoint, new AzureKeyCredential("fake")); ArgumentException ex = Assert.Throws(() => service.GetIndex(null)); Assert.AreEqual("indexName", ex.ParamName); @@ -244,7 +242,7 @@ public async Task GetIndex() { await using SearchResources resources = await SearchResources.CreateWithHotelsIndexAsync(this); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); SearchIndex index = await client.GetIndexAsync(resources.IndexName); // TODO: Replace with comparison of actual SearchIndex once test framework uses Azure.Search.Documents instead. @@ -257,7 +255,7 @@ public async Task GetIndexes() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); bool found = false; await foreach (SearchIndex index in client.GetIndexesAsync()) @@ -274,7 +272,7 @@ public async Task GetIndexesNextPageThrows() { await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); AsyncPageable pageable = client.GetIndexesAsync(); string continuationToken = Recording.GenerateId(); @@ -284,60 +282,6 @@ public async Task GetIndexesNextPageThrows() Assert.ThrowsAsync(async () => await e.MoveNextAsync()); } - [Test] - public async Task CreateAzureBlobIndexer() - { - await using SearchResources resources = await SearchResources.CreateWithBlobStorageAndIndexAsync(this); - - SearchServiceClient serviceClient = resources.GetServiceClient(); - - // Create the Azure Blob data source and indexer. - SearchIndexerDataSource dataSource = new SearchIndexerDataSource( - Recording.Random.GetName(), - SearchIndexerDataSourceType.AzureBlob, - resources.StorageAccountConnectionString, - new SearchIndexerDataContainer(resources.BlobContainerName)); - - SearchIndexerDataSource actualSource = await serviceClient.CreateDataSourceAsync( - dataSource, - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); - - SearchIndexer indexer = new SearchIndexer( - Recording.Random.GetName(), - dataSource.Name, - resources.IndexName); - - SearchIndexer actualIndexer = await serviceClient.CreateIndexerAsync( - indexer, - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); - - // Update the indexer. - actualIndexer.Description = "Updated description"; - await serviceClient.CreateOrUpdateIndexerAsync( - actualIndexer, - onlyIfUnchanged: true, - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); - - await WaitForIndexingAsync(serviceClient, actualIndexer.Name); - - // Run the indexer. - await serviceClient.RunIndexerAsync( - indexer.Name, - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); - - await WaitForIndexingAsync(serviceClient, actualIndexer.Name); - - // Query the index. - SearchClient client = serviceClient.GetSearchClient( - resources.IndexName); - - long count = await client.GetDocumentCountAsync( - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); - - // This should be equal, but sometimes reports double despite logs showing no shared resources. - Assert.That(count, Is.GreaterThanOrEqualTo(SearchResources.TestDocuments.Length)); - } - [Test] public async Task CrudSynonymMaps() { @@ -345,7 +289,7 @@ public async Task CrudSynonymMaps() string synonymMapName = Recording.Random.GetName(); - SearchServiceClient client = resources.GetServiceClient(); + SearchIndexClient client = resources.GetIndexClient(); SynonymMap createdMap = await client.CreateSynonymMapAsync(new SynonymMap(synonymMapName, "msft=>Microsoft")); Assert.AreEqual(synonymMapName, createdMap.Name); @@ -383,54 +327,5 @@ await client.CreateOrUpdateSynonymMapAsync( await client.DeleteSynonymMapAsync(updatedMap, onlyIfUnchanged: true); } - - /// - /// Waits for an indexer to complete up to the given . - /// - /// The to use for requests. - /// The name of the to check. - /// The amount of time before being canceled. The default is 1 minute. - /// A to await. - private async Task WaitForIndexingAsync( - SearchServiceClient client, - string indexerName, - TimeSpan? timeout = null) - { - TimeSpan delay = TimeSpan.FromSeconds(10); - timeout ??= TimeSpan.FromMinutes(5); - - using CancellationTokenSource cts = new CancellationTokenSource(timeout.Value); - - while (true) - { - await DelayAsync(delay, cancellationToken: cts.Token); - - SearchIndexerStatus status = await client.GetIndexerStatusAsync( - indexerName, - new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }, - cts.Token); - - if (status.Status == IndexerStatus.Running && - status.LastResult?.Status == IndexerExecutionStatus.Success) - { - return; - } - else if (status.Status == IndexerStatus.Error && status.LastResult is IndexerExecutionResult lastResult) - { - StringBuilder sb = new StringBuilder(); - sb.AppendLine($"Error: {lastResult.ErrorMessage}"); - - if (lastResult.Errors?.Count > 0) - { - foreach (SearchIndexerError error in lastResult.Errors) - { - sb.AppendLine($" ---> {error.ErrorMessage}"); - } - } - - Assert.Fail(sb.ToString()); - } - } - } } } diff --git a/sdk/search/Azure.Search.Documents/tests/SearchIndexerClientTests.cs b/sdk/search/Azure.Search.Documents/tests/SearchIndexerClientTests.cs new file mode 100644 index 000000000000..c80b0dba866c --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SearchIndexerClientTests.cs @@ -0,0 +1,178 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.Search.Documents.Indexes.Models; +using NUnit.Framework; + +namespace Azure.Search.Documents.Tests +{ + public class SearchIndexerClientTests : SearchTestBase + { + public SearchIndexerClientTests(bool async, SearchClientOptions.ServiceVersion serviceVersion) + : base(async, serviceVersion, null /* RecordedTestMode.Record /* to re-record */) + { + } + + [Test] + public void Constructor() + { + var serviceName = "my-svc-name"; + var endpoint = new Uri($"https://{serviceName}.search.windows.net"); + var service = new SearchIndexerClient(endpoint, new AzureKeyCredential("fake")); + Assert.NotNull(service); + Assert.AreEqual(endpoint, service.Endpoint); + Assert.AreEqual(serviceName, service.ServiceName); + + Assert.Throws(() => new SearchIndexerClient(null, new AzureKeyCredential("fake"))); + Assert.Throws(() => new SearchIndexerClient(endpoint, null)); + Assert.Throws(() => new SearchIndexerClient(new Uri("http://bing.com"), null)); + } + + [Test] + public async Task ClientRequestIdRountrips() + { + await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this); + SearchIndexerClient client = resources.GetIndexerClient(); + Guid id = Recording.Random.NewGuid(); + Response> response = + await client.GetIndexersAsync( + new SearchRequestOptions { ClientRequestId = id }); + + Assert.AreEqual(id.ToString(), response.GetRawResponse().ClientRequestId); + } + + [Test] + public void DiagnosticsAreUnique() + { + // Make sure we're not repeating Header/Query names already defined + // in the base ClientOptions + SearchClientOptions options = new SearchClientOptions(); + Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedHeaderNames)); + Assert.IsEmpty(GetDuplicates(options.Diagnostics.LoggedQueryParameters)); + + // CollectionAssert.Unique doesn't give you the duplicate values + // which is less helpful than it could be + static string GetDuplicates(IEnumerable values) + { + List duplicates = new List(); + HashSet unique = new HashSet(); + foreach (string value in values) + { + if (!unique.Add(value)) + { + duplicates.Add(value); + } + } + return string.Join(", ", duplicates); + } + } + + [Test] + public async Task CreateAzureBlobIndexer() + { + await using SearchResources resources = await SearchResources.CreateWithBlobStorageAndIndexAsync(this); + + SearchIndexerClient serviceClient = resources.GetIndexerClient(); + + // Create the Azure Blob data source and indexer. + SearchIndexerDataSource dataSource = new SearchIndexerDataSource( + Recording.Random.GetName(), + SearchIndexerDataSourceType.AzureBlob, + resources.StorageAccountConnectionString, + new SearchIndexerDataContainer(resources.BlobContainerName)); + + SearchIndexerDataSource actualSource = await serviceClient.CreateDataSourceAsync( + dataSource, + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); + + SearchIndexer indexer = new SearchIndexer( + Recording.Random.GetName(), + dataSource.Name, + resources.IndexName); + + SearchIndexer actualIndexer = await serviceClient.CreateIndexerAsync( + indexer, + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); + + // Update the indexer. + actualIndexer.Description = "Updated description"; + await serviceClient.CreateOrUpdateIndexerAsync( + actualIndexer, + onlyIfUnchanged: true, + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); + + await WaitForIndexingAsync(serviceClient, actualIndexer.Name); + + // Run the indexer. + await serviceClient.RunIndexerAsync( + indexer.Name, + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); + + await WaitForIndexingAsync(serviceClient, actualIndexer.Name); + + // Query the index. + SearchClient client = resources.GetSearchClient(); + + long count = await client.GetDocumentCountAsync( + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }); + + // This should be equal, but sometimes reports double despite logs showing no shared resources. + Assert.That(count, Is.GreaterThanOrEqualTo(SearchResources.TestDocuments.Length)); + } + + /// + /// Waits for an indexer to complete up to the given . + /// + /// The to use for requests. + /// The name of the to check. + /// The amount of time before being canceled. The default is 1 minute. + /// A to await. + private async Task WaitForIndexingAsync( + SearchIndexerClient client, + string indexerName, + TimeSpan? timeout = null) + { + TimeSpan delay = TimeSpan.FromSeconds(10); + timeout ??= TimeSpan.FromMinutes(5); + + using CancellationTokenSource cts = new CancellationTokenSource(timeout.Value); + + while (true) + { + await DelayAsync(delay, cancellationToken: cts.Token); + + SearchIndexerStatus status = await client.GetIndexerStatusAsync( + indexerName, + new SearchRequestOptions { ClientRequestId = Recording.Random.NewGuid() }, + cts.Token); + + if (status.Status == IndexerStatus.Running && + status.LastResult?.Status == IndexerExecutionStatus.Success) + { + return; + } + else if (status.Status == IndexerStatus.Error && status.LastResult is IndexerExecutionResult lastResult) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine($"Error: {lastResult.ErrorMessage}"); + + if (lastResult.Errors?.Count > 0) + { + foreach (SearchIndexerError error in lastResult.Errors) + { + sb.AppendLine($" ---> {error.ErrorMessage}"); + } + } + + Assert.Fail(sb.ToString()); + } + } + } + } +} diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ClientRequestIdRountrips.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ClientRequestIdRountrips.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ClientRequestIdRountrips.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ClientRequestIdRountrips.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ClientRequestIdRountripsAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ClientRequestIdRountripsAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ClientRequestIdRountripsAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ClientRequestIdRountripsAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/Constructor.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/Constructor.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/Constructor.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/Constructor.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ConstructorAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ConstructorAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/ConstructorAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/ConstructorAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndex.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndex.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndex.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndex.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexParameterValidation.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexParameterValidation.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexParameterValidation.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexParameterValidation.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexParameterValidationAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexParameterValidationAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateIndexParameterValidationAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CreateIndexParameterValidationAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CrudSynonymMaps.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CrudSynonymMaps.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CrudSynonymMaps.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CrudSynonymMaps.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CrudSynonymMapsAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CrudSynonymMapsAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CrudSynonymMapsAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/CrudSynonymMapsAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/DiagnosticsAreUnique.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/DiagnosticsAreUnique.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/DiagnosticsAreUnique.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/DiagnosticsAreUnique.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/DiagnosticsAreUniqueAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/DiagnosticsAreUniqueAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/DiagnosticsAreUniqueAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/DiagnosticsAreUniqueAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndex.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndex.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndex.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndex.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexParameterValidation.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexParameterValidation.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexParameterValidation.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexParameterValidation.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexParameterValidationAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexParameterValidationAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexParameterValidationAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexParameterValidationAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexes.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexes.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexes.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexes.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexesAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexesAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexesAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexesAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexesNextPageThrowsAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexesNextPageThrowsAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetIndexesNextPageThrowsAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetIndexesNextPageThrowsAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetSearchClient.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetSearchClient.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetSearchClient.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetSearchClient.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetSearchClientAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetSearchClientAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetSearchClientAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetSearchClientAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetServiceStatistics.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetServiceStatistics.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetServiceStatistics.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetServiceStatistics.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetServiceStatisticsAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetServiceStatisticsAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/GetServiceStatisticsAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/GetServiceStatisticsAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/IndexSharesPipeline.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/IndexSharesPipeline.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/IndexSharesPipeline.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/IndexSharesPipeline.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/IndexSharesPipelineAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/IndexSharesPipelineAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/IndexSharesPipelineAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/IndexSharesPipelineAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/SearchApiKeyCredential.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/SearchApiKeyCredential.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/SearchApiKeyCredential.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/SearchApiKeyCredential.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/SearchApiKeyCredentialAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/SearchApiKeyCredentialAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/SearchApiKeyCredentialAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/SearchApiKeyCredentialAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/UpdateIndex.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/UpdateIndex.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/UpdateIndex.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/UpdateIndex.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/UpdateIndexAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/UpdateIndexAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/UpdateIndexAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexClientTests/UpdateIndexAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountrips.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountrips.json new file mode 100644 index 000000000000..77eafe110540 --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountrips.json @@ -0,0 +1,46 @@ +{ + "Entries": [ + { + "RequestUri": "https://azs-net-heathsrchtst.search.windows.net/indexers?$select=%2A\u0026api-version=2019-05-06-Preview", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json; odata.metadata=minimal", + "api-key": "Sanitized", + "traceparent": "00-bdcdf5e6f7df4c40a641e3a76d252fac-d5dd5da48e18434b-00", + "User-Agent": [ + "azsdk-net-Search.Documents/1.0.0-dev.20200519.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "68966ae8-323d-1ca5-12f0-8e47cdae07d4", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "client-request-id": "68966ae8-323d-1ca5-12f0-8e47cdae07d4", + "Content-Length": "101", + "Content-Type": "application/json; odata.metadata=minimal", + "Date": "Tue, 19 May 2020 23:41:13 GMT", + "elapsed-time": "18", + "Expires": "-1", + "OData-Version": "4.0", + "Pragma": "no-cache", + "Preference-Applied": "odata.include-annotations=\u0022*\u0022", + "request-id": "68966ae8-323d-1ca5-12f0-8e47cdae07d4", + "Strict-Transport-Security": "max-age=15724800; includeSubDomains", + "x-ms-client-request-id": "68966ae8-323d-1ca5-12f0-8e47cdae07d4" + }, + "ResponseBody": { + "@odata.context": "https://azs-net-heathsrchtst.search.windows.net/$metadata#indexers(*)", + "value": [] + } + } + ], + "Variables": { + "RandomSeed": "1622410931", + "SearchIndexName": "iakmaxlf", + "SEARCH_ADMIN_API_KEY": "Sanitized", + "SEARCH_SERVICE_NAME": "azs-net-heathsrchtst" + } +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountripsAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountripsAsync.json new file mode 100644 index 000000000000..d3ef2d69ea6d --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ClientRequestIdRountripsAsync.json @@ -0,0 +1,46 @@ +{ + "Entries": [ + { + "RequestUri": "https://azs-net-heathsrchtst.search.windows.net/indexers?$select=%2A\u0026api-version=2019-05-06-Preview", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json; odata.metadata=minimal", + "api-key": "Sanitized", + "traceparent": "00-64a2166851960444b581875fa570defa-999e7943e4382642-00", + "User-Agent": [ + "azsdk-net-Search.Documents/1.0.0-dev.20200519.1", + "(.NET Core 4.6.28801.04; Microsoft Windows 10.0.19041 )" + ], + "x-ms-client-request-id": "f32f3b11-7b2c-df0f-c417-672b2950b49a", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "client-request-id": "f32f3b11-7b2c-df0f-c417-672b2950b49a", + "Content-Length": "101", + "Content-Type": "application/json; odata.metadata=minimal", + "Date": "Tue, 19 May 2020 23:41:13 GMT", + "elapsed-time": "4", + "Expires": "-1", + "OData-Version": "4.0", + "Pragma": "no-cache", + "Preference-Applied": "odata.include-annotations=\u0022*\u0022", + "request-id": "f32f3b11-7b2c-df0f-c417-672b2950b49a", + "Strict-Transport-Security": "max-age=15724800; includeSubDomains", + "x-ms-client-request-id": "f32f3b11-7b2c-df0f-c417-672b2950b49a" + }, + "ResponseBody": { + "@odata.context": "https://azs-net-heathsrchtst.search.windows.net/$metadata#indexers(*)", + "value": [] + } + } + ], + "Variables": { + "RandomSeed": "1481307319", + "SearchIndexName": "iakmaxlf", + "SEARCH_ADMIN_API_KEY": "Sanitized", + "SEARCH_SERVICE_NAME": "azs-net-heathsrchtst" + } +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/Constructor.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/Constructor.json new file mode 100644 index 000000000000..20e5015d169f --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/Constructor.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ConstructorAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ConstructorAsync.json new file mode 100644 index 000000000000..20e5015d169f --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/ConstructorAsync.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateAzureBlobIndexer.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/CreateAzureBlobIndexer.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateAzureBlobIndexer.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/CreateAzureBlobIndexer.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateAzureBlobIndexerAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/CreateAzureBlobIndexerAsync.json similarity index 100% rename from sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchServiceClientTests/CreateAzureBlobIndexerAsync.json rename to sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/CreateAzureBlobIndexerAsync.json diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUnique.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUnique.json new file mode 100644 index 000000000000..20e5015d169f --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUnique.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUniqueAsync.json b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUniqueAsync.json new file mode 100644 index 000000000000..20e5015d169f --- /dev/null +++ b/sdk/search/Azure.Search.Documents/tests/SessionRecords/SearchIndexerClientTests/DiagnosticsAreUniqueAsync.json @@ -0,0 +1,4 @@ +{ + "Entries": [], + "Variables": {} +} \ No newline at end of file diff --git a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs index 2c894bc0aea8..6c978992f8de 100644 --- a/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs +++ b/sdk/search/Azure.Search.Documents/tests/Utilities/SearchResources.cs @@ -225,34 +225,46 @@ public static async Task GetSharedHotelsIndexAsync(SearchTestBa #region Get Clients /// - /// Get a SearchServiceClient to use for testing. + /// Get a to use for testing. /// /// Optional client options. - /// A SearchServiceClient instance. - public SearchServiceClient GetServiceClient(SearchClientOptions options = null) => + /// A instance. + public SearchIndexClient GetIndexClient(SearchClientOptions options = null) => TestFixture.InstrumentClient( - new SearchServiceClient( + new SearchIndexClient( Endpoint, new AzureKeyCredential(PrimaryApiKey), TestFixture.GetSearchClientOptions(options))); /// - /// Get a SearchClient to use for testing with an Admin API key. + /// Get a to use for testing. /// /// Optional client options. - /// A SearchClient instance. + /// A instance. + public SearchIndexerClient GetIndexerClient(SearchClientOptions options = null) => + TestFixture.InstrumentClient( + new SearchIndexerClient( + Endpoint, + new AzureKeyCredential(PrimaryApiKey), + TestFixture.GetSearchClientOptions(options))); + + /// + /// Get a to use for testing with an Admin API key. + /// + /// Optional client options. + /// A instance. public SearchClient GetSearchClient(SearchClientOptions options = null) { Assert.IsNotNull(IndexName, "No index was created for these TestResources!"); return TestFixture.InstrumentClient( - GetServiceClient(options).GetSearchClient(IndexName)); + GetIndexClient(options).GetSearchClient(IndexName)); } /// - /// Get a SearchClient to use for testing with a query API key. + /// Get a to use for testing with a query API key. /// /// Optional client options. - /// A SearchClient instance. + /// A instance. public SearchClient GetQueryClient(SearchClientOptions options = null) { Assert.IsNotNull(IndexName, "No index was created for these TestResources!"); @@ -282,7 +294,7 @@ private async Task DeleteIndexAsync() { if (RequiresCleanup && !string.IsNullOrEmpty(IndexName)) { - SearchServiceClient client = GetServiceClient(); + SearchIndexClient client = GetIndexClient(); await client.DeleteIndexAsync(IndexName); RequiresCleanup = false; @@ -318,7 +330,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 SearchIndexClient(Endpoint, new AzureKeyCredential(PrimaryApiKey)); await client.CreateIndexAsync(GetHotelIndex(IndexName)); RequiresCleanup = true;