Skip to content

Commit aefad61

Browse files
authored
Merge pull request #249696 from HeidiSteen/heidist-js
[azure search] Search web appt tutorial (workaround for SWA YML path issue)
2 parents a43e5ad + c27aeee commit aefad61

18 files changed

+127
-93
lines changed

articles/search/includes/tutorial-add-search-website-create-app.md

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
ms.topic: include
3-
ms.date: 07/18/2023
3+
ms.date: 08/29/2023
44
author: HeidiSteen
55
ms.author: heidist
66
ms.service: cognitive-search
@@ -12,73 +12,108 @@ The static web app pulls the information and files for deployment from GitHub us
1212

1313
## Create a Static Web App in Visual Studio Code
1414

15-
1. Select **Azure** from the Activity Bar, then open **Resources** from the Side bar.
15+
1. In Visual Studio Code, open a folder at the repository root (`azure-search-javascript-samples`).
1616

17-
1. Right-click **Static Web Apps** and then select **Create Static Web App (Advanced)**.
17+
1. Select **Azure** from the Activity Bar, then open **Resources** from the side bar.
18+
19+
1. Right-click **Static Web Apps** and then select **Create Static Web App (Advanced)**. If you don't see this option, verify that you have the Azure Functions extension for Visual Studio Code.
1820

1921
:::image type="content" source="../media/tutorial-javascript-create-load-index/visual-studio-code-create-static-web-app-resource-advanced.png" alt-text="Screenshot of Visual Studio Code, with the Azure Static Web Apps explorer showing the option to create an advanced static web app.":::
2022

21-
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**.
23+
1. If you see a pop-up window in Visual Studio Code asking which branch you want to deploy from, select the default branch, usually **main**.
2224

2325
This setting means only changes you commit to that branch are deployed to your static web app.
2426

2527
1. If you see a pop-up window asking you to commit your changes, don't do this. The secrets from the bulk import step shouldn't be committed to the repository.
2628

27-
To roll back 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.
29+
To roll back the changes, in Visual Studio 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.
2830

29-
1. Follow the prompts to provide the following information:
31+
1. Follow the prompts to create the static web app:
3032

3133
|Prompt|Enter|
3234
|--|--|
33-
|Select a resource group for new resources.|Use the resource group you created for this tutorial.|
34-
|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`. |
35-
|Select a SKU| Select the free SKU for this tutorial.|
36-
|Select a location for new resources.|For Node.js: Select `West US 2` during the Azure Function programming model (PM) v4 preview. For C# and Python, select a region near you.|
37-
|Choose build preset to configure default project structure.|Select **Custom**|
38-
|Select the location of your application code|`search-website-functions-v4/client-v4`<br><br>This is the path, from the root of the repository, to your static web app. |
39-
|Select the location of your Azure Functions code|`search-website-functions-v4/api-v4`<br><br>This is the path, from the root of the repository, to your static web app. |
40-
|Enter the path of your build output...|`build`<br><br>This is the path, from your static web app, to your generated files.|
35+
|Select a resource group for new resources. | Use the resource group you created for this tutorial.|
36+
|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, `my-demo-static-web-app`. |
37+
|Select a SKU | Select the free SKU for this tutorial.|
38+
|Select a location for new resources. | For Node.js: Select `West US 2` during the Azure Function programming model (PM) v4 preview. For C# and Python, select a region near you. |
39+
|Choose build preset to configure default project structure. |Select **Custom**. |
40+
|Select the location of your client application code | `search-website-functions-v4/client-v4`<br><br>This is the path, from the root of the repository, to your static web app. |
41+
|Select the location of your Azure Functions code | `search-website-functions-v4/api-v4`<br><br>This is the path, from the root of the repository, to your static web app. If there are no other functions in the repository, you won't be prompted for the function code location. Currently, you'll need to perform extra steps to ensure the function code location is correct. These steps are performed after the resource is created and are documented in this article. |
42+
|Enter the path of your build output... | `build`<br><br>This is the path, from your static web app, to your generated files.|
43+
44+
If you get an error about an incorrect region, make sure the resource group and static web app resource are in one of the supported regions listed in the error response.
45+
46+
1. When the static web app is created, a GitHub workflow YML file is also created locally and on GitHub in your fork. This workflow executes in your fork, building and deploying the static web app and functions.
47+
48+
Check the status of static web app deployment using any of these approaches:
49+
50+
* Select **Open Actions in GitHub** from the Notifications. This opens a browser window pointed to your forked repo.
51+
* Select the **Actions** tab in your forked repository. You should see a list of all workflows on your fork.
52+
* Select the **Azure: Activity Log** in Visual Code. You should see a message similar to the following screenshot.
53+
54+
:::image type="content" source="../media/tutorial-javascript-static-web-app/visual-studio-code-azure-activity-log.png" alt-text="Screenshot of the Activity Log in Visual Studio Code." border="true":::
55+
56+
1. Currently, the YML file is created with erroneous path syntax for the Azure function code. Use this workaround to correct the syntax. You can perform this step as soon as the YML file is created. A new workflow will launch as soon as you push the updates:
4157

42-
If you get an error about an incorrect region, make sure the resource group and Static web app resource are in one of the supported regions listed in the error response.
58+
1. In Visual Studio Code explorer, open the `./.github/workflows/` directory.
4359

44-
1. The resource is created and a notification window appears.
60+
1. Open the YML file.
4561

46-
When the resource is created, it creates a GitHub action file on GitHub.
62+
1. Scroll to the `api-location` path (on or near line 31).
4763

48-
1. Select **Open Actions in GitHub** from the Notifications. This opens a browser window pointed to your forked repo.
64+
1. Change the path syntax to use a forward slash (only `api_location` needs editing, other locations are here for context):
4965

50-
Wait until the _workflow_ completes before continuing. This may take a minute or two to finish.
66+
```yml
67+
app_location: "search-website-functions-v4/client-v4" # App source code path
68+
api_location: "search-website-functions-v4/api-v4" # Api source code path - optional
69+
output_location: "build" # Built app content directory - optional
70+
```
5171
52-
1. Pull the new GitHub action file to your local computer by synchronizing your local fork with your remote fork:
72+
1. Save the file.
73+
74+
1. Open an integrated terminal and issue the following GitHub commands to send the updated YML to your fork:
75+
76+
```bash
77+
git add -A
78+
git commit -m "fix path"
79+
git push origin main
80+
```
81+
82+
:::image type="content" source="../media/tutorial-javascript-static-web-app/git-yml-path-workaround.png" alt-text="Screenshot of the GitHub commands in Visual Studio Code." border="true":::
83+
84+
Wait until the workflow execution completes before continuing. This may take a minute or two to finish.
85+
86+
<!-- 1. Pull the new GitHub action file to your local computer by synchronizing your local fork with your remote fork:
5387

5488
```bash
5589
git pull origin main
5690
```
5791

5892
* _origin_ refers to your forked repo.
5993
* _main_ refers to the default branch.
94+
-->
6095

61-
1. In Visual Studio file explorer, find and open the workflow file in the `./.github/workflows/` directory. The file path and name looks _something_ `.github\workflows\azure-static-web-apps-lemon-mushroom-0e1bd060f.yml`.
96+
<!-- 1. In Visual Studio file explorer, find and open the workflow file in the `./.github/workflows/` directory. The file path and name looks _something_ `.github\workflows\azure-static-web-apps-lemon-mushroom-0e1bd060f.yml`.
6297

6398
The _part_ of the YAML file relevant to the static web app is shown below:
6499

65-
:::code language="yml" source="~/azure-search-javascript-samples/search-website-functions-v4/example-github-action-v4.yml":::
100+
:::code language="yml" source="~/azure-search-javascript-samples/search-website-functions-v4/example-github-action-v4.yml"::: -->
66101

67102
## Get Cognitive Search query key in Visual Studio Code
68103

69104
1. In Visual Studio Code, open a new terminal window.
70105

71-
1. Get the Query Key with this Azure CLI command:
106+
1. Get the query API key with this Azure CLI command:
72107

73108
```azurecli
74109
az search query-key list --resource-group cognitive-search-demo-rg --service-name my-cog-search-demo-svc
75110
```
76111

77-
1. Keep this query key, you'll need to use it in the next section. The query key is able to query your Index.
112+
1. Keep this query key to use in the next section. The query key authorizes read access to a search index.
78113

79114
## Add configuration settings in Azure portal
80115

81-
The Azure Function app won't return Search data until the Search secrets are in settings.
116+
The Azure Function app won't return search data until the search secrets are in settings.
82117

83118
1. Select **Azure** from the Activity Bar.
84119
1. Right-click on your Static Web Apps resource then select **Open in Portal**.
@@ -93,21 +128,22 @@ The Azure Function app won't return Search data until the Search secrets are in
93128

94129
|Setting|Your Search resource value|
95130
|--|--|
96-
|SearchApiKey|Your Search query key|
97-
|SearchServiceName|Your Search resource name|
131+
|SearchApiKey|Your search query key|
132+
|SearchServiceName|Your search resource name|
98133
|SearchIndexName|`good-books`|
99134
|SearchFacets|`authors*,language_code`|
100135

101136
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.
102137

103138
1. Select **Save** to save the settings.
104139

105-
:::image type="content" source="../media/tutorial-javascript-static-web-app/save-new-application-setting-to-static-web-app-in-portal.png" alt-text="Screenshot of browser showing Azure portal with the button to save the settings for your app..":::
140+
:::image type="content" source="../media/tutorial-javascript-static-web-app/save-new-application-setting-to-static-web-app-in-portal.png" alt-text="Screenshot of browser showing Azure portal with the button to save the settings for your app.":::
141+
142+
1. Return to Visual Studio Code.
106143

107-
1. Return to VS Code.
108-
1. Refresh your static web app to see the application settings.
144+
1. Refresh your static web app to see the application settings and functions.
109145

110-
:::image type="content" source="../media/tutorial-javascript-static-web-app/visual-studio-code-extension-fresh-resource.png" alt-text="Screenshot of Visual Studio Code showing the Azure Static Web Apps explorer with the new application settings.":::
146+
:::image type="content" source="../media/tutorial-javascript-static-web-app/visual-studio-code-extension-fresh-resource-2.png" alt-text="Screenshot of Visual Studio Code showing the Azure Static Web Apps explorer with the new application settings." border="true":::
111147

112148
## Use search in your static web app
113149

@@ -121,7 +157,6 @@ The Azure Function app won't return Search data until the Search secrets are in
121157
1. In the website search bar, enter a search query such as `code`, 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.
122158
1. Review the results then select one of the books to see more details.
123159

124-
125160
## Troubleshooting
126161

127162
[!INCLUDE [tutorial-troubleshooting](tutorial-add-search-website-troubleshooting.md)]

articles/search/includes/tutorial-add-search-website-fork-and-clone.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

articles/search/includes/tutorial-add-search-website-troubleshooting.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ If the web app didn't deploy or work, use the following list to determine and fi
1010

1111
* **Did the deployment succeed?**
1212

13-
In order to determine if your deployment succeeded, you need to go to _your_ fork of the sample repo and review the success or failure of the GitHub action. There should be only 1 action and it should have static web app settings for the `app_location`, `api_location`, and `output_location`. If the action didn't deploy successfully, dive into the action logs and look for the last failure.
13+
In order to determine if your deployment succeeded, you need to go to _your_ fork of the sample repo and review the success or failure of the GitHub action. There should be only one action and it should have static web app settings for the `app_location`, `api_location`, and `output_location`. If the action didn't deploy successfully, dive into the action logs and look for the last failure.
1414

1515
* **Does the client (front-end) application work?**
1616

17-
You should be able to get to your web app and it should successfully display. If the deployment succeeded but the website doesn't display, this may be an issue with how the static web app is configured for rebuilding the app, once it is on Azure.
17+
You should be able to get to your web app and it should successfully display. If the deployment succeeded but the website doesn't display, this may be an issue with how the static web app is configured for rebuilding the app, once it is on Azure.
1818

1919
* **Does the API (serverless back-end) application work?**
2020

21-
You should be able to interact with the client app, searching for books and filtering. If the form doesn't return any values, open the browser's developer tools, and determine if the HTTP calls to the API were successful. If the calls weren't successful, the most likely reason if the static web app configurations for the API endpoint name and Search query key are incorrect.
21+
You should be able to interact with the client app, searching for books and filtering. If the form doesn't return any values, open the browser's developer tools, and determine if the HTTP calls to the API were successful. If the calls weren't successful, the most likely reason if the static web app configurations for the API endpoint name and Search query key are incorrect.
22+
23+
If the path to the Azure function code (`api_location`) isn't correct in the YML file, the application loads but won't call any of the functions that provide integration with Cognitive Search. Revisit the workaround in the deployment section for help with correcting the path.

articles/search/includes/tutorial-add-search-website-what-sample-does.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ ms.service: cognitive-search
77
---
88
This sample website provides access to a catalog of 10,000 books. A user can search the catalog by entering text in the search bar. While the user enters text, the website uses the search index's suggest feature to complete the text. Once the query finishes, the list of books is displayed with a portion of the details. A user can select a book to see all the details, stored in the search index, of the book.
99

10-
:::image type="content" source="../media/tutorial-javascript-overview/cognitive-search-enabled-book-website.png" alt-text="This sample website provides access to a catalog of 10,000 books. A user can search the catalog by entering text in the search bar. While the user enters text, the website uses the search index's suggest feature to complete the text. Once the search finishes, the list of books is displayed with a portion of the details. A user can select a book to see all the details, stored in the search index, of the book.":::
10+
:::image type="content" source="../media/tutorial-javascript-overview/cognitive-search-enabled-book-website-2.png" alt-text="Screenshot of the sample app in a browser window.":::
1111

12-
The search experience includes:
12+
The search experience includes:
1313

1414
* Search – provides search functionality for the application.
1515
* Suggest – provides suggestions as the user is typing in the search bar.
16+
* Facets and filters - provides a faceted navigation structure that filters by author or language.
17+
* Paginated results - provides paging controls for scrolling through results.
1618
* Document Lookup – looks up a document by ID to retrieve all of its contents for the details page.
9.74 KB
Loading
Loading
290 KB
Loading
-14.7 KB
Loading
Loading
30.5 KB
Loading

0 commit comments

Comments
 (0)