Skip to content

Commit 67d70a8

Browse files
authored
Merge pull request #114119 from HeidiSteen/heidist-master
[azure search] C# AI enrichment tutorial revisions
2 parents 9fd77ae + 3115f57 commit 67d70a8

File tree

3 files changed

+22
-86
lines changed

3 files changed

+22
-86
lines changed

articles/search/cognitive-search-tutorial-blob-dotnet.md

Lines changed: 22 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: MarkHeff
88
ms.author: maheff
99
ms.service: cognitive-search
1010
ms.topic: tutorial
11-
ms.date: 02/27/2020
11+
ms.date: 05/05/2020
1212
---
1313

1414
# Tutorial: AI-generated searchable content from Azure blobs using the .NET SDK
@@ -39,7 +39,9 @@ If you don't have an Azure subscription, open a [free account](https://azure.mic
3939

4040
1. Open this [OneDrive folder](https://1drv.ms/f/s!As7Oy81M_gVPa-LCb5lC_3hbS-4) and on the top-left corner, click **Download** to copy the files to your computer.
4141

42-
1. Right-click the zip file and select **Extract All**. There are 14 files of various types. Use all of them for this tutorial.
42+
1. Right-click the zip file and select **Extract All**. There are 14 files of various types. You'll use 7 for this exercise.
43+
44+
You can also download the source code for this tutorial. Source code is in the tutorial-ai-enrichment folder in the [azure-search-dotnet-samples](https://github.com/Azure-Samples/azure-search-dotnet-samples) repository.
4345

4446
## 1 - Create services
4547

@@ -71,22 +73,22 @@ If possible, create both in the same region and resource group for proximity and
7173

7274
1. Click **Blobs** service.
7375

74-
1. Click **+ Container** to create a container and name it *basic-demo-data-pr*.
76+
1. Click **+ Container** to create a container and name it *cog-search-demo*.
7577

76-
1. Select *basic-demo-data-pr* and then click **Upload** to open the folder where you saved the download files. Select all fourteen files and click **OK** to upload.
78+
1. Select *cog-search-demo* and then click **Upload** to open the folder where you saved the download files. Select all fourteen files and click **OK** to upload.
7779

7880
![Upload sample files](media/cognitive-search-quickstart-blob/sample-data.png "Upload sample files")
7981

8082
1. Before you leave Azure Storage, get a connection string so that you can formulate a connection in Azure Cognitive Search.
8183

82-
1. Browse back to the Overview page of your storage account (we used *blobstragewestus* as an example).
84+
1. Browse back to the Overview page of your storage account (we used *blobstoragewestus* as an example).
8385

8486
1. In the left navigation pane, select **Access keys** and copy one of the connection strings.
8587

8688
The connection string is a URL similar to the following example:
8789

8890
```http
89-
DefaultEndpointsProtocol=https;AccountName=cogsrchdemostorage;AccountKey=<your account key>;EndpointSuffix=core.windows.net
91+
DefaultEndpointsProtocol=https;AccountName=blobstoragewestus;AccountKey=<your account key>;EndpointSuffix=core.windows.net
9092
```
9193
9294
1. Save the connection string to Notepad. You'll need it later when setting up the data source connection.
@@ -95,7 +97,7 @@ If possible, create both in the same region and resource group for proximity and
9597
9698
AI enrichment is backed by Cognitive Services, including Text Analytics and Computer Vision for natural language and image processing. If your objective was to complete an actual prototype or project, you would at this point provision Cognitive Services (in the same region as Azure Cognitive Search) so that you can attach it to indexing operations.
9799
98-
For this exercise, however, you can skip resource provisioning because Azure Cognitive Search can connect to Cognitive Services behind the scenes and give you 20 free transactions per indexer run. Since this tutorial uses 7 transactions, the free allocation is sufficient. For larger projects, plan on provisioning Cognitive Services at the pay-as-you-go S0 tier. For more information, see [Attach Cognitive Services](cognitive-search-attach-cognitive-services.md).
100+
For this exercise, however, you can skip resource provisioning because Azure Cognitive Search can connect to Cognitive Services behind the scenes and give you 20 free transactions per indexer run. Since this tutorial uses 14 transactions, the free allocation is sufficient. For larger projects, plan on provisioning Cognitive Services at the pay-as-you-go S0 tier. For more information, see [Attach Cognitive Services](cognitive-search-attach-cognitive-services.md).
99101
100102
### Azure Cognitive Search
101103
@@ -125,15 +127,15 @@ The [Azure Cognitive Search .NET SDK](https://aka.ms/search-sdk) consists of a f
125127
126128
For this project, install version 9 or later of the `Microsoft.Azure.Search` NuGet package.
127129
128-
1. Open the Package Manager Console. Select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
129-
130-
1. Navigate to [Microsoft.Azure.Search NuGet package page](https://www.nuget.org/packages/Microsoft.Azure.Search).
130+
1. In a browser, go to [Microsoft.Azure.Search NuGet package page](https://www.nuget.org/packages/Microsoft.Azure.Search).
131131
132132
1. Select the latest version (9 or later).
133133
134134
1. Copy the Package Manager command.
135135
136-
1. Return to the Package Manager console and run the command you copied in the previous step.
136+
1. Open the Package Manager Console. Select **Tools** > **NuGet Package Manager** > **Package Manager Console**.
137+
138+
1. Paste and run the command that you copied in the previous step.
137139
138140
Next, install the latest `Microsoft.Extensions.Configuration.Json` NuGet package.
139141
@@ -163,9 +165,11 @@ Next, install the latest `Microsoft.Extensions.Configuration.Json` NuGet package
163165
"AzureBlobConnectionString": "Put your Azure Blob connection string here",
164166
}
165167
```
166-
168+
167169
Add your search service and blob storage account information. Recall that you can get this information from the service provisioning steps indicated in the previous section.
168170
171+
For **SearchServiceName**, enter the short service name and not the full URL.
172+
169173
### Add namespaces
170174
171175
In `Program.cs`, add the following namespaces.
@@ -242,7 +246,7 @@ private static DataSource CreateOrUpdateDataSource(SearchServiceClient serviceCl
242246
DataSource dataSource = DataSource.AzureBlobStorage(
243247
name: "demodata",
244248
storageConnectionString: configuration["AzureBlobConnectionString"],
245-
containerName: "basic-demo-data-pr",
249+
containerName: "cog-search-demo",
246250
description: "Demo files to demonstrate cognitive search capabilities.");
247251

248252
// The data source does not need to be deleted if it was already created
@@ -278,34 +282,6 @@ public static void Main(string[] args)
278282
DataSource dataSource = CreateOrUpdateDataSource(serviceClient, configuration);
279283
```
280284

281-
282-
<!--
283-
```csharp
284-
DataSource dataSource = DataSource.AzureBlobStorage(
285-
name: "demodata",
286-
storageConnectionString: configuration["AzureBlobConnectionString"],
287-
containerName: "basic-demo-data-pr",
288-
deletionDetectionPolicy: new SoftDeleteColumnDeletionDetectionPolicy(
289-
softDeleteColumnName: "IsDeleted",
290-
softDeleteMarkerValue: "true"),
291-
description: "Demo files to demonstrate cognitive search capabilities.");
292-
```
293-
294-
Now that you have initialized the `DataSource` object, create the data source. `SearchServiceClient` has a `DataSources` property. This property provides all the methods you need to create, list, update, or delete Azure Cognitive Search data sources.
295-
296-
For a successful request, the method will return the data source that was created. If there is a problem with the request, such as an invalid parameter, the method will throw an exception.
297-
298-
```csharp
299-
try
300-
{
301-
serviceClient.DataSources.CreateOrUpdate(dataSource);
302-
}
303-
catch (Exception e)
304-
{
305-
// Handle the exception
306-
}
307-
``` -->
308-
309285
Build and run the solution. Since this is your first request, check the Azure portal to confirm the data source was created in Azure Cognitive Search. On the search service dashboard page, verify the Data Sources tile has a new item. You might need to wait a few minutes for the portal page to refresh.
310286

311287
![Data sources tile in the portal](./media/cognitive-search-tutorial-blob/data-source-tile.png "Data sources tile in the portal")
@@ -626,33 +602,6 @@ namespace EnrichwithAI
626602
}
627603
```
628604
629-
<!-- Add the below model class definition to `DemoIndex.cs` and include it in the same namespace where you'll create the index.
630-
631-
```csharp
632-
// The SerializePropertyNamesAsCamelCase attribute is defined in the Azure Cognitive Search .NET SDK.
633-
// It ensures that Pascal-case property names in the model class are mapped to camel-case
634-
// field names in the index.
635-
[SerializePropertyNamesAsCamelCase]
636-
public class DemoIndex
637-
{
638-
[System.ComponentModel.DataAnnotations.Key]
639-
[IsSearchable, IsSortable]
640-
public string Id { get; set; }
641-
642-
[IsSearchable]
643-
public string Content { get; set; }
644-
645-
[IsSearchable]
646-
public string LanguageCode { get; set; }
647-
648-
[IsSearchable]
649-
public string[] KeyPhrases { get; set; }
650-
651-
[IsSearchable]
652-
public string[] Organizations { get; set; }
653-
}
654-
``` -->
655-
656605
Now that you've defined a model class, back in `Program.cs` you can create an index definition fairly easily. The name for this index will be `demoindex`. If an index already exists with that name, it will be deleted.
657606
658607
```csharp
@@ -692,27 +641,14 @@ Add the following lines to `Main`.
692641
```csharp
693642
// Create the index
694643
Console.WriteLine("Creating the index...");
695-
Index demoIndex = CreateDemoIndex(serviceClient);
644+
Microsoft.Azure.Search.Models.Index demoIndex = CreateDemoIndex(serviceClient);
696645
```
697646
698-
<!-- ```csharp
699-
try
700-
{
701-
bool exists = serviceClient.Indexes.Exists(index.Name);
647+
Add the following using statement to resolve the disambiguate reference.
702648
703-
if (exists)
704-
{
705-
serviceClient.Indexes.Delete(index.Name);
706-
}
707-
708-
serviceClient.Indexes.Create(index);
709-
}
710-
catch (Exception e)
711-
{
712-
// Handle exception
713-
}
649+
```csharp
650+
using Index = Microsoft.Azure.Search.Models.Index;
714651
```
715-
-->
716652
717653
To learn more about defining an index, see [Create Index (Azure Cognitive Search REST API)](https://docs.microsoft.com/rest/api/searchservice/create-index).
718654
@@ -795,7 +731,7 @@ Add the following lines to `Main`.
795731
796732
```csharp
797733
// Create the indexer, map fields, and execute transformations
798-
Console.WriteLine("Creating the indexer...");
734+
Console.WriteLine("Creating the indexer and executing the pipeline...");
799735
Indexer demoIndexer = CreateDemoIndexer(serviceClient, dataSource, skillset, demoIndex);
800736
```
801737
90 Bytes
Loading
-4.19 KB
Loading

0 commit comments

Comments
 (0)