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/tutorial-add-search-website-create-app.md
+67-32Lines changed: 67 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
ms.topic: include
3
-
ms.date: 07/18/2023
3
+
ms.date: 08/29/2023
4
4
author: HeidiSteen
5
5
ms.author: heidist
6
6
ms.service: cognitive-search
@@ -12,73 +12,108 @@ The static web app pulls the information and files for deployment from GitHub us
12
12
13
13
## Create a Static Web App in Visual Studio Code
14
14
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`).
16
16
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.
18
20
19
21
:::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.":::
20
22
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**.
22
24
23
25
This setting means only changes you commit to that branch are deployed to your static web app.
24
26
25
27
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.
26
28
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.
28
30
29
-
1. Follow the prompts to provide the following information:
31
+
1. Follow the prompts to create the static web app:
30
32
31
33
|Prompt|Enter|
32
34
|--|--|
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. |
|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:
41
57
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.
43
59
44
-
1. The resource is created and a notification window appears.
60
+
1. Open the YML file.
45
61
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).
47
63
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):
49
65
50
-
Wait until the _workflow_ completes before continuing. This may take a minute or two to finish.
api_location: "search-website-functions-v4/api-v4"# Api source code path - optional
69
+
output_location: "build"# Built app content directory - optional
70
+
```
51
71
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:
53
87
54
88
```bash
55
89
git pull origin main
56
90
```
57
91
58
92
* _origin_ refers to your forked repo.
59
93
* _main_ refers to the default branch.
94
+
-->
60
95
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`.
62
97
63
98
The _part_ of the YAML file relevant to the static web app is shown below:
## Get Cognitive Search query key in Visual Studio Code
68
103
69
104
1. In Visual Studio Code, open a new terminal window.
70
105
71
-
1. Get the Query Key with this Azure CLI command:
106
+
1. Get the query API key with this Azure CLI command:
72
107
73
108
```azurecli
74
109
az search query-key list --resource-group cognitive-search-demo-rg --service-name my-cog-search-demo-svc
75
110
```
76
111
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 keyto use in the next section. The query key authorizes read access to a search index.
78
113
79
114
## Add configuration settings in Azure portal
80
115
81
-
The Azure Function app won't returnSearch 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.
82
117
83
118
1. Select **Azure** from the Activity Bar.
84
119
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
93
128
94
129
|Setting|Your Search resource value|
95
130
|--|--|
96
-
|SearchApiKey|Your Search query key|
97
-
|SearchServiceName|Your Search resource name|
131
+
|SearchApiKey|Your search query key|
132
+
|SearchServiceName|Your search resource name|
98
133
|SearchIndexName|`good-books`|
99
134
|SearchFacets|`authors*,language_code`|
100
135
101
136
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.
102
137
103
138
1. Select **Save** to save the settings.
104
139
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.
106
143
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.
109
145
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":::
111
147
112
148
## Use search in your static web app
113
149
@@ -121,7 +157,6 @@ The Azure Function app won't return Search data until the Search secrets are in
121
157
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.
122
158
1. Review the results then select one of the books to see more details.
Copy file name to clipboardExpand all lines: articles/search/includes/tutorial-add-search-website-troubleshooting.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,14 @@ If the web app didn't deploy or work, use the following list to determine and fi
10
10
11
11
***Did the deployment succeed?**
12
12
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.
14
14
15
15
***Does the client (front-end) application work?**
16
16
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.
18
18
19
19
***Does the API (serverless back-end) application work?**
20
20
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.
Copy file name to clipboardExpand all lines: articles/search/includes/tutorial-add-search-website-what-sample-does.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,12 @@ ms.service: cognitive-search
7
7
---
8
8
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.
9
9
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.":::
11
11
12
-
The search experience includes:
12
+
The search experience includes:
13
13
14
14
* Search – provides search functionality for the application.
15
15
* 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.
16
18
* Document Lookup – looks up a document by ID to retrieve all of its contents for the details page.
0 commit comments