Thank you again for the thoughtful response. This is the high level solution I've ended up with.
To recap:
This is a SwiftUI document-based app: DocumentGroup backed by SwiftData.
A user will typically have only a few of these files.
A file will typically have only a few thousand indexed records.
Search is required for in-app use only; system-wide search is not.
The application maintains a single search index.
When the app launches it deletes all items from the search index. This keeps the search index clean in the case of renamed, deleted or seldom used files.
A document uses the domainIdentifier search attribute set to its URL to tag all of its searchable items.
When a document is opened it deletes all of its searchable items using the domainIdentifier to scope the operation. It then adds all of its searchableItems to the index.
The document adds, deletes & updates its searchable items while it is open.
When a document's URL changes it updates the domainIdentifier of its searchable items.
In-app search queries are always scoped to the domainIdentifier of the file.
Topic:
App & System Services
SubTopic:
General
Tags: