Skip to content

Commit

Permalink
Return pageables from SearchServiceClient.GetIndexes(Async) (#11517)
Browse files Browse the repository at this point in the history
Fixes #11053
  • Loading branch information
heaths authored Apr 23, 2020
1 parent 570e4ae commit 673f5bc
Show file tree
Hide file tree
Showing 8 changed files with 957 additions and 23 deletions.
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

- Removed constructor from `SynonymMap` with `IEnumerable<string>` parameter.
- `SearchServiceClient.GetIndexes` and `SearchServiceClient.GetIndexesAsync` now return `Pageable<SearchIndex>` and `AsyncPageable<SearchIndex>` respectively.

## 1.0.0-preview.2 (2020-04-06)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public SearchServiceClient(System.Uri endpoint, Azure.AzureKeyCredential credent
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Models.SearchIndexer>>> GetIndexersAsync(System.Collections.Generic.IEnumerable<string> selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Search.Documents.Models.IndexerExecutionInfo> 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<Azure.Response<Azure.Search.Documents.Models.IndexerExecutionInfo>> GetIndexerStatusAsync(string indexerName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Models.SearchIndex>> GetIndexes(System.Collections.Generic.IEnumerable<string> selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Models.SearchIndex>>> GetIndexesAsync(System.Collections.Generic.IEnumerable<string> selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Search.Documents.Models.SearchIndex> GetIndexes(System.Collections.Generic.IEnumerable<string> selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Search.Documents.Models.SearchIndex> GetIndexesAsync(System.Collections.Generic.IEnumerable<string> selectProperties = null, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Search.Documents.Models.SearchIndexStatistics> 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<Azure.Response<Azure.Search.Documents.Models.SearchIndexStatistics>> GetIndexStatisticsAsync(string indexName, Azure.Search.Documents.SearchRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Search.Documents.SearchIndexClient GetSearchIndexClient(string indexName) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="$(AzureCoreSharedSources)HttpMessageSanitizer.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)TaskExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)OperationHelpers.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureCoreSharedSources)PageResponseEnumerator.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>

<!-- Project and Package references -->
Expand Down
52 changes: 31 additions & 21 deletions sdk/search/Azure.Search.Documents/src/SearchServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,21 +753,26 @@ await IndexesClient.GetAsync(
/// <param name="selectProperties">Optional property names to select. The default is all properties.</param>
/// <param name="options">Optional <see cref="SearchRequestOptions"/> to customize the operation's behavior.</param>
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/> to propagate notifications that the operation should be canceled.</param>
/// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SearchIndex"/>.</returns>
/// <returns>The <see cref="Pageable{T}"/> from the server containing a list of <see cref="SearchIndex"/>.</returns>
/// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception>
[ForwardsClientCalls]
public virtual Response<IReadOnlyList<SearchIndex>> GetIndexes(
public virtual Pageable<SearchIndex> GetIndexes(
IEnumerable<string> selectProperties = null,
SearchRequestOptions options = null,
CancellationToken cancellationToken = default)
{
Response<ListIndexesResult> result = IndexesClient.List(
selectProperties.CommaJoin() ?? Constants.All,
options?.ClientRequestId,
cancellationToken);
CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateEnumerable((continuationToken) =>
{
if (continuationToken != null)
{
throw new NotSupportedException("A continuation token is unexpected and unsupported at this time.");
}

return Response.FromValue(result.Value.Indexes, result.GetRawResponse());
}
Response<ListIndexesResult> result = IndexesClient.List(
selectProperties.CommaJoin() ?? Constants.All,
options?.ClientRequestId,
cancellationToken);

return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse());
});

/// <summary>
/// Gets a list of all indexes.
Expand All @@ -778,19 +783,24 @@ public virtual Response<IReadOnlyList<SearchIndex>> GetIndexes(
/// <returns>The <see cref="Response{T}"/> from the server containing a list of <see cref="SearchIndex"/>.</returns>
/// <exception cref="RequestFailedException">Thrown when a failure is returned by the Search service.</exception>
[ForwardsClientCalls]
public virtual async Task<Response<IReadOnlyList<SearchIndex>>> GetIndexesAsync(
public virtual AsyncPageable<SearchIndex> GetIndexesAsync(
IEnumerable<string> selectProperties = null,
SearchRequestOptions options = null,
CancellationToken cancellationToken = default)
{
Response<ListIndexesResult> result = await IndexesClient.ListAsync(
selectProperties.CommaJoin() ?? Constants.All,
options?.ClientRequestId,
cancellationToken)
.ConfigureAwait(false);

return Response.FromValue(result.Value.Indexes, result.GetRawResponse());
}
CancellationToken cancellationToken = default) => PageResponseEnumerator.CreateAsyncEnumerable(async (continuationToken) =>
{
if (continuationToken != null)
{
throw new NotSupportedException("A continuation token is unexpected and unsupported at this time.");
}

Response<ListIndexesResult> result = await IndexesClient.ListAsync(
selectProperties.CommaJoin() ?? Constants.All,
options?.ClientRequestId,
cancellationToken)
.ConfigureAwait(false);

return Page<SearchIndex>.FromValues(result.Value.Indexes, null, result.GetRawResponse());
});

/// <summary>
/// Gets <see cref="SearchIndexStatistics"/> for the given index, including a document count and storage usage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,38 @@ public async Task GetIndex()
Assert.AreEqual(13, index.Fields.Count);
}

[Test]
public async Task GetIndexes()
{
await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this);

SearchServiceClient client = resources.GetServiceClient();

bool found = false;
await foreach (SearchIndex index in client.GetIndexesAsync())
{
found |= string.Equals(resources.IndexName, index.Name, StringComparison.InvariantCultureIgnoreCase);
}

Assert.IsTrue(found, "Shared index not found");
}

[Test]
[AsyncOnly]
public async Task GetIndexesNextPageThrows()
{
await using SearchResources resources = await SearchResources.GetSharedHotelsIndexAsync(this);

SearchServiceClient client = resources.GetServiceClient();
AsyncPageable<SearchIndex> pageable = client.GetIndexesAsync();

string continuationToken = Recording.GenerateId();
IAsyncEnumerator<Page<SearchIndex>> e = pageable.AsPages(continuationToken).GetAsyncEnumerator();

// Given a continuationToken above, this actually starts with the second page.
Assert.ThrowsAsync<NotSupportedException>(async () => await e.MoveNextAsync());
}

[Test]
public async Task CreateAzureBlobIndexer()
{
Expand Down
Loading

0 comments on commit 673f5bc

Please sign in to comment.