Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/search/Azure.Search.Documents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions sdk/search/Azure.Search.Documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchServiceStatistics> stats = search.GetServiceStatistics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchServiceStatistics> stats = await search.GetServiceStatisticsAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchServiceStatistics> stats = await search.GetServiceStatisticsAsync();
Expand Down
1,354 changes: 1,354 additions & 0 deletions sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexClient.cs

Large diffs are not rendered by default.

1,722 changes: 1,722 additions & 0 deletions sdk/search/Azure.Search.Documents/src/Indexes/SearchIndexerClient.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sdk/search/Azure.Search.Documents/src/SearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public SearchClient(

/// <summary>
/// Initializes a new instance of the SearchClient class from a
/// <see cref="SearchServiceClient"/>.
/// <see cref="SearchIndexClient"/>.
/// </summary>
/// <param name="endpoint">
/// Required. The URI endpoint of the Search Service. This is likely
Expand Down
3,014 changes: 0 additions & 3,014 deletions sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs

This file was deleted.

12 changes: 6 additions & 6 deletions sdk/search/Azure.Search.Documents/tests/Samples/HelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchServiceStatistics> stats = search.GetServiceStatistics();
Expand All @@ -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<SearchServiceStatistics> stats = await search.GetServiceStatisticsAsync();
Expand Down Expand Up @@ -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<SearchServiceStatistics> stats = await search.GetServiceStatisticsAsync();
Expand Down
6 changes: 3 additions & 3 deletions sdk/search/Azure.Search.Documents/tests/Samples/Readme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */)
{
}
Expand All @@ -27,22 +25,22 @@ 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<ArgumentNullException>(() => new SearchServiceClient(null, new AzureKeyCredential("fake")));
Assert.Throws<ArgumentNullException>(() => new SearchServiceClient(endpoint, null));
Assert.Throws<ArgumentException>(() => new SearchServiceClient(new Uri("http://bing.com"), null));
Assert.Throws<ArgumentNullException>(() => new SearchIndexClient(null, new AzureKeyCredential("fake")));
Assert.Throws<ArgumentNullException>(() => new SearchIndexClient(endpoint, null));
Assert.Throws<ArgumentException>(() => new SearchIndexClient(new Uri("http://bing.com"), null));
}

[Test]
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);
Expand Down Expand Up @@ -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();
Expand All @@ -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<SearchServiceStatistics> response =
await client.GetServiceStatisticsAsync(
Expand Down Expand Up @@ -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<SearchServiceStatistics> response = await client.GetServiceStatisticsAsync();
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.IsNotNull(response.Value);
Expand All @@ -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<ArgumentNullException>(() => service.CreateIndex(null));
Assert.AreEqual("index", ex.ParamName);
Expand All @@ -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);
Expand All @@ -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";
Expand Down Expand Up @@ -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<ArgumentNullException>(() => service.GetIndex(null));
Assert.AreEqual("indexName", ex.ParamName);
Expand All @@ -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.
Expand All @@ -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())
Expand All @@ -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<SearchIndex> pageable = client.GetIndexesAsync();

string continuationToken = Recording.GenerateId();
Expand All @@ -284,68 +282,14 @@ public async Task GetIndexesNextPageThrows()
Assert.ThrowsAsync<NotSupportedException>(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()
{
await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this);

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);
Expand Down Expand Up @@ -383,54 +327,5 @@ await client.CreateOrUpdateSynonymMapAsync(

await client.DeleteSynonymMapAsync(updatedMap, onlyIfUnchanged: true);
}

/// <summary>
/// Waits for an indexer to complete up to the given <paramref name="timeout"/>.
/// </summary>
/// <param name="client">The <see cref="SearchServiceClient"/> to use for requests.</param>
/// <param name="indexerName">The name of the <see cref="SearchIndexer"/> to check.</param>
/// <param name="timeout">The amount of time before being canceled. The default is 1 minute.</param>
/// <returns>A <see cref="Task"/> to await.</returns>
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());
}
}
}
}
}
Loading