| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. See License.txt in the project root for |
| | | 3 | | // license information. |
| | | 4 | | |
| | | 5 | | namespace Microsoft.Azure.Search |
| | | 6 | | { |
| | | 7 | | using System.Linq; |
| | | 8 | | using System.Net.Http; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Defines an extension method for obtaining a pre-configured SearchIndexClient from the Indexes property |
| | | 12 | | /// of a SearchServiceClient. |
| | | 13 | | /// </summary> |
| | | 14 | | public static class IndexesGetClientExtensions |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Creates a new index client for querying and managing documents in a given index. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <param name="operations">The operation group for indexes of the Search service.</param> |
| | | 20 | | /// <param name="indexName">The name of the index.</param> |
| | | 21 | | /// <returns>A new <c cref="Microsoft.Azure.Search.SearchIndexClient">SearchIndexClient</c> instance.</returns> |
| | | 22 | | /// <remarks> |
| | | 23 | | /// The new client is configured with full read-write access to the index. If you are only planning to use the |
| | | 24 | | /// client for query operations, we recommend directly creating a |
| | | 25 | | /// <c cref="Microsoft.Azure.Search.SearchIndexClient">SearchIndexClient</c> instance instead. |
| | | 26 | | /// </remarks> |
| | | 27 | | public static ISearchIndexClient GetClient(this IIndexesOperations operations, string indexName) |
| | | 28 | | { |
| | | 29 | | // Argument checking is done by the SearchIndexClient constructor. Note that HttpClient can't be shared in |
| | | 30 | | // case it has already been used (SearchIndexClient will attempt to set the Timeout property on it). |
| | 8 | 31 | | SearchServiceClient serviceClient = operations.Client; |
| | 8 | 32 | | var rootHandler = serviceClient.HttpMessageHandlers.OfType<HttpClientHandler>().SingleOrDefault(); |
| | 8 | 33 | | var indexClient = |
| | 8 | 34 | | new SearchIndexClient(serviceClient.SearchServiceName, indexName, serviceClient.SearchCredentials, rootH |
| | 8 | 35 | | { |
| | 8 | 36 | | SearchDnsSuffix = serviceClient.SearchDnsSuffix |
| | 8 | 37 | | }; |
| | | 38 | | |
| | 8 | 39 | | indexClient.HttpClient.Timeout = serviceClient.HttpClient.Timeout; |
| | 8 | 40 | | return indexClient; |
| | | 41 | | } |
| | | 42 | | } |
| | | 43 | | } |