Skip to content

Commit

Permalink
Adding SearchClientBuilderExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tg-msft committed Jun 9, 2020
1 parent 66e62b1 commit 757feae
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2049,3 +2049,13 @@ public ValueFacetResult(long count, T value) { }
public T Value { get { throw null; } }
}
}
namespace Microsoft.Extensions.Azure
{
public static partial class SearchClientBuilderExtensions
{
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Search.Documents.SearchClient, Azure.Search.Documents.SearchClientOptions> AddSearchClient<TBuilder>(this TBuilder builder, System.Uri endpoint, string indexName, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Search.Documents.SearchClient, Azure.Search.Documents.SearchClientOptions> AddSearchClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Search.Documents.Indexes.SearchIndexClient, Azure.Search.Documents.SearchClientOptions> AddSearchIndexClient<TBuilder>(this TBuilder builder, System.Uri endpoint, Azure.AzureKeyCredential credential) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilder { throw null; }
public static Azure.Core.Extensions.IAzureClientBuilder<Azure.Search.Documents.Indexes.SearchIndexClient, Azure.Search.Documents.SearchClientOptions> AddSearchIndexClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration) where TBuilder : Azure.Core.Extensions.IAzureClientFactoryBuilderWithConfiguration<TConfiguration> { throw null; }
}
}
110 changes: 110 additions & 0 deletions sdk/search/Azure.Search.Documents/src/SearchClientBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure;
using Azure.Core.Extensions;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;

namespace Microsoft.Extensions.Azure
{
/// <summary>
/// Extension methods to add <see cref="SearchClient"/> to the Azure client
/// builder.
/// </summary>
public static class SearchClientBuilderExtensions
{
/// <summary>
/// Registers a <see cref="SearchClient"/> instance with the provided
/// <paramref name="endpoint"/>, <paramref name="indexName"/>, and
/// <paramref name="credential"/>.
/// </summary>
/// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
/// <param name="builder">The client factory builder.</param>
/// <param name="endpoint">
/// 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.
/// </param>
/// <param name="indexName">
/// Required. The name of the Search Index.
/// </param>
/// <param name="credential">
/// Required. The API key credential used to authenticate requests
/// against the search service. You need to use an admin key to
/// modify the documents in a Search Index. See
/// <see href="https://docs.microsoft.com/azure/search/search-security-api-keys"/>
/// for more information about API keys in Azure Cognitive Search.
/// </param>
/// <returns>An Azure client builder.</returns>
public static IAzureClientBuilder<SearchClient, SearchClientOptions> AddSearchClient<TBuilder>(
this TBuilder builder,
Uri endpoint,
string indexName,
AzureKeyCredential credential)
where TBuilder : IAzureClientFactoryBuilder =>
builder.RegisterClientFactory<SearchClient, SearchClientOptions>(
options => new SearchClient(endpoint, indexName, credential, options));

/// <summary>
/// Registers a <see cref="SearchClient"/> instance with connection
/// options loaded from the provided <paramref name="configuration"/>
/// instance.
/// </summary>
/// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
/// <typeparam name="TConfiguration">Type of the configuration.</typeparam>
/// <param name="builder">The client factory builder.</param>
/// <param name="configuration">The client configuration.</param>
/// <returns>An Azure client builder.</returns>
public static IAzureClientBuilder<SearchClient, SearchClientOptions> AddSearchClient<TBuilder, TConfiguration>(
this TBuilder builder,
TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> =>
builder.RegisterClientFactory<SearchClient, SearchClientOptions>(configuration);


/// <summary>
/// Registers a <see cref="SearchIndexClient"/> instance with the
/// provided <paramref name="endpoint"/> and <paramref name="credential"/>.
/// </summary>
/// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
/// <param name="builder">The client factory builder.</param>
/// <param name="endpoint">
/// 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.
/// </param>
/// <param name="credential">
/// Required. The API key credential used to authenticate requests
/// against the search service. You need to use an admin key to
/// modify the documents in a Search Index. See
/// <see href="https://docs.microsoft.com/azure/search/search-security-api-keys"/>
/// for more information about API keys in Azure Cognitive Search.
/// </param>
/// <returns>An Azure client builder.</returns>
public static IAzureClientBuilder<SearchIndexClient, SearchClientOptions> AddSearchIndexClient<TBuilder>(
this TBuilder builder,
Uri endpoint,
AzureKeyCredential credential)
where TBuilder : IAzureClientFactoryBuilder =>
builder.RegisterClientFactory<SearchIndexClient, SearchClientOptions>(
options => new SearchIndexClient(endpoint, credential, options));

/// <summary>
/// Registers a <see cref="SearchIndexClient"/> instance with connection
/// options loaded from the provided <paramref name="configuration"/>
/// instance.
/// </summary>
/// <typeparam name="TBuilder">Type of the client factory builder.</typeparam>
/// <typeparam name="TConfiguration">Type of the configuration.</typeparam>
/// <param name="builder">The client factory builder.</param>
/// <param name="configuration">The client configuration.</param>
/// <returns>An Azure client builder.</returns>
public static IAzureClientBuilder<SearchIndexClient, SearchClientOptions> AddSearchIndexClient<TBuilder, TConfiguration>(
this TBuilder builder,
TConfiguration configuration)
where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration> =>
builder.RegisterClientFactory<SearchIndexClient, SearchClientOptions>(configuration);
}
}

0 comments on commit 757feae

Please sign in to comment.