您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Azure 搜索库Azure Search libraries for .NET

概述Overview

Azure 搜索是一个完全托管的云搜索服务,可基于 Web、移动和企业应用程序中的数据提供丰富的搜索体验。Azure Search is a fully managed cloud search service that provides a rich search experience over data in web, mobile, and enterprise applications.

客户端库Client library

使用 Azure 搜索客户端库可访问搜索服务、索引、文档或其他对象并对其执行索引和搜索操作。Use the Azure Search client library to access and execute indexing and search operations on a search service, index, documents, or other object. 有关分步介绍,请参阅如何通过 .NET 应用程序使用 Azure 搜索For a step-by-step introduction, see How to use Azure Search from a .NET application.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package Microsoft.Azure.Search
dotnet add package Microsoft.Azure.Search

代码示例Code Example

/* Include these 'using' directives:
   using Microsoft.Azure.Search;
   using Microsoft.Azure.Search.Models;
*/

// A service endpoint and an api-key are required on a connection.
// Set them in a config file (not shown) and then connect to the client.
IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
IConfigurationRoot configuration = builder.Build();

SearchServiceClient serviceClient = CreateSearchServiceClient(configuration);

// Create an index named hotels
ISearchIndexClient indexClient = serviceClient.Indexes.GetClient("hotels");

管理库Management library

使用 Azure 搜索管理库可预配服务、管理 API 密钥,以及调整资源。Use the Azure Search management library to provision a service, manage api-keys, and adjust resources. 服务管理依赖于使用 Azure 资源管理器来识别订阅方和租户。Service management has a dependency on Azure Resource Manager for subscriber and tenant identification. 通常,若要支持工作流,还需要在 Azure Active Directory 中完成身份验证和应用程序注册。Typically, authentication and application registration with Azure Active Directory is also necessary to support the workflow. 有关 Azure 搜索服务预配的简介,请参阅如何使用管理 REST APIFor an introduction to Azure Search service provisioning, see How to use the Management REST API.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package Microsoft.Azure.Management.Search
dotnet add package Microsoft.Azure.Management.Search

示例Samples

在 Github 上的 Azure 示例存储库中查找更多的搜索示例。Find more search samples in the Azure samples repository on Github.