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/includes/quickstarts/dotnet.md
+27-25Lines changed: 27 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,12 @@ ms.service: cognitive-search
5
5
ms.custom:
6
6
- ignite-2023
7
7
ms.topic: include
8
-
ms.date: 06/09/2023
8
+
ms.date: 10/07/2024
9
9
---
10
10
11
-
Build a console application using the [**Azure.Search.Documents**](/dotnet/api/overview/azure/search.documents-readme) client library to create, load, and query a search index. Alternatively, you can [download the source code](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/quickstart/v11) to start with a finished project or follow these steps to create your own.
11
+
Build a console application using the [Azure.Search.Documents](/dotnet/api/overview/azure/search.documents-readme) client library to create, load, and query a search index.
12
+
13
+
Alternatively, you can [download the source code](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/quickstart/v11) to start with a finished project or follow these steps to create your own.
12
14
13
15
#### Set up your environment
14
16
@@ -20,11 +22,11 @@ Build a console application using the [**Azure.Search.Documents**](/dotnet/api/o
20
22
21
23
1. Search for [Azure.Search.Documents package](https://www.nuget.org/packages/Azure.Search.Documents/) and select version 11.0 or later.
22
24
23
-
1. Select **Install**on the right to add the assembly to your project and solution.
25
+
1. Select **Install** to add the assembly to your project and solution.
24
26
25
27
#### Create a search client
26
28
27
-
1. In **Program.cs**, change the namespace to `AzureSearch.SDK.Quickstart.v11` and then add the following `using` directives.
29
+
1. In *Program.cs*, change the namespace to `AzureSearch.SDK.Quickstart.v11` and then add the following `using` directives.
28
30
29
31
```csharp
30
32
usingAzure;
@@ -34,9 +36,9 @@ Build a console application using the [**Azure.Search.Documents**](/dotnet/api/o
34
36
usingAzure.Search.Documents.Models;
35
37
```
36
38
37
-
1.Create two clients:[SearchIndexClient](/dotnet/api/azure.search.documents.indexes.searchindexclient) creates the index, and [SearchClient](/dotnet/api/azure.search.documents.searchclient) loads and queries an existing index. Both need the service endpoint and an admin API key for authentication with create/delete rights.
39
+
1.Copy the following code to create two clients.[SearchIndexClient](/dotnet/api/azure.search.documents.indexes.searchindexclient) creates the index, and [SearchClient](/dotnet/api/azure.search.documents.searchclient) loads and queries an existing index. Both need the service endpoint and an admin API key for authentication with create/delete rights.
38
40
39
-
Because the code builds out the URI for you, specify just the search service name in the "serviceName" property.
41
+
Because the code builds out the URI for you, specify just the search service name in the `serviceName` property.
40
42
41
43
```csharp
42
44
staticvoidMain(string[] args)
@@ -60,11 +62,11 @@ Build a console application using the [**Azure.Search.Documents**](/dotnet/api/o
60
62
61
63
ThisquickstartbuildsaHotelsindexthatyou'll load with hotel data and execute queries against. In this step, define the fields in the index. Each field definition includes a name, data type, and attributes that determine how the field is used.
62
64
63
-
Inthisexample, synchronousmethodsoftheAzure.Search.Documentslibraryareusedfor simplicity and readability. However, for production scenarios, you should use asynchronous methods to keep your app scalable and responsive. For example, you would use [CreateIndexAsync](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindexasync) insteadof [CreateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindex).
65
+
Inthisexample, synchronousmethodsofthe*Azure.Search.Documents*libraryareusedfor simplicity and readability. However, for production scenarios, you should use asynchronous methods to keep your app scalable and responsive. For example, you would use [CreateIndexAsync](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindexasync) insteadof [CreateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindex).
64
66
65
-
1. Addanemptyclassdefinition to your project: **Hotel.cs**
67
+
1. Addanemptyclassdefinition to your project: *Hotel.cs*
66
68
67
-
1. Copythefollowingcodeinto **Hotel.cs** todefinethestructureofahoteldocument. Attributesonthefielddeterminehowit'susedinanapplication. Forexample, the `IsFilterable` attributemustbeassignedtoeveryfieldthatsupportsafilterexpression.
69
+
1. Copythefollowingcodeinto *Hotel.cs* todefinethestructureofahoteldocument. Attributesonthefielddeterminehowit'susedinanapplication. Forexample, the `IsFilterable` attributemustbeassignedtoeveryfieldthatsupportsafilterexpression.
68
70
69
71
```csharp
70
72
usingSystem;
@@ -110,15 +112,15 @@ In this example, synchronous methods of the Azure.Search.Documents library are u
110
112
}
111
113
```
112
114
113
-
IntheAzure.Search.Documentsclientlibrary, youcanuse [SearchableField](/dotnet/api/azure.search.documents.indexes.models.searchablefield) and [SimpleField](/dotnet/api/azure.search.documents.indexes.models.simplefield) tostreamlinefielddefinitions. Botharederivativesofa [SearchField](/dotnet/api/azure.search.documents.indexes.models.searchfield) andcanpotentiallysimplifyyourcode:
115
+
Inthe*Azure.Search.Documents*clientlibrary, youcanuse [SearchableField](/dotnet/api/azure.search.documents.indexes.models.searchablefield) and [SimpleField](/dotnet/api/azure.search.documents.indexes.models.simplefield) tostreamlinefielddefinitions. Botharederivativesofa [SearchField](/dotnet/api/azure.search.documents.indexes.models.searchfield) andcanpotentiallysimplifyyourcode:
114
116
115
117
+ `SimpleField` canbeanydatatype, isalwaysnon-searchable (it'signoredforfulltextsearchqueries), andisretrievable (it'snothidden). Otherattributesareoffbydefault, butcanbeenabled. Youmightusea `SimpleField` for document IDs or fields used only in filters, facets, or scoring profiles. If so, be sure to apply any attributes that are necessary for the scenario, such as `IsKey = true` for a document ID. For more information, see [SimpleFieldAttribute.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/src/Indexes/SimpleFieldAttribute.cs) in source code.
116
118
117
119
+ `SearchableField` must be astring, andisalwayssearchableandretrievable. Otherattributesareoffbydefault, butcanbeenabled. Becausethisfieldtypeissearchable, itsupportssynonymsandthefullcomplementofanalyzerproperties. Formoreinformation, seethe [SearchableFieldAttribute.cs](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/search/Azure.Search.Documents/src/Indexes/SearchableFieldAttribute.cs) in source code.
1. Addasecondemptyclassdefinition to your project: **Address.cs**. Copythefollowingcodeintotheclass.
123
+
1. Addasecondemptyclassdefinition to your project: *Address.cs*.Copythefollowingcodeintotheclass.
122
124
123
125
```csharp
124
126
usingAzure.Search.Documents.Indexes;
@@ -145,9 +147,9 @@ In this example, synchronous methods of the Azure.Search.Documents library are u
145
147
}
146
148
```
147
149
148
-
1. Create two more classes: **Hotel.Methods.cs** and **Address.Methods.cs** for ToString() overrides. These classes are used to render search results in the console output. The contents of these classes aren't provided in this article, but you can copy the code from [files in GitHub](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/quickstart/v11/AzureSearchQuickstart-v11).
150
+
1. Create two more classes: *Hotel.Methods.cs* and *Address.Methods.cs* for `ToString()` overrides. These classes are used to render search results in the console output. The contents of these classes aren't provided in this article, but you can copy the code from [files in GitHub](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/quickstart/v11/AzureSearchQuickstart-v11).
149
151
150
-
1. In **Program.cs**, create a [SearchIndex](/dotnet/api/azure.search.documents.indexes.models.searchindex) object, and then call the [CreateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindex) method to express the index in your search service. The index also includes a [SearchSuggester](/dotnet/api/azure.search.documents.indexes.models.searchsuggester) to enable autocomplete on the specified fields.
152
+
1. In *Program.cs*, create a [SearchIndex](/dotnet/api/azure.search.documents.indexes.models.searchindex) object, and then call the [CreateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createindex) method to express the index in your search service. The index also includes a [SearchSuggester](/dotnet/api/azure.search.documents.indexes.models.searchsuggester) to enable autocomplete on the specified fields.
151
153
152
154
```csharp
153
155
// Create hotels-quickstart index
@@ -173,7 +175,7 @@ In Azure AI Search, search documents are data structures that are both inputs to
173
175
174
176
When uploading documents, you must use an [IndexDocumentsBatch](/dotnet/api/azure.search.documents.models.indexdocumentsbatch-1) object. An `IndexDocumentsBatch` object contains a collection of [Actions](/dotnet/api/azure.search.documents.models.indexdocumentsbatch-1.actions), each of which contains a document and a property telling Azure AI Search what action to perform ([upload, merge, delete, and mergeOrUpload](/azure/search/search-what-is-data-import#indexing-actions)).
175
177
176
-
1. In **Program.cs**, create an array of documents and index actions, and then pass the array to `IndexDocumentsBatch`. The documents below conform to the hotels-quickstart index, as defined by the hotel class.
178
+
1. In *Program.cs*, create an array of documents and index actions, and then pass the array to `IndexDocumentsBatch`. The following documents conform to the hotels-quickstart index, as defined by the hotel class.
177
179
178
180
```csharp
179
181
// Upload documents in a single Upload request.
@@ -281,7 +283,7 @@ When uploading documents, you must use an [IndexDocumentsBatch](/dotnet/api/azur
0 commit comments