You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/search-howto-dotnet-sdk.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,18 @@
1
1
---
2
2
title: Use Azure.Search.Documents (v11) in .NET
3
3
titleSuffix: Azure Cognitive Search
4
-
description: Learn how to create and manage search objects in a .NET application using C# and the Azure.Search.Documents (v11) client library. Code snippets demonstrate connecting to the service, creating indexes, and queries.
4
+
description: Learn how to create and manage search objects in a .NET application using C# and the Azure.Search.Documents (v11) client library.
5
5
6
6
manager: nitinme
7
7
author: HeidiSteen
8
8
ms.author: heidist
9
9
ms.devlang: csharp
10
10
ms.service: cognitive-search
11
-
ms.topic: conceptual
12
-
ms.date: 08/15/2022
11
+
ms.topic: how-to
12
+
ms.date: 10/04/2022
13
13
ms.custom: devx-track-csharp
14
14
---
15
+
15
16
# How to use Azure.Search.Documents in a C# .NET Application
16
17
17
18
This article explains how to create and manage search objects using C# and the [**Azure.Search.Documents**](/dotnet/api/overview/azure/search) (version 11) client library in the Azure SDK for .NET.
@@ -38,11 +39,11 @@ The client library defines classes like `SearchIndex`, `SearchField`, and `Searc
38
39
39
40
Azure.Search.Documents (version 11) targets version [`2020-06-30` of the Azure Cognitive Search REST API](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/search/data-plane/Azure.Search/preview/2020-06-30).
40
41
41
-
The client library does not provide [service management operations](/rest/api/searchmanagement/), such as creating and scaling search services and managing API keys. If you need to manage your search resources from a .NET application, use the [Microsoft.Azure.Management.Search](/dotnet/api/overview/azure/search/management) library in the Azure SDK for .NET.
42
+
The client library doesn't provide [service management operations](/rest/api/searchmanagement/), such as creating and scaling search services and managing API keys. If you need to manage your search resources from a .NET application, use the [Microsoft.Azure.Management.Search](/dotnet/api/overview/azure/search/management) library in the Azure SDK for .NET.
42
43
43
44
## Upgrade to v11
44
45
45
-
If you have been using the previous version of the .NET SDK and you'd like to upgrade to the current generally available version, see [Upgrade to Azure Cognitive Search .NET SDK version 11](search-dotnet-sdk-migration-version-11.md)
46
+
If you have been using the previous version of the .NET SDK and you'd like to upgrade to the current generally available version, see [Upgrade to Azure Cognitive Search .NET SDK version 11](search-dotnet-sdk-migration-version-11.md).
46
47
47
48
## SDK requirements
48
49
@@ -52,7 +53,7 @@ If you have been using the previous version of the .NET SDK and you'd like to up
52
53
53
54
+ Download the [Azure.Search.Documents package](https://www.nuget.org/packages/Azure.Search.Documents) using **Tools** > **NuGet Package Manager** > **Manage NuGet Packages for Solution** in Visual Studio. Search for the package name `Azure.Search.Documents`.
54
55
55
-
Azure SDK for .NET conforms to [.NET Standard 2.0](/dotnet/standard/net-standard#net-implementation-support), which means .NET Framework 4.6.1 and .NET Core 2.0 as minimum requirements.
56
+
Azure SDK for .NET conforms to [.NET Standard 2.0](/dotnet/standard/net-standard#net-implementation-support).
56
57
57
58
## Example application
58
59
@@ -96,7 +97,7 @@ static void Main(string[] args)
96
97
97
98
Next is a partial screenshot of the output, assuming you run this application with a valid service name and API keys:
98
99
99
-
:::image type="content" source="media/search-howto-dotnet-sdk/console-output.png" alt-text="Console.WriteLine output from the sample program":::
100
+
:::image type="content" source="media/search-howto-dotnet-sdk/console-output.png" alt-text="Screenshot of the Console.WriteLine output from the sample program.":::
In the early stages of development, you might want to include a [`DeleteIndex`](/dotnet/api/azure.search.documents.indexes.searchindexclient.deleteindex) statement to delete a work-in-progress index so that you can recreate it with an updated definition. Sample code for Azure Cognitive Search often includes a deletion step so that you can re-run the sample.
142
+
In the early stages of development, you might want to include a [`DeleteIndex`](/dotnet/api/azure.search.documents.indexes.searchindexclient.deleteindex) statement to delete a work-in-progress index so that you can recreate it with an updated definition. Sample code for Azure Cognitive Search often includes a deletion step so that you can rerun the sample.
Exactlyonefieldinyourindexmustserveasthedocumentkey (`IsKey=true`). Itmustbeastring, anditmustuniquelyidentifyeachdocument. It's also required to have `IsHidden = true`, which means it cannot be visible in search results.
283
+
Exactlyonefieldinyourindexmustserveasthedocumentkey (`IsKey=true`). Itmustbeastring, anditmustuniquelyidentifyeachdocument. It's also required to have `IsHidden = true`, which means it can'tbevisibleinsearchresults.
283
284
284
285
|Fieldtype|Descriptionandusage|
285
286
|------------|-----------------------|
@@ -304,7 +305,7 @@ Did you happen to notice the `SmokingAllowed` property?
The `JsonIgnore` attributeonthispropertytellsthe `FieldBuilder` tonotserializeittotheindexasafield. Thisisagreatwaytocreateclient-sidecalculatedpropertiesyoucanuseashelpersinyourapplication. Inthiscase, the `SmokingAllowed` propertyreflectswhetherany `Room` inthe `Rooms` collectionallowssmoking. Ifallarefalse, itindicatesthattheentirehoteldoesnotallowsmoking.
308
+
The `JsonIgnore` attributeonthispropertytellsthe `FieldBuilder` tonotserializeittotheindexasafield. Thisisagreatwaytocreateclient-sidecalculatedpropertiesyoucanuseashelpersinyourapplication. Inthiscase, the `SmokingAllowed` propertyreflectswhetherany `Room` inthe `Rooms` collectionallowssmoking. Ifallarefalse, itindicatesthattheentirehoteldoesn't allow smoking.
308
309
309
310
## Load an index
310
311
@@ -466,7 +467,7 @@ Second, define a method that sends a query request.
466
467
467
468
Eachtimethemethodexecutesaquery, itcreatesanew [`SearchOptions`](/dotnet/api/azure.search.documents.searchoptions) object. Thisobjectisusedtospecifyadditionaloptionsforthequerysuchassorting, filtering, paging, andfaceting. Inthismethod, we're setting the `Filter`, `Select`, and `OrderBy` property for different queries. For more information about the search query expression syntax, [Simple query syntax](/rest/api/searchservice/Simple-query-syntax-in-Azure-Search).
Thenextstepisqueryexecution. Runningthesearchisdoneusingthe `SearchClient.Search` method. Foreachquery, passthesearchtexttouseasastring (or `"*"` ifthere's no search text), plus the search options created earlier. We also specify `Hotel` as the type parameter for `SearchClient.Search`, which tells the SDK to deserialize documents in the search results into objects of type `Hotel`.
Thissectionconcludesthisintroductiontothe .NETSDK, butdon't stop here. The next section suggests additional resources for learning more about programming with Azure Cognitive Search.
636
+
Thissectionconcludesthisintroductiontothe .NETSDK, butdon't stop here. The next section suggests other resources for learning more about programming with Azure Cognitive Search.
0 commit comments