Skip to content

Commit f48ae30

Browse files
committed
Updated docs per sample refresh
1 parent ae422a8 commit f48ae30

File tree

7 files changed

+59
-47
lines changed

7 files changed

+59
-47
lines changed
21 Bytes
Loading
-10.3 KB
Loading
10.4 KB
Loading
-302 Bytes
Loading
-105 Bytes
Loading

articles/search/search-howto-dotnet-sdk.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
---
22
title: Use Azure.Search.Documents (v11) in .NET
33
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.
55

66
manager: nitinme
77
author: HeidiSteen
88
ms.author: heidist
99
ms.devlang: csharp
1010
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
1313
ms.custom: devx-track-csharp
1414
---
15+
1516
# How to use Azure.Search.Documents in a C# .NET Application
1617

1718
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
3839

3940
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).
4041

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.
4243

4344
## Upgrade to v11
4445

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).
4647

4748
## SDK requirements
4849

@@ -52,7 +53,7 @@ If you have been using the previous version of the .NET SDK and you'd like to up
5253

5354
+ 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`.
5455

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).
5657

5758
## Example application
5859

@@ -96,7 +97,7 @@ static void Main(string[] args)
9697

9798
Next is a partial screenshot of the output, assuming you run this application with a valid service name and API keys:
9899

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.":::
100101

101102
### Client types
102103

@@ -138,7 +139,7 @@ private static SearchClient CreateSearchClientForQueries(string indexName, IConf
138139
139140
### Deleting the index
140141

141-
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.
142143

143144
The following line calls `DeleteIndexIfExists`:
144145

@@ -279,7 +280,7 @@ public partial class Hotel
279280

280281
When defining fields, you can use the base [`SearchField`](/dotnet/api/azure.search.documents.indexes.models.searchfield) class, or you can use derivative helper models that serve as "templates", with pre-configured properties.
281282

282-
Exactly one field in your index must serve as the document key (`IsKey = true`). It must be a string, and it must uniquely identify each document. It's also required to have `IsHidden = true`, which means it cannot be visible in search results.
283+
Exactly one field in your index must serve as the document key (`IsKey = true`). It must be a string, and it must uniquely identify each document. It's also required to have `IsHidden = true`, which means it can't be visible in search results.
283284

284285
| Field type | Description and usage |
285286
|------------|-----------------------|
@@ -304,7 +305,7 @@ Did you happen to notice the `SmokingAllowed` property?
304305
public bool? SmokingAllowed => (Rooms != null) ? Array.Exists(Rooms, element => element.SmokingAllowed == true) : (bool?)null;
305306
```
306307

307-
The `JsonIgnore` attribute on this property tells the `FieldBuilder` to not serialize it to the index as a field. This is a great way to create client-side calculated properties you can use as helpers in your application. In this case, the `SmokingAllowed` property reflects whether any `Room` in the `Rooms` collection allows smoking. If all are false, it indicates that the entire hotel does not allow smoking.
308+
The `JsonIgnore` attribute on this property tells the `FieldBuilder` to not serialize it to the index as a field. This is a great way to create client-side calculated properties you can use as helpers in your application. In this case, the `SmokingAllowed` property reflects whether any `Room` in the `Rooms` collection allows smoking. If all are false, it indicates that the entire hotel doesn't allow smoking.
308309

309310
## Load an index
310311

@@ -466,7 +467,7 @@ Second, define a method that sends a query request.
466467

467468
Each time the method executes a query, it creates a new [`SearchOptions`](/dotnet/api/azure.search.documents.searchoptions) object. This object is used to specify additional options for the query such as sorting, filtering, paging, and faceting. In this method, 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).
468469

469-
The next step is query execution. Running the search is done using the `SearchClient.Search` method. For each query, pass the search text to use as a string (or `"*"` if there is 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`.
470+
The next step is query execution. Running the search is done using the `SearchClient.Search` method. For each query, pass the search text to use as a string (or `"*"` if there'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`.
470471

471472
```csharp
472473
private static void RunQueries(SearchClient searchClient)
@@ -562,7 +563,7 @@ RunQueries(indexClientForQueries);
562563

563564
### Explore query constructs
564565

565-
Let's take a closer look at each of the queries in turn. Here is the code to execute the first query:
566+
Let's take a closer look at each of the queries in turn. Here's the code to execute the first query:
566567

567568
```csharp
568569
options = new SearchOptions();
@@ -596,7 +597,7 @@ results = searchClient.Search<Hotel>("*", options);
596597

597598
The above query uses an OData `$filter` expression, `Rooms/any(r: r/BaseRate lt 100)`, to filter the documents in the index. This uses the [any operator](./search-query-odata-collection-operators.md) to apply the 'BaseRate lt 100' to every item in the Rooms collection. For more information, see [OData filter syntax](./query-odata-filter-orderby-syntax.md).
598599

599-
In the third query, find the top two hotels that have been most recently renovated, and show the hotel name and last renovation date. Here is the code:
600+
In the third query, find the top two hotels that have been most recently renovated, and show the hotel name and last renovation date. Here's the code:
600601

601602
```csharp
602603
options =
@@ -632,7 +633,7 @@ results = searchClient.Search<Hotel>("hotel", options);
632633
WriteDocuments(results);
633634
```
634635

635-
This section concludes this introduction to the .NET SDK, but don't stop here. The next section suggests additional resources for learning more about programming with Azure Cognitive Search.
636+
This section concludes this introduction to the .NET SDK, but don't stop here. The next section suggests other resources for learning more about programming with Azure Cognitive Search.
636637

637638
## Next steps
638639

0 commit comments

Comments
 (0)