Skip to content

Latest commit

 

History

History
87 lines (53 loc) · 4.21 KB

tutorial-csharp-search-query-integration.md

File metadata and controls

87 lines (53 loc) · 4.21 KB
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
devx-track-csharp
devx-track-dotnet
ignite-2023
csharp

Step 4 - Explore the .NET search code

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:

Azure SDK Azure.Search.Documents

The Function app uses the Azure SDK for Azure AI Search:

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.

Configure secrets in a local.settings.json file

:::code language="json" source="~/azure-search-dotnet-samples/search-website-functions-v4/api/local.settings.json":::

Azure Function: Search the catalog

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" :::

Client: Search from the catalog

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" :::

Azure Function: Suggestions from the catalog

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" :::

Client: Suggestions from the catalog

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" :::

Azure Function: Get specific document

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" :::

Client: Get specific document

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" :::

C# models to support function app

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" :::

Next steps