CSSearchableIndex
An on-device index for your app’s searchable content.
Declaration
class CSSearchableIndexMentioned in
Overview
A CSSearchableIndex object manages an on-device index for your app’s searchable content. To make your app’s content searchable, create one or more CSSearchableItem objects for your content and add those items to the index. If your app defines AppEntity types, you can also index those types directly or associate them with your CSSearchableItem objects. When you execute a query, Core Spotlight searches your indexes for the requested information and returns the results to your code.
Create custom CSSearchableIndex objects in your production code to store your app’s content, instead of using the default index. Custom indexes support data protection, which allows you to encrypt your data and protect it from unauthorized access. Custom indexes also support batch operations, which allow you to index large amounts of data more efficiently and with less risk. For example, you can add custom state information to each batch operation to make it easier to restart the indexing process if your app or app extension crashes. Use the default index only during testing or prototyping of your features.
Modify a CSSearchableIndex object from only one thread or task at a time, and modify it only from your signed app or app extension. It’s a programming error to access a custom index from multiple threads simultaneously or from an unsigned bundle. When performing batch updates on an index, start each new batch operation only after calling the endBatch(withClientState:completionHandler:) or endIndexBatch(expectedClientState:newClientState:completionHandler:) method of the previous batch operation.
Topics
Creating an index
Determining if indexing is available
Responding to index-related changes
Managing items in an index
indexSearchableItems(_:completionHandler:)deleteAllSearchableItems(completionHandler:)deleteSearchableItems(withDomainIdentifiers:completionHandler:)deleteSearchableItems(withIdentifiers:completionHandler:)
Indexing app entities
Batching index updates
beginBatch()endBatch(withClientState:completionHandler:)endIndexBatch(expectedClientState:newClientState:completionHandler:)fetchLastClientState(completionHandler:)