Skip to content

Commit 9a31017

Browse files
authored
Merge pull request #216760 from diberry/diberry/1101-search-dotnet
Cognitive Search - add search to website - .NET
2 parents 6bec8bc + 86dcf77 commit 9a31017

7 files changed

+57
-202
lines changed

articles/search/includes/tutorial-add-search-website-load-index-copy-resource-name.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ ms.service: cognitive-search
88
Note your **Search resource name**. You'll need this to connect the Azure Function app to your search resource.
99

1010
> [!CAUTION]
11-
> While you may be tempted to use your search admin key in the Azure Function, that isn't following the principle of least privilege. The Azure Function will use the query key to conform to least privilege.
11+
> While you may be tempted to use your search admin key in the Azure Function, that isn't following the principle of least privilege. The Azure Function will use the query key to conform to least privilege.

articles/search/includes/tutorial-add-search-website-load-index-review.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ Once the upload completes, the search index is ready to use. Review your new ind
1313
:::image type="content" source="../media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-resource.png" alt-text="Screenshot of Visual Studio Code using the search extension.":::
1414

1515
1. Expand Indexes, then Documents, then `good-books`, then select a doc to see all the document-specific data.
16-
1716
:::image type="content" source="../media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-docs.png" lightbox="../media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-docs.png" alt-text="Expandable screenshot of Visual Studio Code showing documents listed in an index.":::

articles/search/tutorial-csharp-create-load-index.md

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ author: diberry
77
ms.author: diberry
88
ms.service: cognitive-search
99
ms.topic: tutorial
10-
ms.date: 08/30/2022
10+
ms.date: 11/01/2022
1111
ms.custom: devx-track-csharp
1212
ms.devlang: csharp
1313
---
1414

1515
# 2 - Create and load Search Index with .NET
1616

1717
Continue to build your Search-enabled website by:
18-
* Creating a Search resource with the VS Code extension
19-
* Creating a new index and importing data with .NET using the sample script and Azure SDK [Azure.Search.Documents](https://www.nuget.org/packages/Azure.Search.Documents/).
18+
* Create a Search resource with the VS Code extension
19+
* Create a new index
20+
* Import data with .NET using the sample script and Azure SDK [Azure.Search.Documents](https://www.nuget.org/packages/Azure.Search.Documents/).
2021

2122
## Create an Azure Search resource
2223

@@ -26,7 +27,7 @@ Create a new Search resource with the [Azure Cognitive Search](https://marketpla
2627

2728
1. In the Side bar, **right-click on your Azure subscription** under the `Azure: Cognitive Search` area and select **Create new search service**.
2829

29-
:::image type="content" source="./media/tutorial-javascript-create-load-index/visual-studio-code-create-search-resource.png" alt-text="In the Side bar, right-click on your Azure subscription under the **Azure: Cognitive Search** area and select **Create new search service**.":::
30+
:::image type="content" source="./media/tutorial-javascript-create-load-index/visual-studio-code-create-search-resource.png" alt-text="Screenshot of Visual Studio code showing the Azure explorer bar, right-click on your Azure subscription under the Azure: Cognitive Search area and select Create new search service.":::
3031

3132
1. Follow the prompts to provide the following information:
3233

@@ -45,9 +46,9 @@ Get your Search resource admin key with the Visual Studio Code extension.
4546

4647
1. In Visual Studio Code, in the Side bar, right-click on your Search resource and select **Copy Admin Key**.
4748

48-
:::image type="content" source="./media/tutorial-javascript-create-load-index/visual-studio-code-copy-admin-key.png" alt-text="In the Side bar, right-click on your Search resource and select **Copy Admin Key**.":::
49+
:::image type="content" source="./media/tutorial-javascript-create-load-index/visual-studio-code-copy-admin-key.png" alt-text="Screenshot of Visual Studio code showing the Azure explorer bar, right-click on your Search resource and select Copy Admin Key.":::
4950

50-
1. Keep this admin key, you will need to use it in [a later section](#prepare-the-bulk-import-script-for-search).
51+
1. Keep this admin key, you'll need to use it in [a later section](#prepare-the-bulk-import-script-for-search).
5152

5253
## Prepare the bulk import script for Search
5354

@@ -56,22 +57,22 @@ The script uses the Azure SDK for Cognitive Search:
5657
* [NuGet package Azure.Search.Documents](https://www.nuget.org/packages/Azure.Search.Documents/)
5758
* [Reference Documentation](/dotnet/api/overview/azure/search)
5859

59-
1. In Visual Studio Code, open the `Program.cs` file in the subdirectory, `search-website/bulk-insert`, replace the following variables with your own values to authenticate with the Azure Search SDK:
60+
1. In Visual Studio Code, open the `Program.cs` file in the subdirectory, `search-website-functions-v4/bulk-insert`, replace the following variables with your own values to authenticate with the Azure Search SDK:
6061

6162
* YOUR-SEARCH-RESOURCE-NAME
6263
* YOUR-SEARCH-ADMIN-KEY
6364

64-
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website/bulk-insert/Program.cs" highlight="16-19" :::
65+
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website-functions-v4/bulk-insert/Program.cs" highlight="16-19, 21-23, 32, 49" :::
6566

66-
1. Open an integrated terminal in Visual Studio Code for the project directory's subdirectory, `search-website/bulk-insert`, then run the following command to install the dependencies.
67+
1. Open an integrated terminal in Visual Studio Code for the project directory's subdirectory, `search-website-functions-v4/bulk-insert`, then run the following command to install the dependencies.
6768

6869
```bash
6970
dotnet restore
7071
```
7172

7273
## Run the bulk import script for Search
7374

74-
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website/bulk-insert`, to run the following bash command to run the `Program.cs` script:
75+
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-insert`, to run the following bash command to run the `Program.cs` script:
7576
7677
```bash
7778
dotnet run
@@ -82,30 +83,14 @@ The script uses the Azure SDK for Cognitive Search:
8283
8384
## Review the new Search Index
8485
85-
Once the upload completes, the Search Index is ready to use. Review your new Index.
86-
87-
1. In Visual Studio Code, open the Azure Cognitive Search extension and select your Search resource.
88-
89-
:::image type="content" source="media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-resource.png" alt-text="In Visual Studio Code, open the Azure Cognitive Search extension and open your Search resource.":::
90-
91-
1. Expand Indexes, then Documents, then `good-books`, then select a doc to see all the document-specific data.
92-
93-
:::image type="content" source="media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-docs.png" lightbox="media/tutorial-javascript-create-load-index/visual-studio-code-search-extension-view-docs.png" alt-text="Expand Indexes, then `good-books`, then select a doc.":::
94-
95-
## Copy your Search resource name
96-
97-
Note your **Search resource name**. You will need this to connect the Azure Function app to your Search resource.
98-
99-
> [!CAUTION]
100-
> While you may be tempted to use your Search admin key in the Azure Function, that isn't following the principle of least privilege. The Azure Function will use the query key to conform to least privilege.
86+
[!INCLUDE [tutorial-load-index-review-index](includes/tutorial-add-search-website-load-index-review.md)]
10187
10288
## Rollback bulk import file changes
10389
104-
Use the following git command in the VS Code integrated terminal at the `bulk-insert` directory, to rollback the changes. They are not needed to continue the tutorial and you shouldn't save or push these secrets to your repo.
90+
[!INCLUDE [tutorial-load-index-rollback](includes/tutorial-add-search-website-load-index-rollback-changes.md)]
10591
106-
```git
107-
git checkout .
108-
```
92+
## Copy your Search resource name
93+
[!INCLUDE [tutorial-load-index-copy](includes/tutorial-add-search-website-load-index-copy-resource-name.md)]
10994
11095
## Next steps
11196

articles/search/tutorial-csharp-deploy-static-web-app.md

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -7,118 +7,14 @@ author: diberry
77
ms.author: diberry
88
ms.service: cognitive-search
99
ms.topic: tutorial
10-
ms.date: 08/30/2022
10+
ms.date: 11/01/2022
1111
ms.custom: devx-track-csharp
1212
ms.devlang: csharp
1313
---
1414

1515
# 3 - Deploy the search-enabled .NET website
1616

17-
Deploy the search-enabled website as an Azure Static web app. This deployment includes both the React app and the Function app.
18-
19-
The Static Web app pulls the information and files for deployment from GitHub using your fork of the samples repository.
20-
21-
## Create a Static Web App in Visual Studio Code
22-
23-
1. Select **Azure** from the Activity Bar, then open **Resources** from the Side bar.
24-
25-
1. Right-click **Static Web Apps** and then select **Create Static Web App (Advanced)**.
26-
27-
:::image type="content" source="media/tutorial-javascript-create-load-index/visual-studio-code-create-static-web-app-resource-advanced.png" alt-text="Right-click **Static Web Apps** and then select **Create Static Web App (Advanced)**":::
28-
29-
1. If you see a pop-up window in VS Code asking which branch you want to deploy from, select the default branch, usually **master** or **main**.
30-
31-
This setting means only changes you commit to that branch are deployed to your static web app.
32-
33-
1. If you see a pop-up window asking you to commit your changes, do not do this. The secrets from the bulk import step should not be committed to the repository.
34-
35-
To rollback the changes, in VS Code select the Source Control icon in the Activity bar, then select each changed file in the Changes list and select the **Discard changes** icon.
36-
37-
1. Follow the prompts to provide the following information:
38-
39-
|Prompt|Enter|
40-
|--|--|
41-
|Enter the name for the new Static Web App.|Create a unique name for your resource. For example, you can prepend your name to the repository name such as, `joansmith-azure-search-dotnet-samples`. |
42-
|Select a resource group for new resources.|Use the resource group you created for this tutorial.|
43-
|Select a SKU| Select the free SKU for this tutorial.|
44-
|Choose build preset to configure default project structure.|Select **Custom**|
45-
|Select the location of your application code|`search-website`<br><br>This is the path, from the root of the repository, to your Azure Static web app. |
46-
|Select the location of your Azure Function code|`search-website/api`<br><br>This is the path, from the root of the repository, to your Azure Function app. |
47-
|Enter the path of your build output...|`build`<br><br>This is the path, from your Azure Static web app, to your generated files.|
48-
|Select a location for new resources.|Select a region close to you.|
49-
50-
1. The resource is created, select **Open Actions in GitHub** from the Notifications. This opens a browser window pointed to your forked repo.
51-
52-
The list of actions indicates your web app, both client and functions, were successfully pushed to your Azure Static Web App.
53-
54-
Wait until the build and deployment complete before continuing. This may take a minute or two to finish.
55-
56-
## Get Cognitive Search query key in Visual Studio Code
57-
58-
1. In Visual Studio Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
59-
60-
1. In the Side bar, select your Azure subscription under the **Azure: Cognitive Search** area, then right-click on your Search resource and select **Copy Query Key**.
61-
62-
:::image type="content" source="./media/tutorial-javascript-create-load-index/visual-studio-code-copy-query-key.png" alt-text="In the Side bar, select your Azure subscription under the **Azure: Cognitive Search** area, then right-click on your Search resource and select **Copy Query Key**.":::
63-
64-
1. Keep this query key, you will need to use it in the next section. The query key is able to query your Index.
65-
66-
## Add configuration settings in Azure portal
67-
68-
The Azure Function app won't return Search data until the Search secrets are in settings.
69-
70-
1. Select **Azure** from the Activity Bar.
71-
1. Right-click on your Static web app resource then select **Open in Portal**.
72-
73-
:::image type="content" source="media/tutorial-javascript-static-web-app/open-static-web-app-in-azure-portal.png" alt-text="Right-click on your JavaScript Static web app resource then select Open in Portal.":::
74-
75-
1. Select **Configuration** then select **+ Add**.
76-
77-
:::image type="content" source="media/tutorial-javascript-static-web-app/add-new-application-setting-to-static-web-app-in-portal.png" alt-text="Select Configuration then select Add for your JavaScript app.":::
78-
79-
1. Add each of the following settings:
80-
81-
|Setting|Your Search resource value|
82-
|--|--|
83-
|SearchApiKey|Your Search query key|
84-
|SearchServiceName|Your Search resource name|
85-
|SearchIndexName|`good-books`|
86-
|SearchFacets|`authors*,language_code`|
87-
88-
Azure Cognitive Search requires different syntax for filtering collections than it does for strings. Add a `*` after a field name to denote that the field is of type `Collection(Edm.String)`. This allows the Azure Function to add filters correctly to queries.
89-
90-
1. Select **Save** to save the settings.
91-
92-
:::image type="content" source="media/tutorial-javascript-static-web-app/save-new-application-setting-to-static-web-app-in-portal.png" alt-text="Select Save to save the settings for your JavaScript app..":::
93-
94-
1. Return to VS Code.
95-
1. Refresh your Static web app to see the Static web app's application settings.
96-
97-
:::image type="content" source="media/tutorial-javascript-static-web-app/visual-studio-code-extension-fresh-resource.png" alt-text="Refresh your JavaScript Static web app to see the Static web app's application settings.":::
98-
99-
## Use search in your Static web app
100-
101-
1. In Visual Studio Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
102-
1. In the Side bar, **right-click on your Azure subscription** under the `Static web apps` area and find the Static web app you created for this tutorial.
103-
1. Right-click the Static Web App name and select **Browse site**.
104-
105-
:::image type="content" source="media/tutorial-javascript-create-load-index/visual-studio-code-browse-static-web-app.png" alt-text="Right-click the Static Web App name and select **Browse site**.":::
106-
107-
1. Select **Open** in the pop-up dialog.
108-
1. In the website search bar, enter a search query such as `code`, _slowly_ so the suggest feature suggests book titles. Select a suggestion or continue entering your own query. Press enter when you've completed your search query.
109-
1. Review the results then select one of the books to see more details.
110-
111-
## Clean up resources
112-
113-
To clean up the resources created in this tutorial, delete the resource group.
114-
115-
1. In Visual Studio Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
116-
117-
1. In the Side bar, **right-click on your Azure subscription** under the `Resource Groups` area and find the resource group you created for this tutorial.
118-
1. Right-click the resource group name then select **Delete**.
119-
This deletes both the Search and Static web app resources.
120-
1. If you no longer want the GitHub fork of the sample, remember to delete that on GitHub. Go to your fork's **Settings** then delete the fork.
121-
17+
[!INCLUDE [tutorial-deploy](includes/tutorial-add-search-website-create-app.md)]
12218

12319
## Next steps
12420

0 commit comments

Comments
 (0)