Related feedback: FB16995719
This is an old one, that has not been solved in iOS 27. This is very annoying since iOS 27 brings new AI stuff to Spotlight, that can't be used because of this bug.
Jennifer has acknowledged this bug during a one-on-one session last year (WWDC25) where we carefully reviewed my code.
I simply would like that the app documents content to be indexed. It's simple text that I pass to textContent.
-------
try await CSSearchableIndex.default().indexAppEntities([entity]) // How the indexing is called
-------
@available(iOS 18, *)
/// The IndexedEntity
struct DocumentEntity: IndexedEntity, Identifiable {
static var typeDisplayRepresentation: TypeDisplayRepresentation { TypeDisplayRepresentation(name: LocalizedStringResource("INTENT_DOCUMENT_DISPLAY_REP")) }
static let defaultQuery = DocumentQuery()
// A unique identifier for each document
let id: NSManagedObjectID
let title: String?
let thumbnailData: Data?
// The document's text to be indexed
let textContent: String?
let pageCount: Int
// A display representation for UI purposes.
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(
title: "\(title ?? "")",
image: thumbnailData == nil ? nil : .init(data: thumbnailData!) // INDEXED successfully through the use of @available(iOS 18, *)
struct DocumentEntity: IndexedEntity, Identifiable {
static var typeDisplayRepresentation: TypeDisplayRepresentation { TypeDisplayRepresentation(name: LocalizedStringResource("INTENT_DOCUMENT_DISPLAY_REP")) }
static let defaultQuery = DocumentQuery()
// A unique identifier for each document (for example, your NSManagedObject's objectID).
let id: NSManagedObjectID
let title: String?
let thumbnailData: Data?
// The OCR text to be indexed
let textContent: String?
let pageCount: Int
// A display representation for UI purposes.
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(
title: "\(title ?? "")",
image: thumbnailData == nil ? nil : .init(data: thumbnailData!)
)
}
}
)
}
}
@available(iOS 18, *)
extension DocumentEntity {
// The attributeSet for Spotlight
var attributeSet: CSSearchableItemAttributeSet {
let attributeSet = defaultAttributeSet
attributeSet.title = title
attributeSet.displayName = title // THIS ONE IS INDEXED
attributeSet.contentType = UTType.plainText.identifier
attributeSet.textContent = textContent // THIS ONE IS **NOT** INDEXED
attributeSet.pageCount = NSNumber(integerLiteral: pageCount) // THIS ONE IS INDEXED
attributeSet.thumbnailData = thumbnailData
attributeSet.creator = Constants.APP_NAME
return attributeSet
}
}
Related:
https://discussions.apple.com/thread/256061571
0
0
21