How can I query Spotlight?
Generated on 8/9/2024
1 search
To query Spotlight using Core Spotlight, you can utilize the framework to donate searchable content from your app to Spotlight and then retrieve that content with a query. Here's a brief overview of the process:
-
Donate Searchable Content: First, you need to donate the content you want to be searchable to Spotlight. This involves creating a
CSSearchableItem
with a unique identifier, an optional domain identifier, and an attribute set that describes the content. This content is stored in a private, local index on the device. -
Semantic Search: With the latest updates, Core Spotlight supports semantic search, allowing users to search for content in your app using terms that are similar in meaning, not just exact matches. This is achieved through Spotlight's query understanding models.
-
Indexing: You can create a searchable index in Spotlight and donate items to it. The new APIs support batch indexing with client state and item updates, making the process more efficient.
-
Querying: To query the index, you can configure queries to return results ranked using machine learning models. You can also configure a suggestions menu in your app using
CSUserQueryContext
. -
Boosting Results: You can boost the ranking of search results that are most relevant to the user over time.
For a detailed walkthrough on building a search experience in your app, you can refer to the session Support semantic search with Core Spotlight (01:37).
Relevant Sessions
What’s new in App Intents
Learn about improvements and all-new features with App Intents, and discover how this framework can help you expose your app’s functionality to Siri, Spotlight, Shortcuts, and more. We’ll show you how to make your entities more meaningful to the platform with the Transferable API, File Representations, new IntentFile APIs, and Spotlight Indexing, opening up powerful functionality in Siri and the Shortcuts app. Empower your intents to take people deep into your app with URL Representable Entities. Explore new techniques to model your entities and intents with new APIs for error handling and union values.
Support semantic search with Core Spotlight
Learn how to provide semantic search results in your app using Core Spotlight. Understand how to make your app’s content available in the user’s private, on-device index so people can search for items using natural language. We’ll also share how to optimize your app’s performance by scheduling indexing activities. To get the most out of this session, we recommend first checking out Core Spotlight documentation on the Apple Developer website.