Skip to content

Commit 958825f

Browse files
Merge pull request #251317 from diberry/diberry/0912-search-materialui-updates
Search - Add search to website - updates - JS
2 parents 8e6c9f7 + 24e658d commit 958825f

4 files changed

+45
-23
lines changed

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

Lines changed: 6 additions & 6 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/29/2023
10+
ms.date: 09/13/2023
1111
ms.custom: devx-track-js, devx-track-azurecli, devx-track-azurepowershell
1212
ms.devlang: javascript
1313
---
@@ -18,7 +18,7 @@ Continue to build your search-enabled website by following these steps:
1818

1919
* Create a search resource
2020
* Create a new index
21-
* Import data with JavaScript using the [bulk_insert_books script](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/main/search-website-functions-v4/bulk-insert-v4/bulk_insert_books.js) and Azure SDK [@azure/search-documents](https://www.npmjs.com/package/@azure/search-documents).
21+
* Import data with JavaScript using the [bulk_insert_books script](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/main/search-website-functions-v4/bulk-insert/bulk_insert_books.js) and Azure SDK [@azure/search-documents](https://www.npmjs.com/package/@azure/search-documents).
2222

2323
## Create an Azure Cognitive Search resource
2424

@@ -31,22 +31,22 @@ The ESM script uses the Azure SDK for Cognitive Search:
3131
* [npm package @azure/search-documents](https://www.npmjs.com/package/@azure/search-documents)
3232
* [Reference Documentation](/javascript/api/overview/azure/search-documents-readme)
3333

34-
1. In Visual Studio Code, open the `bulk_insert_books.js` file in the subdirectory, `search-website-functions-v4/bulk-insert-v4`, replace the following variables with your own values to authenticate with the Azure Search SDK:
34+
1. In Visual Studio Code, open the `bulk_insert_books.js` file in the subdirectory, `search-website-functions-v4/bulk-insert`, replace the following variables with your own values to authenticate with the Azure Search SDK:
3535

3636
* YOUR-SEARCH-RESOURCE-NAME
3737
* YOUR-SEARCH-ADMIN-KEY
3838

39-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/bulk-insert-v4/bulk_insert_books.js" :::
39+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/bulk-insert/bulk_insert_books.js" :::
4040

41-
1. Open an integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-insert-v4`, and run the following command to install the dependencies.
41+
1. Open an integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-insert`, and run the following command to install the dependencies.
4242

4343
```bash
4444
npm install
4545
```
4646

4747
## Run the bulk import script for Search
4848

49-
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-insert-v4`, to run the following bash command to run the `bulk_insert_books.js` script:
49+
1. Continue using the integrated terminal in Visual Studio for the project directory's subdirectory, `search-website-functions-v4/bulk-insert`, to run the `bulk_insert_books.js` script:
5050
5151
```javascript
5252
npm start

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

Lines changed: 1 addition & 1 deletion
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/29/2023
10+
ms.date: 09/13/2023
1111
ms.custom: devx-track-js
1212
ms.devlang: javascript
1313
---

articles/search/tutorial-javascript-overview.md

Lines changed: 4 additions & 4 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/29/2023
10+
ms.date: 09/13/2023
1111
ms.custom: devx-track-js
1212
ms.devlang: javascript
1313
---
@@ -30,9 +30,9 @@ The [sample](https://github.com/Azure-Samples/azure-search-javascript-samples/tr
3030

3131
|App|Purpose|GitHub<br>Repository<br>Location|
3232
|--|--|--|
33-
|Client|React app (presentation layer) to display books, with search. It calls the Azure Function app. |[/search-website-functions-v4/client-v4](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/search-website-functions-v4/client-v4)|
34-
|Server|Azure Function app (business layer) - calls the Azure Cognitive Search API using JavaScript SDK |[/search-website-functions-v4/api-v4](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/search-website-functions-v4/api-v4)|
35-
|Bulk insert|JavaScript file to create the index and add documents to it.|[/search-website-functions-v4/bulk-insert-v4](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/search-website-functions-v4/bulk-insert-v4)|
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-javascript-samples/tree/master/search-website-functions-v4/client)|
34+
|Server|Azure Function app (business layer) - calls the Azure Cognitive Search API using JavaScript SDK |[/search-website-functions-v4/api](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/search-website-functions-v4/api)|
35+
|Bulk insert|JavaScript file to create the index and add documents to it.|[/search-website-functions-v4/bulk-insert](https://github.com/Azure-Samples/azure-search-javascript-samples/tree/master/search-website-functions-v4/bulk-insert)|
3636

3737
## Set up your development environment
3838

articles/search/tutorial-javascript-search-query-integration.md

Lines changed: 34 additions & 12 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/29/2023
10+
ms.date: 09/13/2023
1111
ms.custom: devx-track-js
1212
ms.devlang: javascript
1313
---
@@ -29,47 +29,69 @@ The Function app authenticates through the SDK to the cloud-based Cognitive Sear
2929

3030
## Configure secrets in a configuration file
3131

32-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api-v4/src/lib/config.js":::
32+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api/src/lib/config.js":::
3333

3434
## Azure Function: Search the catalog
3535

36-
The [Search API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api-v4/src/functions/search.js) takes a search term and searches across the documents in the search index, returning a list of matches.
36+
The [Search API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api/src/functions/search.js) takes a search term and searches across the documents in the search index, returning a list of matches.
3737

3838
The Azure Function pulls in the search configuration information, and fulfills the query.
3939

40-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api-v4/src/functions/search.js" :::
40+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api/src/functions/search.js" :::
4141

4242
## Client: Search from the catalog
4343

4444
Call the Azure Function in the React client with the following code.
4545

46-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client-v4/src/pages/Search/Search.js" highlight="41-52" :::
46+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client/src/pages/Search.js" highlight="88-100" :::
47+
48+
## Client: Facets from the catalog
49+
50+
This React component includes the search textbox and the [**facets**](search-faceted-navigation.md) associated with the search results. Facets need to be thought out and designed as part of the search schema when the search data is loaded. Then the facets are used in the search query, along with the search text, to provide the faceted navigation experience.
51+
52+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client/src/components/Facets/Facets.js" highlight="49-76" :::
53+
54+
## Client: Pagination from the catalog
55+
56+
When the search results expand beyond a trivial few (8), the `@mui/material/TablePagination` component provides **pagination** across the results.
57+
58+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client/src/components/Pager.js" highlight="27" :::
59+
60+
When the user changes the page, that value is sent to the parent `Search.js` page from the `handleChangePage` function. The function sends a new request to the search API for the same query and the new page. The API response updates the facets, results, and pager components.
4761

4862
## Azure Function: Suggestions from the catalog
4963

50-
The [Suggest API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api-v4/src/functions/suggest.js) 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.
64+
The [Suggest API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api/src/functions/suggest.js) 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.
5165

52-
The search suggester, `sg`, is defined in the [schema file](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/bulk-insert-v4/good-books-index.json) used during bulk upload.
66+
The search suggester, `sg`, is defined in the [schema file](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/bulk-insert/good-books-index.json) used during bulk upload.
5367

54-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api-v4/src/functions/suggest.js" :::
68+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api/src/functions/suggest.js" :::
5569

5670
## Client: Suggestions from the catalog
5771

5872
The Suggest function API is called in the React app at `\src\components\SearchBar\SearchBar.js` as part of component initialization:
5973

60-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client-v4/src/components/SearchBar/SearchBar.js" highlight="52-60" :::
74+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client/src/components/SearchBar.js" highlight="40-55, 75-117" :::
75+
76+
This React component uses the `@mui/material/Autocomplete` component to provide a search textbox, which also supports displaying suggestions (using the `renderInput` function). Autocomplete starts after the first several characters are entered. As each new character is entered, it's sent as a query to the search engine. The results are displayed as a short list of suggestions.
77+
78+
This autocomplete functionality is a common feature but this specific implementation has an additional use case. The customer can enter text and select from the suggestions _or_ submit their entered text. The input from the suggestion list as well as the input from the textbox must be tracked for changes, which impact how the form is rendered and what is sent to the **search** API when the form is submitted.
79+
80+
If your use case for search allows your user to select only from the suggestions, that will reduce the scope of complexity of the control but limit the user experience.
6181

6282
## Azure Function: Get specific document
6383

64-
The [Lookup API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api-v4/src/functions/lookup.js) takes an ID and returns the document object from the search index.
84+
The [Lookup API](https://github.com/Azure-Samples/azure-search-javascript-samples/blob/master/search-website-functions-v4/api/src/functions/lookup.js) takes an ID and returns the document object from the search index.
6585

66-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api-v4/src/functions/lookup.js" :::
86+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/api/src/functions/lookup.js" :::
6787

6888
## Client: Get specific document
6989

7090
This function API is called in the React app at `\src\pages\Details\Detail.js` as part of component initialization:
7191

72-
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client-v4/src/pages/Details/Details.js" highlight="20-30" :::
92+
:::code language="javascript" source="~/azure-search-javascript-samples/search-website-functions-v4/client/src/pages/Details.js" highlight="17-21,28" :::
93+
94+
If your client app can use pregenerated content, this page is a good candidate for autogeneration because the content is static, pulled directly from the search index.
7395

7496
## Next steps
7597

0 commit comments

Comments
 (0)