Skip to content

Commit 2e86367

Browse files
Merge pull request #230234 from HeidiSteen/heidist-refresh
[azure search] Misc edits to new tutorial doc
2 parents 59cd0f4 + 7ad792f commit 2e86367

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

articles/search/tutorial-csharp-create-mvc-app.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ In this tutorial, create a basic ASP.NET Core (Model-View-Controller) app that r
2020
> + Filter results
2121
> + Sort results
2222
23-
This tutorial puts the focus on several operations that execute server-side using the Search APIs. Although it's common to sort and filter in client-side script, knowing how to invoke these operations on the server gives you more options when designing the search experience.
23+
This tutorial puts the focus on server-side operations called through the Search APIs. Although it's common to sort and filter in client-side script, knowing how to invoke these operations on the server gives you more options when designing the search experience.
2424

2525
Sample code for this tutorial can be found in the [azure-search-dotnet-samples](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/create-mvc-app) repository on GitHub.
2626

2727
## Prerequisites
2828

2929
+ [Visual Studio](https://visualstudio.microsoft.com/downloads/)
3030
+ [Azure.Search.Documents NuGet package](https://www.nuget.org/packages/Azure.Search.Documents/)
31-
+ [Microsoft.Spatial NuGet package](https://www.nuget.org/packages/Microsoft.Spatial/)
3231
+ [Azure Cognitive Search](search-create-service-portal.md) <sup>1</sup>
3332
+ [Hotel samples index](search-get-started-portal.md) <sup>2</sup>
3433

35-
<sup>1</sup> The search service can be any tier, but it must have public network access.
34+
<sup>1</sup> The search service can be any tier, but it must have public network access for this tutorial.
3635

3736
<sup>2</sup> To complete this tutorial, you need to create the hotels-sample-index on your search service. Make sure the search index name is`hotels-sample-index`, or change the index name in the `HomeController.cs` file.
3837

@@ -56,13 +55,13 @@ Sample code for this tutorial can be found in the [azure-search-dotnet-samples](
5655

5756
1. Browse for `Azure.Search.Documents` and install the latest stable version.
5857

59-
1. Browse for and install the `Microsoft.Spatial` package. The sample index includes a GeoPoint data type. Installing this package avoids run time errors. Alternatively, remove the field from the Hotels class if you don't want to install the package.
58+
1. Browse for and install the `Microsoft.Spatial` package. The sample index includes a GeographyPoint data type. Installing this package avoids run time errors. Alternatively, remove the "Location" field from the Hotels class if you don't want to install the package. It's not used in this tutorial.
6059

6160
### Add service information
6261

63-
For the connection, the app presents a query API key to your fully qualified search URL specified in the `appsettings.json` file.
62+
For the connection, the app presents a query API key to your fully qualified search URL. Both are specified in the `appsettings.json` file.
6463

65-
Modify `appsettings.json` to specify your search service and query API key.
64+
Modify `appsettings.json` to specify your search service and [query API key](search-security-api-keys.md).
6665

6766
```json
6867
{
@@ -75,7 +74,7 @@ Modify `appsettings.json` to specify your search service and query API key.
7574

7675
In this step, create models that represent the schema of the hotels-search-index.
7776

78-
1. In Solution explorer, right-select **Models** and add a new class named "Hotel".
77+
1. In Solution explorer, right-select **Models** and add a new class named "Hotel" for the following code:
7978

8079
```csharp
8180
using Azure.Search.Documents.Indexes.Models;
@@ -122,7 +121,6 @@ In this step, create models that represent the schema of the hotels-search-index
122121

123122
public Rooms[] Rooms { get; set; }
124123
}
125-
126124
}
127125
```
128126

@@ -149,7 +147,6 @@ In this step, create models that represent the schema of the hotels-search-index
149147

150148
[SearchableField(IsFilterable = true, IsSortable = true, IsFacetable = true)]
151149
public string Country { get; set; }
152-
153150
}
154151
}
155152
```
@@ -193,7 +190,7 @@ In this step, create models that represent the schema of the hotels-search-index
193190
}
194191
```
195192

196-
1. Add a class named "SearchData". and replace it with the following code:
193+
1. Add a class named "SearchData" and replace it with the following code:
197194

198195
```csharp
199196
using Azure.Search.Documents.Models;
@@ -293,8 +290,8 @@ For this tutorial, modify the default `HomeController` to contain methods that e
293290
IncludeTotalCount = true
294291
};
295292

296-
// Enter Hotel property names into this list so only these values will be returned.
297-
// If Select is empty, all values will be returned, which can be inefficient.
293+
// Enter Hotel property names to specify which fields are returned.
294+
// If Select is empty, all "retrievable" fields are returned.
298295
options.Select.Add("HotelName");
299296
options.Select.Add("Category");
300297
options.Select.Add("Rating");
@@ -334,11 +331,7 @@ For this tutorial, modify the default `HomeController` to contain methods that e
334331
<img src="~/images/azure-logo.png" width="80" />
335332
<h2>Search for Hotels</h2>
336333
337-
<p>Use this demo app to test server-side behaviors, including sorting, filters, and relevance tuning. Modify the RunQueryAsnc method to change the operation.
338-
</p>
339-
340-
<p>The app connects to the sample hotels index on your search service using the default search configuration (simple search, with searchMode=Any).
341-
</p>
334+
<p>Use this demo app to test server-side sorting and filtering. Modify the RunQueryAsync method to change the operation. The app uses the default search configuration (simple search syntax, with searchMode=Any).</p>
342335
343336
<form asp-controller="Home" asp-action="Index">
344337
<p>
@@ -409,7 +402,7 @@ Index field attributes determine which fields are searchable, filterable, sortab
409402
410403
A filter always executes first, followed by a query assuming one is specified.
411404
412-
1. Open the `HomeController` and replace **RunQueryAsync** method with the following version:
405+
1. Open the `HomeController` and find the **RunQueryAsync** method. Add [Filter](/dotnet/api/azure.search.documents.searchoptions.filter) to `var options = new SearchOptions()`:
413406
414407
```csharp
415408
private async Task<ActionResult> RunQueryAsync(SearchData model)
@@ -422,8 +415,6 @@ A filter always executes first, followed by a query assuming one is specified.
422415
Filter = "search.in(Category,'Budget,Suite')"
423416
};
424417
425-
// Enter Hotel property names into this list so only these values will be returned.
426-
// If Select is empty, all values will be returned, which can be inefficient.
427418
options.Select.Add("HotelName");
428419
options.Select.Add("Category");
429420
options.Select.Add("Rating");
@@ -432,19 +423,21 @@ A filter always executes first, followed by a query assuming one is specified.
432423
options.Select.Add("Address/StateProvince");
433424
options.Select.Add("Description");
434425
435-
// For efficiency, the search call should be asynchronous, so use SearchAsync rather than Search.
436426
model.resultList = await _searchClient.SearchAsync<Hotel>(model.searchText, options).ConfigureAwait(false);
437427
438-
// Display the results.
439428
return View("Index", model);
440429
}
441430
```
442431

443432
1. Run the application.
444433

434+
1. Select **Search** to run an empty query. The filter criteria returns 18 documents instead of the original 50.
435+
436+
For more information about filter expressions, see [Filters in Azure Cognitive Search](search-filters.md) and [OData $filter syntax in Azure Cognitive Search](search-query-odata-filter.md).
437+
445438
## Sort results
446439

447-
In the hotels-sample-index, sortable fields include "Rating" and "LastRenovated". This example adds an [$OrderBy](search-query-odata-orderby.md) expression to the "Rating" field.
440+
In the hotels-sample-index, sortable fields include "Rating" and "LastRenovated". This example adds an [$OrderBy](/dotnet/api/azure.search.documents.searchoptions.orderby) expression to the "Rating" field.
448441

449442
1. Open the `HomeController` and replace **RunQueryAsync** method with the following version:
450443

@@ -460,25 +453,23 @@ In the hotels-sample-index, sortable fields include "Rating" and "LastRenovated"
460453

461454
options.OrderBy.Add("Rating desc");
462455

463-
// Enter Hotel property names into this list so only these values will be returned.
464-
// If Select is empty, all values will be returned, which can be inefficient.
465456
options.Select.Add("HotelName");
466457
options.Select.Add("Category");
467458
options.Select.Add("Rating");
468459
options.Select.Add("Tags");
469460
options.Select.Add("Address/City");
470461
options.Select.Add("Address/StateProvince");
471462
options.Select.Add("Description");
472-
473-
// For efficiency, the search call should be asynchronous, so use SearchAsync rather than Search.
463+
474464
model.resultList = await _searchClient.SearchAsync<Hotel>(model.searchText, options).ConfigureAwait(false);
475465

476-
// Display the results.
477466
return View("Index", model);
478467
}
479468
```
480469

481-
1. Run the application.
470+
1. Run the application. Results are sorted by "Rating" in descending order.
471+
472+
For more information about sorting, see [OData $orderby syntax in Azure Cognitive Search](search-query-odata-orderby.md).
482473

483474
<!-- ## Relevance tuning
484475

0 commit comments

Comments
 (0)