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/tutorial-python-create-load-index.md
+16-22Lines changed: 16 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,17 @@ author: diberry
7
7
ms.author: diberry
8
8
ms.service: cognitive-search
9
9
ms.topic: tutorial
10
-
ms.date: 11/17/2021
10
+
ms.date: 11/02/2022
11
11
ms.custom: devx-track-python
12
12
ms.devlang: python
13
13
---
14
14
15
15
# 2 - Create and load Search Index with Python
16
16
17
17
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 Python using the sample script and Azure SDK [azure-search-documents](https://pypi.org/project/azure-search-documents/).
18
+
* Create a Search resource with the VS Code extension
19
+
* Create a new index
20
+
* Import data with Python using the [sample script](https://github.com/Azure-Samples/azure-search-python-samples/blob/main/search-website-functions-v4/bulk-upload/bulk-upload.py) and Azure SDK [azure-search-documents](https://pypi.org/project/azure-search-documents/).
20
21
21
22
## Create an Azure Cognitive Search resource
22
23
@@ -26,7 +27,7 @@ Create a new Search resource with the [Azure Cognitive Search](https://marketpla
26
27
27
28
1. In the Side bar, **right-click on your Azure subscription** under the `Azure: Cognitive Search` area and select **Create new search service**.
28
29
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, right-click on your Azure subscription under the Azure: Cognitive Search area and select Create new search service.":::
30
31
31
32
1. Follow the prompts to provide the following information:
32
33
@@ -45,9 +46,9 @@ Get your Search resource admin key with the Visual Studio Code extension.
45
46
46
47
1. In Visual Studio Code, in the Side bar, right-click on your Search resource and select **Copy Admin Key**.
47
48
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, right-click on your Search resource and select Copy Admin Key.":::
49
50
50
-
1. Keep this admin key, you will need to use it to create objects in [a later section](#prepare-the-bulk-import-script-for-search).
51
+
1. Keep this admin key, you'll need to use it to create objects in [a later section](#prepare-the-bulk-import-script-for-search).
51
52
52
53
## Prepare the bulk import script for Search
53
54
@@ -56,14 +57,14 @@ The script uses the Azure SDK for Cognitive Search:
1. In Visual Studio Code, open the `bulk_upload.py` file in the subdirectory, `search-website/bulk-upload`, replace the following variables with your own values to authenticate with the Azure Search SDK:
60
+
1. In Visual Studio Code, open the `bulk_upload.py` file in the subdirectory, `search-website-functions-v4/bulk-upload`, replace the following variables with your own values to authenticate with the Azure Search SDK:
1. Open an integrated terminal in Visual Studio for the project directory's subdirectory, `search-website/bulk-upload`, and run the following command to install the dependencies.
67
+
1. Open an integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-upload`, and run the following command to install the dependencies.
67
68
68
69
# [macOS/Linux](#tab/linux-install)
69
70
@@ -79,7 +80,7 @@ The script uses the Azure SDK for Cognitive Search:
79
80
80
81
## Run the bulk import script for Search
81
82
82
-
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website/bulk-upload`, to run the following bash command to run the `bulk_upload.py` script:
83
+
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-upload`, to run the following bash command to run the `bulk_upload.py` script:
83
84
84
85
# [macOS/Linux](#tab/linux-run)
85
86
@@ -95,26 +96,19 @@ The script uses the Azure SDK for Cognitive Search:
95
96
96
97
97
98
1. As the code runs, the console displays progress.
98
-
1. When the upload is complete, the last statement printed to the console is "Done. Press any key to close the terminal.".
99
+
1. When the upload is complete, the last statement printed to the console is "Done! Upload complete".
99
100
100
101
## Review the new Search Index
101
102
102
-
Once the upload completes, the searchindex is ready to use. Review your new index.
1. In Visual Studio Code, open the Azure Cognitive Search extension and select your Search resource.
105
+
## Rollback bulk import file changes
105
106
106
-
:::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.":::
107
-
108
-
1. Expand Indexes, then Documents, then `good-books`, then select a doc to see all the document-specific data.
109
-
110
-
:::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.":::
Note your **Search resource name**. You will need this to connect the Azure Function app to your Search resource.
115
-
116
-
> [!CAUTION]
117
-
> 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.
Copy file name to clipboardExpand all lines: articles/search/tutorial-python-deploy-static-web-app.md
+2-98Lines changed: 2 additions & 98 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,110 +7,14 @@ author: diberry
7
7
ms.author: diberry
8
8
ms.service: cognitive-search
9
9
ms.topic: tutorial
10
-
ms.date: 08/30/2022
10
+
ms.date: 11/02/2022
11
11
ms.custom: devx-track-python
12
12
ms.devlang: python
13
13
---
14
14
15
15
# 3 - Deploy the search-enabled Python website
16
16
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. Follow the 8 prompts to provide the following information:
30
-
31
-
|Prompt|Enter|
32
-
|--|--|
33
-
|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-javascript-samples`. |
34
-
|Select a resource group for new resources.|Use the resource group you created for this tutorial.|
35
-
|Select a SKU| Select the free SKU for this tutorial.|
36
-
|Choose build preset to configure default project structure.|Select **Custom**|
37
-
|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. |
38
-
|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. |
39
-
|Enter the path of your build output...|`build`<br><br>This is the path, from your Azure Static web app, to your generated files.|
40
-
|Select a location for new resources.|Select a region close to you.|
41
-
42
-
1. The resource is created, select **Open Actions in GitHub** from the Notifications. This opens a browser window pointed to your forked repo.
43
-
44
-
The list of actions indicates your web app, both client and functions, were successfully pushed to your Azure Static Web App.
45
-
46
-
Wait until the build and deployment complete before continuing. This may take a minute or two to finish.
47
-
48
-
## Get Cognitive Search query key in VS Code
49
-
50
-
1. In VS Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
51
-
52
-
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**.
53
-
54
-
:::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**.":::
55
-
56
-
1. Keep this query key, you will need to use it in the next section. The query key is able to query your index.
57
-
58
-
## Add configuration settings in Azure portal
59
-
60
-
The Azure Function app won't return search data until the search secrets are in settings.
61
-
62
-
1. Select **Azure** from the Activity Bar.
63
-
1. Right-click on your Static web app resource then select **Open in Portal**.
64
-
65
-
:::image type="content" source="media/tutorial-javascript-static-web-app/open-static-web-app-in-azure-portal.png" alt-text="Right-click on your Python Static web app resource then select Open in Portal.":::
66
-
67
-
1. Select **Configuration** then select **+ Add**.
68
-
69
-
:::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 Python app.":::
70
-
71
-
1. Add each of the following settings:
72
-
73
-
|Setting|Your Search resource value|
74
-
|--|--|
75
-
|SearchApiKey|Your search query key|
76
-
|SearchServiceName|Your search resource name|
77
-
|SearchIndexName|`good-books`|
78
-
|SearchFacets|`authors*,language_code`|
79
-
80
-
Azure Cognitive Search requires different syntax for filtering collections than it does for strings. For the authors* facet, adding a * after a field name denotes that the field is of type Collection(Edm.String). This allows the Azure Function to add filters correctly to queries.
81
-
82
-
1. Select **Save** to save the settings.
83
-
84
-
:::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.":::
85
-
86
-
1. Return to VS Code.
87
-
1. Refresh your static web app to see the static web app's application settings.
88
-
89
-
:::image type="content" source="media/tutorial-javascript-static-web-app/visual-studio-code-extension-fresh-resource.png" alt-text="Refresh your Static web app to see the Static web app's application settings.":::
90
-
91
-
## Use search in your Static web app
92
-
93
-
1. In VS Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
94
-
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.
95
-
1. Right-click your static web app name and select **Browse site**.
96
-
97
-
:::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**.":::
98
-
99
-
1. Select **Open** in the pop-up dialog.
100
-
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.
101
-
1. Review the results then select one of the books to see more details.
102
-
103
-
## Clean up resources
104
-
105
-
To clean up the resources created in this tutorial, delete the resource group.
106
-
107
-
1. In VS Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
108
-
109
-
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.
110
-
1. Right-click the resource group name then select **Delete**.
111
-
This deletes both the Search and Static web app resources.
112
-
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.
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 your 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.
26
-
27
-
:::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.":::
28
-
29
-
The search experience includes:
30
-
31
-
* Search – provides search functionality for the application.
32
-
* Suggest – provides suggestions as the user is typing in the search bar.
33
-
* Document Lookup – looks up a document by ID to retrieve all of its contents for the details page.
The [sample](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website) includes the following:
29
+
The [sample](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website-functions-v4) includes the following:
38
30
39
31
|App|Purpose|GitHub<br>Repository<br>Location|
40
32
|--|--|--|
41
-
|Client|React app (presentation layer) to display books, with search. It calls the Azure Function app. |[/search-website/src](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website/src)|
42
-
|Server|Azure Function app (business layer) - calls the Azure Cognitive Search API using Python SDK |[/search-website/api](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website/src)|
43
-
|Bulk insert|Python file to create the index and add documents to it.|[/search-website/bulk-upload](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website/bulk-upload)|
33
+
|Client|React app (presentation layer) to display books, with search. It calls the Azure Function app. |[/search-website-functions-v4/client](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website-functions-v4/client)|
34
+
|Server|Azure Function app (business layer) - calls the Azure Cognitive Search API using Python SDK |[/search-website-functions-v4/api](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website-functions-v4/api)|
35
+
|Bulk insert|Python file to create the index and add documents to it.|[/search-website-functions-v4/bulk-upload](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website-functions-v4/bulk-upload)|
44
36
45
37
## Set up your development environment
46
38
@@ -49,8 +41,7 @@ Install the following for your local development environment.
49
41
-[Python 3.9](https://www.python.org/downloads/)
50
42
-[Git](https://git-scm.com/downloads)
51
43
-[Visual Studio Code](https://code.visualstudio.com/) and the following extensions
-[Azure Static Web App](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps)
55
46
- Optional:
56
47
- This tutorial doesn't run the Azure Function API locally but if you intend to run it locally, you need to install [azure-functions-core-tools](../azure-functions/functions-run-local.md?tabs=linux%2ccsharp%2cbash).
@@ -75,15 +66,7 @@ Forking the sample repository is critical to be able to deploy the static web ap
75
66
76
67
## Create a resource group for your Azure resources
77
68
78
-
1. In Visual Studio Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and selectthe Azure icon.
79
-
1. In Resources, selectAdd (**+**), and thenselect**Create Resource Group**.
80
-
81
-
:::image type="content" source="./media/tutorial-javascript-overview/visual-studio-code-create-resource-group.png" alt-text="In Resources, select Add (**+**), and then select **Create Resource Group**.":::
82
-
1. Enter a resource group name, such as `cognitive-search-website-tutorial`.
83
-
1. Select a location close to you.
84
-
1. When you create the Cognitive Search and Static Web App resources, later in the tutorial, use this resource group.
85
-
86
-
Creating a resource group gives you a logical unit to manage the resources, including deleting them when you are finished using them.
0 commit comments