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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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