AI-102 Question 383
Single answerYou are designing an Azure AI solution and need to query an Azure Cognitive Search index to retrieve documents that contain the phrase 'machine learning' in the title field. Additionally, you want to filter results to include only those published after '2022-01-01' and sorted by the 'popularity' field in descending order. Which query syntax should you use?
- A
search=title:'machine learning'&$filter=publishedDate gt 2022-01-01&$orderby=popularity desc
- B
search=title:"machine learning"&$filter=publishedDate gt '2022-01-01'&$orderby=popularity desc
- C
search=title='machine learning'&filter=publishedDate > 2022-01-01&orderby=popularity descending
- D
search="machine learning"&$filter=publishedDate gt '2022-01-01'&orderby=popularity desc
Show answer and explanation
Correct answer: B
Explanation
In Azure Cognitive Search, specific syntax rules must be followed for querying indexes. For phrase searches, double quotes are used. Filtering requires the use of operators like 'gt' and dates must be enclosed in single quotes. Sorting requires the '$orderby' directive followed by the field name and order ('asc' or 'desc'). Option 2 strictly adheres to these rules, making it the correct answer.
- A. Incorrect.
This syntax uses incorrect quotes around the phrase 'machine learning' and omits proper single quotes for the date string in the filter.
- B. Correct.
This is the correct syntax. Double quotes are used for exact phrase matching in Cognitive Search. The filter correctly uses the 'gt' operator and wraps the date in single quotes. The orderby clause is correctly specified as 'popularity desc'.
- C. Incorrect.
This syntax incorrectly uses '=' instead of ':' for field-value matching and does not use the required single quotes for the date string.
- D. Incorrect.
This syntax incorrectly uses '=' instead of ':' for field-value matching in the search query and omits the '$' prefix in the orderby clause.