![]() ![]() Limit the results to a specific number ( $top=5).Īuto-filling a query term or dropping down a list of matching links requires user interaction code, typically JavaScript, that can consume requests from external sources, such as autocomplete or suggestion queries against an Azure Search Cognitive index.Īlthough you could write this code natively, it's much easier to use functions from existing JavaScript library, such as one of the following.Īutocomplete widget (jQuery UI) appears in the Suggestion code snippet. ParameterĪpply match criteria on the result set ( $filter=Category eq 'ActionAdventure'). The following additional parameters apply to both autocomplete and suggestions, but are perhaps more necessary for suggestions, especially when a suggester includes multiple fields. Avoid fields that contain duplicate values (such as a category or city). ![]() Responses are shaped by the parameters on the request:įor Autocomplete, set the autocompleteMode to determine whether text completion occurs on one or two terms.įor Suggestions, set $select to return fields containing unique or differentiating values, such as names and description. ![]() ![]() Responses for autocomplete and suggestions are what you might expect for the pattern: Autocomplete returns a list of terms, Suggestions returns terms plus a document ID so that you can fetch the document (use the Lookup Document API to fetch the specific document for a detail page). APIs for search-as-you-typeįollow these links for the REST and. A partial query of "quick br" will match on "quick brown" or "quick bread", but neither "brown" or "bread" by themselves would be match unless "quick" precedes them. Furthermore, each match sets the scope for downstream expansions. Given "the quick brown fox", both autocomplete and suggestions will match on partial versions of "the", "quick", "brown", or "fox" but not on partial infix terms like "rown" or "ox". Matches are on the beginning of a term anywhere in the input string. A minimum of two or three characters is typical. However, jQuery Autocomplete provides a minimum length. The APIs do not impose minimum length requirements on the partial query it can be as little as one character. In the above example, "minecraf" is a static illustration of what the control might have passed in. The "search" parameter provides the partial query, where characters are fed to the query request through the jQuery Autocomplete control. On a site that sells computer games, the field might be the game title. For suggestions in particular, the field list should be composed of those that offer clear choices among matching results. The "suggesterName" gives you the suggester-aware fields used to complete terms or suggestions. POST /indexes/myxboxgames/docs/autocomplete?search&api-version= The following script illustrates components of a request, using the Autocomplete REST API as an example. Set up a requestĮlements of a request include one of the search-as-you-type APIs, a partial query, and a suggester. For links to end-to-end code samples, see Next steps. REST API examples are used to concisely present each operation. It uses JavaScript and C# to illustrate key points. The remainder of this article is focused on queries and client code. For more information, see Create a suggester. For suggestions, choosing suitable fields that are unique, or at least not repetitive, is essential to the experience. When the index is created and loaded, a suggester data structure is created internally to store prefixes used for matching on partial queries. A suggester is part of the index, and it specifies which fields will provide content that either completes a query, suggests a result, or does both. In Azure Cognitive Search, autocompleted queries and suggested results are retrieved from the search index, from selected fields that you have registered with a suggester. We recommend using an existing JavaScript library for this purpose.
0 Comments
Leave a Reply. |