3 - Deploy the search-enabled .NET website
Deploy the search-enabled website as an Azure Static web app. This deployment includes both the React app and the Function app.
The Static Web app pulls the information and files for deployment from GitHub using your fork of the samples repository.
Create a Static Web App in Visual Studio Code
Select Azure from the Activity Bar, then select Static Web Apps from the Side bar.
Right-click on the subscription name then select Create Static Web App (Advanced).
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.
This setting means only changes you commit to that branch are deployed to your static web app.
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.
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.
Follow the prompts to provide the following information:
Prompt Enter 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.Select a resource group for new resources. Use the resource group you created for this tutorial. Select a SKU Select the free SKU for this tutorial. Choose build preset to configure default project structure. Select Custom Select the location of your application code search-website
This is the path, from the root of the repository, to your Azure Static web app.Select the location of your Azure Function code search-website/api
This is the path, from the root of the repository, to your Azure Function app.Enter the path of your build output... build
This is the path, from your Azure Static web app, to your generated files.Select a location for new resources. Select a region close to you. The resource is created, select Open Actions in GitHub from the Notifications. This opens a browser window pointed to your forked repo.
The list of actions indicates your web app, both client and functions, were successfully pushed to your Azure Static Web App.
Wait until the build and deployment complete before continuing. This may take a minute or two to finish.
Get Cognitive Search query key in Visual Studio Code
In Visual Studio Code, open the Activity bar, and select the Azure icon.
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.
Keep this query key, you will need to use it in the next section. The query key is able to query your Index.
Add configuration settings in Azure portal
The Azure Function app won't return Search data until the Search secrets are in settings.
Select Azure from the Activity Bar.
Right-click on your Static web app resource then select Open in Portal.
Select Configuration then select + Add.
Add each of the following settings:
Setting Your Search resource value SearchApiKey Your Search query key SearchServiceName Your Search resource name SearchIndexName good-booksSearchFacets authors*,language_codeAzure 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 typeCollection(Edm.String). This allows the Azure Function to add filters correctly to queries.Select Save to save the settings.
Return to VS Code.
Refresh your Static web app to see the Static web app's application settings.
Use search in your Static web app
In Visual Studio Code, open the Activity bar, and select the Azure icon.
In the Side bar, right-click on your Azure subscription under the
Static web appsarea and find the Static web app you created for this tutorial.Right-click the Static Web App name and select Browse site.
Select Open in the pop-up dialog.
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.Review the results then select one of the books to see more details.
Clean up resources
To clean up the resources created in this tutorial, delete the resource group.
In Visual Studio Code, open the Activity bar, and select the Azure icon.
In the Side bar, right-click on your Azure subscription under the
Resource Groupsarea and find the resource group you created for this tutorial.Right-click the resource group name then select Delete. This deletes both the Search and Static web app resources.
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.
Next steps
Povratne informacije
Pošalјite i prikažite povratne informacije za