Developing Solutions for Microsoft Azure: Implementing Azure Search for Accommodation Venues

Implementing Azure Search for Accommodation Venues

Question

You are developing a .NET Core MVC application that allows customers to research independent holiday accommodation providers.

You want to implement Azure Search to allow the application to search the index by using various criteria to locate documents related to accommodation venues.

You want the application to list holiday accommodation venues that fall within a specific price range and are within a specified distance to an airport.

What should you do?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

The Filter property gets or sets the OData $filter expression to apply to the search query.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.search.models.searchparameters https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.search.models.searchparameters.querytype

To enable searching within a specific price range and proximity to an airport using Azure Search in a .NET Core MVC application, you should configure the Filter property of the SearchParameters class.

The SearchParameters class represents a set of search parameters that specify options for a search request, such as search mode, query type, and filters.

The Filter property of the SearchParameters class allows you to specify a filter expression that limits the search results to a subset of documents that meet specific criteria. In this case, you can define a filter expression that combines a price range filter and a proximity filter based on the location of the accommodation venue and the airport.

To implement this, you should first create an Azure Search index that includes the necessary fields, such as price and location. Then, when constructing the search query in your .NET Core MVC application, you would set the Filter property of the SearchParameters class to a filter expression that specifies the desired price range and proximity.

For example, the following code snippet demonstrates how to set the Filter property to a filter expression that retrieves documents that fall within a specific price range and are within a specified distance to a given airport:

csharp
var searchParameters = new SearchParameters { Filter = $"price ge {minPrice} and price le {maxPrice} and geo.distance(location, geography'POINT({airportLongitude} {airportLatitude})') le {maxDistance}" }; var searchResults = indexClient.Documents.Search(query, searchParameters);

In this example, the filter expression combines a price range filter (using the "ge" and "le" operators) with a proximity filter (using the "geo.distance" function and the "le" operator) based on the location field and the latitude and longitude coordinates of the airport.

Therefore, the correct answer to the question is D. Configure the Filter property of the SearchParameters class.