title | titleSuffix | description | manager | author | ms.author | ms.service | ms.topic | ms.date | ms.custom | ms.devlang | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Explore code (.NET tutorial) |
Azure AI Search |
Understand the .NET SDK Search integration queries used in the Search-enabled website with this cheat sheet. |
nitinme |
diberry |
diberry |
cognitive-search |
tutorial |
04/25/2024 |
|
csharp |
In the previous lessons, you added search to a Static Web App. This lesson highlights the essential steps that establish integration. If you're looking for a cheat sheet on how to integrate search into your web app, this article explains what you need to know.
The application is available:
The Function app uses the Azure SDK for Azure AI Search:
- NuGet: Azure.Search.Documents
- Reference Documentation: Client Library
The Function app authenticates through the SDK to the cloud-based Azure AI Search API using your resource name, resource key, and index name. The secrets are stored in the Static Web App settings and pulled in to the Function as environment variables.
:::code language="json" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/local.settings.json":::
The Search
API takes a search term and searches across the documents in the Search Index, returning a list of matches.
The Azure Function pulls in the Search configuration information, and fulfills the query.
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/Search.cs" :::
Call the Azure Function in the React client with the following code.
:::code language="javascript" source="~/azure-search-dotnet-samples/search-website-functions-v4/client/src/pages/Search/Search.js" :::
The Suggest
API takes a search term while a user is typing and suggests search terms such as book titles and authors across the documents in the search index, returning a small list of matches.
The search suggester, sg
, is defined in the schema file used during bulk upload.
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/Suggest.cs" :::
The Suggest function API is called in the React app at \client\src\components\SearchBar\SearchBar.js
as part of component initialization:
:::code language="javascript" source="~/azure-search-dotnet-samples/search-website-functions-v4/client/src/components/SearchBar/SearchBar.js" :::
The Lookup
API takes an ID and returns the document object from the Search Index.
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/Lookup.cs" :::
This function API is called in the React app at \client\src\pages\Details\Detail.js
as part of component initialization:
:::code language="javascript" source="~/azure-search-dotnet-samples/search-website-functions-v4/client/src/pages/Details/Details.js" :::
The following models are used to support the functions in this app.
:::code language="csharp" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/Models.cs" :::