Add local source ingest and podcasts

This commit is contained in:
Krishna Kumar
2026-07-02 01:11:03 -05:00
parent 4d875e12d6
commit f8693f4be0
18 changed files with 1044 additions and 31 deletions

View File

@@ -0,0 +1,40 @@
import CoreSpotlight
import Foundation
import UniformTypeIdentifiers
enum SourceSpotlightIndexer {
private static let domainIdentifier = "com.magicive.marks.sources"
static func index(_ sources: [IngestedSource]) async {
guard CSSearchableIndex.isIndexingAvailable(), !sources.isEmpty else { return }
let items = sources.map { source in
let attributes = CSSearchableItemAttributeSet(contentType: source.kind == .pdf ? .pdf : .text)
attributes.title = source.displayTitle
attributes.contentDescription = source.bodyText
attributes.keywords = source.tags + [source.kind.label, source.originalFilename].compactMap { $0 }
attributes.displayName = source.originalFilename ?? source.displayTitle
return CSSearchableItem(
uniqueIdentifier: source.id.uuidString,
domainIdentifier: domainIdentifier,
attributeSet: attributes
)
}
do {
try await CSSearchableIndex.default().indexSearchableItems(items)
Log.spotlight.info("Indexed \(sources.count, privacy: .public) sources")
} catch {
Log.spotlight.error("Source index failed: \(error.localizedDescription, privacy: .public)")
}
}
static func remove(ids: [UUID]) async {
guard CSSearchableIndex.isIndexingAvailable(), !ids.isEmpty else { return }
do {
try await CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: ids.map(\.uuidString))
Log.spotlight.info("Removed \(ids.count, privacy: .public) sources")
} catch {
Log.spotlight.error("Source delete failed: \(error.localizedDescription, privacy: .public)")
}
}
}