Skip to content

Commit a1a8d73

Browse files
Merge pull request #216905 from diberry/diberry/1102-search-py
Cog Search - search website - PY
2 parents 0c355a0 + 1786467 commit a1a8d73

File tree

4 files changed

+46
-165
lines changed

4 files changed

+46
-165
lines changed

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

Lines changed: 16 additions & 22 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: 11/17/2021
10+
ms.date: 11/02/2022
1111
ms.custom: devx-track-python
1212
ms.devlang: python
1313
---
1414

1515
# 2 - Create and load Search Index with Python
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 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/).
2021

2122
## Create an Azure Cognitive 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, 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, right-click on your Search resource and select Copy Admin Key.":::
4950

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).
5152

5253
## Prepare the bulk import script for Search
5354

@@ -56,14 +57,14 @@ The script uses the Azure SDK for Cognitive Search:
5657
* [PYPI package azure-search-documents](https://pypi.org/project/azure-search-documents/)
5758
* [Reference Documentation](/python/api/azure-search-documents)
5859

59-
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:
6061

6162
* YOUR-SEARCH-SERVICE-NAME
6263
* YOUR-SEARCH-SERVICE-ADMIN-API-KEY
6364

64-
:::code language="python" source="~/azure-search-python-samples/search-website/bulk-upload/bulk-upload.py" highlight="20,21,69,83,135" :::
65+
:::code language="python" source="~/azure-search-python-samples/search-website-functions-v4/bulk-upload/bulk-upload.py" highlight="20-22,46-48,53-54,75-80,83,69,83,135,142" :::
6566

66-
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.
6768

6869
# [macOS/Linux](#tab/linux-install)
6970

@@ -79,7 +80,7 @@ The script uses the Azure SDK for Cognitive Search:
7980

8081
## Run the bulk import script for Search
8182

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:
8384
8485
# [macOS/Linux](#tab/linux-run)
8586
@@ -95,26 +96,19 @@ The script uses the Azure SDK for Cognitive Search:
9596
9697
9798
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".
99100
100101
## Review the new Search Index
101102
102-
Once the upload completes, the search index is ready to use. Review your new index.
103+
[!INCLUDE [tutorial-load-index-review-index](includes/tutorial-add-search-website-load-index-review.md)]
103104
104-
1. In Visual Studio Code, open the Azure Cognitive Search extension and select your Search resource.
105+
## Rollback bulk import file changes
105106
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.":::
107+
[!INCLUDE [tutorial-load-index-rollback](includes/tutorial-add-search-website-load-index-rollback-changes.md)]
111108
112109
## Copy your Search resource name
113110
114-
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.
111+
[!INCLUDE [tutorial-load-index-copy](includes/tutorial-add-search-website-load-index-copy-resource-name.md)]
118112
119113
## Next steps
120114

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

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -7,110 +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/02/2022
1111
ms.custom: devx-track-python
1212
ms.devlang: python
1313
---
1414

1515
# 3 - Deploy the search-enabled Python 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. 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.
113-
17+
[!INCLUDE [tutorial-deploy](includes/tutorial-add-search-website-create-app.md)]
11418

11519
## Next steps
11620

articles/search/tutorial-python-overview.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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/02/2022
1111
ms.custom: devx-track-python
1212
ms.devlang: python
1313
---
@@ -17,30 +17,22 @@ ms.devlang: python
1717
This tutorial builds a website to search through a catalog of books then deploys the website to an Azure Static Web App.
1818

1919
The application is available:
20-
* [Sample](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website)
20+
* [Sample](https://github.com/Azure-Samples/azure-search-python-samples/tree/master/search-website-functions-v4)
2121
* [Demo website - aka.ms/azs-good-books](https://aka.ms/azs-good-books)
2222

2323
## What does the sample do?
2424

25-
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.
25+
[!INCLUDE [tutorial-overview](includes/tutorial-add-search-website-what-sample-does.md)]
3426

3527
## How is the sample organized?
3628

37-
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:
3830

3931
|App|Purpose|GitHub<br>Repository<br>Location|
4032
|--|--|--|
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)|
4436

4537
## Set up your development environment
4638

@@ -49,8 +41,7 @@ Install the following for your local development environment.
4941
- [Python 3.9](https://www.python.org/downloads/)
5042
- [Git](https://git-scm.com/downloads)
5143
- [Visual Studio Code](https://code.visualstudio.com/) and the following extensions
52-
- [Azure Resources](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureresourcegroups)
53-
- [Azure Cognitive Search 0.2.0+](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurecognitivesearch)
44+
- [Azure Cognitive Search](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurecognitivesearch)
5445
- [Azure Static Web App](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps)
5546
- Optional:
5647
- 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
7566

7667
## Create a resource group for your Azure resources
7768

78-
1. In Visual Studio Code, open the [Activity bar](https://code.visualstudio.com/docs/getstarted/userinterface), and select the Azure icon.
79-
1. In Resources, select Add (**+**), and then select **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.
69+
[!INCLUDE [tutorial-create-resource-group](includes/tutorial-add-search-website-create-resource-group.md)]
8770

8871
## Next steps
8972

0 commit comments

Comments
 (0)