AI-102 Question 381
Single answerYou are designing a search solution using Azure Cognitive Search for an e-commerce platform to allow customers to query product data. The platform requires functionality for sorting by price, filtering by a specific category, and supporting wildcard searches in the product name. Which of the following queries would correctly implement these requirements?
- A
search=productName:Phone&$orderby=price asc&$filter=category eq 'Electronics'
- B
search=productName eq 'Phone'&$orderby=price asc&$filter=category eq 'Electronics'
- C
search=Phone&$orderby=price desc&$filter=category in ('Electronics', 'Appliances')
- D
search=productName:Phone*&$orderby=price asc&$filter=category eq 'Electronics'
Show answer and explanation
Correct answer: A
Explanation
The correct query syntax for Azure Cognitive Search must align with its supported parameters and operators. Wildcard searches should use the search parameter with * as the wildcard character. Sorting is performed using $orderby, and filtering is achieved through $filter with proper logical operators. Option 1 satisfies all these requirements correctly.
- A. Correct.
This query uses the correct syntax for a wildcard search (
*Phone*), sorting ($orderby=price asc), and filtering ($filter=category eq 'Electronics'). It meets all the requirements. - B. Incorrect.
This query incorrectly uses
productName eq '*Phone*'for the wildcard search, which is not valid Azure Cognitive Search syntax. Wildcard searches should use thesearchparameter, not equality checks. - C. Incorrect.
This query uses
search=*Phone*for the wildcard search, which is valid, but the$orderbyvalue specifies descending order (desc) instead of ascending order as required. Additionally, the$filterclause specifies multiple categories instead of a specific one. - D. Incorrect.
This query uses an invalid syntax for the wildcard search (
productName:Phone*). Azure Cognitive Search does not support this format; it uses thesearchparameter for such queries.