iOS Spotlight indexing seems to be broken on iOS 17?

Content indexed through CSSearchableIndex.default().indexSearchableItems() is no longer searchable from Spotlight.

I created a very small app to demonstrate this. CSSearchableIndex.default().indexSearchableItems() returned no error, yet the result can't be found.

import CoreSpotlight
import SwiftUI

@main
struct testspotlightApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
        .onContinueUserActivity(CSSearchableItemActionType, perform: handleSpotlight)
    }
  }
  func handleSpotlight(_ userActivity: NSUserActivity) {
    print("Found \(userActivity.userInfo?.debugDescription ?? "nothing")")
  }
}
import CoreSpotlight
import SwiftUI

struct ContentView: View {
  @State var result = ""
  var body: some View {
    VStack {
      Text("Hello!")
      Button {
        let attribute = CSSearchableItemAttributeSet(contentType: .text)
        attribute.title = "a page title"
        attribute.contentDescription = "hello this is a page"
        attribute.keywords = ["search", "this", "page", "title"]
        let item = CSSearchableItem(
          uniqueIdentifier: "12345", domainIdentifier: "com.test", attributeSet: attribute)
        CSSearchableIndex.default().indexSearchableItems([item]) { error in
          if let error {
            result = "Failed to index: \(error.localizedDescription)"
          } else {
            result = "Successefully indexed to spotlight. Try searching 'a page title'"
          }
        }
        
      } label: {
        Text("Index a page").font(.title)
      }
      
      Text(result).multilineTextAlignment(.center)
    }
    .padding()
  }
}

Has anyone else seen the same issue?

Answered by baofromsf in 763586022

I finally figured out a way to fix it.

Previously when we create CSSearchableItemAttributeSet when only set its title property. Now with iOS 17, we also need to set displayName property in order for the item to show up.

The code will look like this:

      let attribute = CSSearchableItemAttributeSet(contentType: .item)
      attribute.title = title
      attribute.displayName = title // this is the line that's not required before iOS 17, but necessary now
      let item = CSSearchableItem(uniqueIdentifier: id, domainIdentifier: nil, attributeSet: attribute)
      CSSearchableIndex.default().indexSearchableItems([item])

Also I tried to build from both Xcode 14 and Xcode 15 beta. In both cases, it doesn't work on iOS 17 devices.

Same on our side.. still broken in the latest beta. Not clear if a new API is required or Apple has to fix the actual one 🤷🏻‍♂️

It is broken. Submitted FB12555541 one month ago, no response yet.

Thanks @arcangel06 and [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) . It's reassuring to know that we are not alone. But what concerns me is that for some apps, on iOS 17 beta Spotlight Search does work, e.g. on both Venmo and WhatsApp you can search for friends on Spotlight. So I'm a little worried that Apple would consider this as not broken since it works for some apps.

But what concerns me is that for some apps, on iOS 17 beta Spotlight Search does work, e.g. on both Venmo and WhatsApp you can search for friends on Spotlight. So I'm a little worried that Apple would consider this as not broken since it works for some apps.

@baofromsf are you sure WhatsApp and Venmo - on iOS 17 devices - are built with latest Xcode 15 beta?

The problem is related to apps built with latest beta SDK only.

Accepted Answer

I finally figured out a way to fix it.

Previously when we create CSSearchableItemAttributeSet when only set its title property. Now with iOS 17, we also need to set displayName property in order for the item to show up.

The code will look like this:

      let attribute = CSSearchableItemAttributeSet(contentType: .item)
      attribute.title = title
      attribute.displayName = title // this is the line that's not required before iOS 17, but necessary now
      let item = CSSearchableItem(uniqueIdentifier: id, domainIdentifier: nil, attributeSet: attribute)
      CSSearchableIndex.default().indexSearchableItems([item])

it works [@Mr. Brightside](https://developer.apple.com/forums/profile/Mr. Brightside) :) thank you 🙏🏻

I am facing the exact same problem, proposed workaround works fine but it only let the user search for the words on the displayName field, keywords list is not working for me on iOS 17 :(

I have the same problem. Only the displayName field can be searched, other properties such as keywords、alternateNames、director、comment、information、participants can not be searched on iOS 17. And another problem is that words less than four Chinese can not be searched! Any one knows how to fix it ?

I have filed as FB13205932, would recommend others also file a Feedback and share their ticket numbers in this thread.

Same problem. Filed FB13262028.

Filled FB13265642

When this breaks it also breaks the recent contacts within the share window and recent apps that are location based. I've not yet updated to 17.1 and I am doing so currently. Hopefully @baofromsf fix has been implented.. you are such smart people ;-)

My app's indexing also fails on iOS17, here's what I did to make it work again, after looking at the sample code from "Showcase App Data in Spotlight"

  1. Switched the NSCoreDataCoreSpotlightDelegate init code from init(forStoreWith: NSPersistentStoreDescription, model: NSManagedObjectModel) to init(forStoreWith: NSPersistentStoreDescription, coordinator: NSPersistentStoreCoordinator)
  2. Manually calls startSpotlightIndexing() after the above.
  3. Move the initialisation above from before loadPersistentStores to after loadPersistentStores.

Does anybody get updates? Seems for iOS 17, still only displayName is searchable

iOS Spotlight indexing seems to be broken on iOS 17?
 
 
Q