CSUserQuery
A type you use to initiate searches from your interface and offer suggested text completions.
Declaration
class CSUserQueryMentioned in
Overview
A CSUserQuery object provides the back-end support for your app’s search features. Combine this object with your app’s search interface to perform lexical and semantic searches of human-entered search terms. You can configure a query object to return ranked or unranked results. You can also use it to get a list of suggestions to display from your search interface.
When the text in your search control changes, create a query object to begin searching for results based on the current text. You use a query object only once to perform a search. If the text changes again while a previous query is in progress, cancel the old query and execute the new one. For this reason, it’s a good idea to delay the start of each query until there is a sufficient gap between changes.
Configure the query parameters using a CSUserQueryContext object, which you can reuse for multiple queries. The context lets you configure the behavior for ranking results, specify the maximum number of results and suggestions, and filter the results using a predicate string. When you’re ready to start the query, choose one of the following options:
Get the value of the responses property and iterate over the results.
Configure the foundItemsHandler property and call start() to execute the query manually.
Each query runs until Spotlight returns the requested maximum number of results. If you don’t specify the maximum number of results, Spotlight runs until it returns all results. To end a search before you receive all the results, call the cancel() method. Cancelling a query is especially important if you’re about to start a new query with an updated search string.
For more information about configuring a CSUserQuery object, see Building a search interface for your app.
Topics
Creating a user query
Preparing to search
Executing the query automatically
responsessuggestionsCSUserQuery.ResponsesCSUserQuery.SuggestionsCSUserQuery.ItemCSUserQuery.Suggestion