Azure 认知搜索的 .NET (C#) 代码示例.NET (C#) code samples for Azure Cognitive Search

了解演示 Azure 认知搜索的特性和功能的 C# 代码示例。Learn about the C# code samples that demonstrate the features and functionality of Azure Cognitive Search. 主存储库如下所示:The primary repositories are as follows:

存储库Repository 说明Description
azure-sdk-for-net/sdk/search/Azure.Search.Documents/samples/azure-sdk-for-net/sdk/search/Azure.Search.Documents/samples/ SDK 中 Azure.Search.Documents 客户端库附带的由 Azure SDK 团队生成的示例。Samples produced by the Azure SDK team that ship with the Azure.Search.Documents client library in the SDK. 你还可以查看客户端库的单元测试,以了解如何调用各种 API。You can also review unit tests for the client library to see how various APIs are called.
Azure-Samples/azure-search-dotnet-samplesAzure-Samples/azure-search-dotnet-samples 文档中操作说明文章附带的示例,包括如何使用 .NET 客户端库Samples that accompany how-to articles in the documentation, including How to use the .NET client library.
Azure-Samples/search-dotnet-getting-startedAzure-Samples/search-dotnet-getting-started 文档中快速入门和教程附带的示例。Samples that accompany quickstarts and tutorials in the documentation.


请尝试使用示例浏览器来搜索 Github 中的 Microsoft 代码示例,搜索时可按产品、服务和语言进行筛选。Try the Samples browser to search for Microsoft code samples in Github, filtered by product, service, and language.

.NET SDK 示例.NET SDK samples

用于 .NET 的 Azure SDK 包含多个示例和一个描述每个示例的示例自述文件The Azure SDK for .NET includes numerous samples and a samples readme that describes each one. 下面提供了此列表,以方便查看。That list is provided below for your convenience.

示例Samples 说明Description
“Hello world”,同步"Hello world", synchronously 演示如何使用同步方法创建客户端、验证身份和处理错误。Demonstrates how to create a client, authenticate, and handle errors using synchronous methods.
“Hello world”,异步"Hello world", asynchronously 演示如何使用异步方法创建客户端、验证身份和处理错误。Demonstrates how to create a client, authenticate, and handle errors using asynchronous methods.
服务级操作Service-level operations 演示如何创建索引、索引器、数据源、技能组和同义词映射。Demonstrates how to create indexes, indexers, data sources, skillsets, and synonym maps. 此示例还演示如何获取服务统计信息以及如何查询索引。This sample also shows you how to get service statistics and how to query an index.
索引操作Index operations 演示如何对现有索引执行操作,在此示例中,演示如何获取索引中存储的文档数。Demonstrates how to perform an action on existing index, in this case getting a count of documents stored in the index.
FieldBuilderIgnoreFieldBuilderIgnore 演示用于处理不受支持的数据类型的方法。Demonstrates a technique for working with unsupported data types.
为文档编制索引(推送模型)Indexing documents (push model) 编制索引的“推送”模型,用于将 JSON 有效负载发送到服务的索引。"Push" model indexing, where you send a JSON payload to an index on a service.
加密密钥示例Encryption key sample 演示如何使用客户管理的加密密钥为敏感内容添加额外保护层。Demonstrates using a customer-managed encryption key to add an extra layer of protection over sensitive content.

文档示例Documentation samples

Azure 认知搜索文档中有与以下示例相关联的文章。The following samples have an associated article in Azure Cognitive Search documentation.

示例Samples 说明Description
快速入门quickstart 快速入门:创建搜索索引的源代码。Source code for Quickstart: Create a search index .
DotNetHowToDotNetHowTo 如何使用 .NET 客户端库的源代码Source code for How to use the .NET client library
DotNetHowToSynonymsDotNetHowToSynonyms 同义词列表用于扩展查询,可提供索引外部的匹配术语。Synonym lists are used for query expansion, providing matchable terms that are external to an index. 此示例包含在示例:在 C# 中添加同义词This sample is included in Example: Add synonyms in C#.
DotNetToIndexersDotNetToIndexers 各项目中与索引器相关的代码片段的源代码。Source code behind indexer-related snippets in various articles. 此示例演示如何配置一个具有计划、字段映射和参数的索引器。This example shows how to configure an indexer that has a schedule, field mappings, and parameters.
DotNetHowToEncryptionUsingCMKDotNetHowToEncryptionUsingCMK 如何配置客户管理的密钥以进行数据加密的源代码Source code for How to configure customer-managed keys for data encryption
使用 C# 创建自己的第一个应用Create your first app in C# 教程:创建自己的第一个搜索应用的源代码。Source code for Tutorial: Create your first search app. 虽然大多数示例都是控制台应用程序,但此 MVC 示例使用网页作为酒店索引示例的前端,演示了基本搜索、分页、自动完成以及建议的查询、分面和筛选。While most samples are console applications, this MVC sample uses a web page to front the sample Hotels index, demonstrating basic search, pagination, autocomplete and suggested queries, facets, and filters.
multiple-data-sourcesmultiple-data-sources 教程:从多个数据源编制索引的源代码。Source code for Tutorial: Index from multiple data sources.
optimize-data-indexingoptimize-data-indexing 教程:使用推送 API 优化索引编制的源代码。Source code for Tutorial: Optimize indexing with the push API.
tutorial-ai-enrichmenttutorial-ai-enrichment 教程:AI 使用 .NET SDK 从 Azure Blob 生成可搜索内容的源代码。Source code for Tutorial: AI-generated searchable content from Azure blobs using the .NET SDK.

独立示例和解决方案Standalone samples and solutions

示例Samples 说明Description
azure-search-power-skillsazure-search-power-skills 可合并到你自己的解决方案中的可耗用自定义技能的源代码。Source code for consumable custom skills that you can incorporate in your won solutions.
知识挖掘解决方案加速器Knowledge Mining Solution Accelerator 包括模板、支持文件和分析报表,以帮助你建立端到端知识挖掘解决方案的原型。Includes templates, support files, and analytical reports to help you prototype an end-to-end knowledge mining solution.
Covid-19 搜索应用存储库Covid-19 Search App repository 基于认知搜索的 Covid-19 搜索应用的源代码存储库Source code repository for the Cognitive Search based Covid-19 Search App
JFKJFK 详细了解 JFK 解决方案Learn more about the JFK solution.