Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Generates Core Spotlight indexing infrastructure for making app content searchable via system Spotlight with rich attributes and deep link integration. Use when user wants to index content for Spotlight search, Siri suggestions, or system-wide searchability.
.claude/skills/rshankras-spotlight-indexing/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-04 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 90% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 74% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 88% | 0% |
Generate production Core Spotlight indexing infrastructure — makes app content searchable via Spotlight (and Siri suggestions). Indexes items with rich attributes, handles search continuation into your app, and manages index lifecycle.
Use this skill when the user:
Search for existing Spotlight code:
Glob: **/*Spotlight*.swift, **/*Searchable*.swift, **/*CSSearchable*.swift
Grep: "CoreSpotlight" or "CSSearchableIndex" or "CSSearchableItem"If existing Spotlight code found:
Search for existing deep link or navigation setup:
Grep: "NavigationPath" or "onOpenURL" or "NSUserActivity" or "DeepLink"If deep linking exists:
Verify CoreSpotlight doesn't require special entitlements (it doesn't — it's a standard framework), but check if the app uses App Groups for shared index across extensions.
Ask user via AskUserQuestion:
Read templates.md for production Swift code. Read patterns.md for architecture guidance and best practices.
Generate these files:
SpotlightIndexable.swift — Protocol any model can conform toSpotlightIndexManager.swift — Actor wrapping CSSearchableIndex with batchingSpotlightAttributeBuilder.swift — Fluent builder for CSSearchableItemAttributeSetSpotlightSearchHandler.swift — Handles NSUserActivity continuation from Spotlight tapsBased on configuration:
SpotlightSyncModifier.swift — If incremental indexing selected (ViewModifier for auto index/deindex)Check project structure:
Sources/ exists -> Sources/SpotlightIndexing/App/ exists -> App/SpotlightIndexing/SpotlightIndexing/After generation, provide:
SpotlightIndexing/
├── SpotlightIndexable.swift # Protocol for indexable models
├── SpotlightIndexManager.swift # Actor-based index management
├── SpotlightAttributeBuilder.swift # Fluent attribute builder
├── SpotlightSearchHandler.swift # Handle Spotlight tap continuation
└── SpotlightSyncModifier.swift # Auto index/deindex ViewModifier (optional)Make a model searchable:
swift// Conform your model to SpotlightIndexable struct Article: SpotlightIndexable { let id: UUID let title: String let body: String let author: String let tags: [String] var spotlightID: String { id.uuidString } var spotlightTitle: String { title } var spotlightDescription: String { String(body.prefix(300)) } var spotlightKeywords: [String] { tags + [author] } var spotlightThumbnailData: Data? { nil } var spotlightDomainIdentifier: String { "com.myapp.articles" } }
Index on create, remove on delete:
swiftfunc createArticle(_ article: Article) async throws { try await repository.save(article) await SpotlightIndexManager.shared.index(items: [article]) } func deleteArticle(_ article: Article) async throws { try await repository.delete(article) await SpotlightIndexManager.shared.remove(identifiers: [article.spotlightID]) }
Batch reindex (e.g., on first launch):
swiftfunc reindexAllContent() async { let articles = await repository.fetchAll() await SpotlightIndexManager.shared.reindexAll(items: articles, domain: "com.myapp.articles") }
Handle Spotlight tap (App or Scene delegate):
swift@main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .onContinueUserActivity(CSSearchableItemActionType) { activity in SpotlightSearchHandler.shared.handle(activity) } } } }
Auto index/deindex with ViewModifier:
swiftstruct ArticleDetailView: View { let article: Article var body: some View { ScrollView { Text(article.body) } .spotlightIndexed(article) // Indexes on appear, deindexes on disappear } }
swift@Test func indexAndRetrieveItem() async throws { let manager = SpotlightIndexManager(index: MockSearchableIndex()) let article = Article(id: UUID(), title: "Test", body: "Body", author: "Author", tags: ["swift"]) await manager.index(items: [article]) #expect(manager.indexedCount == 1) } @Test func batchIndexChunksCorrectly() async throws { let mockIndex = MockSearchableIndex() let manager = SpotlightIndexManager(index: mockIndex, batchSize: 10) let items = (0..<25).map { makeArticle(index: $0) } await manager.index(items: items) #expect(mockIndex.indexCallCount == 3) // 10 + 10 + 5 } @Test func handleSpotlightContinuation() async throws { let handler = SpotlightSearchHandler() let activity = NSUserActivity(activityType: CSSearchableItemActionType) activity.userInfo = [CSSearchableItemActivityIdentifier: "article-123"] let itemID = handler.extractItemID(from: activity) #expect(itemID == "article-123") }
Every time a model is created or updated, index it immediately:
swiftawait SpotlightIndexManager.shared.index(items: [newItem])
When content is deleted, remove it from the index:
swiftawait SpotlightIndexManager.shared.remove(identifiers: [item.spotlightID])
After app update or data migration, reindex all content:
swiftawait SpotlightIndexManager.shared.reindexAll(items: allItems, domain: "com.myapp.articles")
When user taps a Spotlight result, the app receives an NSUserActivity. Extract the item ID and navigate:
swift.onContinueUserActivity(CSSearchableItemActionType) { activity in if let id = activity.userInfo?[CSSearchableItemActivityIdentifier] as? String { navigationPath.append(Route.detail(id: id)) } }
expirationDate on CSSearchableItem to auto-expire stale entriesData (JPEG/PNG) not full PlatformImage objectsCSSearchableIndex.default() returns a singleton but its methods are NOT actor-isolatedindexSearchableItems from multiple threads simultaneously.onContinueUserActivity in SwiftUI, not application(_:continue:) aloneCSSearchableItemActionType (a constant from CoreSpotlight)removeAll(domain:) then re-index on first launch after updatedomainIdentifier on items — it allows bulk removal by domain"com.myapp.articles", "com.myapp.products"generators/deep-linking — Deep link routing from Spotlight tapsOther measured skills in the registry, with their headline benchmark lift.