-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
SearchClientBuilderExtensions.cs
109 lines (104 loc) · 5.68 KB
/
SearchClientBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 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">Create and manage api-keys for an Azure Cognitive Search service</see>
/// 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">Create and manage api-keys for an Azure Cognitive Search service</see>
/// 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);
}
}