Core Spotlight

RSS for tag

Index your app so users can search the content from Spotlight and Safari using Core Spotlight.

Core Spotlight Documentation

Posts under Core Spotlight tag

17 Posts
Sort by:
Post not yet marked as solved
0 Replies
131 Views
The WWDC '17 session for core spotlight said QLSupportsSearchableItems is only for "shoebox" apps and explicitly said it's not for document-based apps, but when trying to upload my UIDocumentBrowserViewController-based MacCatalyst app with a quicklook extension (the view-controller-based quicklook preview works great) to App Store connect, it prevents me from uploading without a QLSupportsSearchableItems keys in my quicklook extension's info.plist, and it prevents me from uploading it if the value is false (0). Is the app store validator correct, and I must have this key and it must be true? Do I have to implement func preparePreviewOfSearchableItem(identifier, and if so, can I just have it always fail? If it can't fail, how would I get a sandbox url for the document from a searchable item identifier? Also, Xcode won't find anything when I search for QLSupportsSearchableItems, which is not so much ironic as it is face-palmy.
Posted
by
Post not yet marked as solved
0 Replies
142 Views
I'm working on Spotlight integration for my mac app, I just indexed the data with CoreSpolight everything working fine when the app is running. I'm using below mentioned NSApplicationDelegate method to open corresponding content when the user taps the spotlight result. func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool This method is not triggering when the app is not running (Ensured using NSLog). And I'm expecting it has to open my application as well But both not working as I expected. What am I missing in this implementation?
Post not yet marked as solved
0 Replies
119 Views
I can see a couple of python scripts in indexing folders /System/Volumes/Data/.Spotlight-V100/Store-V2/<GUID>/Cache/0000/0003/0003/12885148578.txt Why is the spotlight keeping copies of the files in addition to the indexing metadata? Are these temporary files and would these be auto-deleted after some known time period?
Posted
by
Post not yet marked as solved
0 Replies
177 Views
The thumbnail does not show in spotlight search results on iOS15 after setting thumbnailData or thumbnailURL in CSSearchableItemAttributeSet and assigning it to NSUserActivity. I have tried setting UIImage.pngData() to thumbnailData and saving an image to a local file URL and setting it to thumbnailURL. I have tried on physical device running iOS 15.2 and 15.3, and simulator running iOS 15.3. See attached code. It works on simulator running iOS 14.5 https://www.dropbox.com/s/odax9d3s6htl0fb/SpotlightTest.zip?dl=0 Feedback ticket: FB9915366 (Spotlight Search does not show thumbnail for NSUserActivity and CSSearchabltItem)
Posted
by
Post not yet marked as solved
0 Replies
242 Views
In the document it says you can define your own custom attribute: The attributes you choose depend on your domain. You can use the properties that Core Spotlight provides in categories that CSSearchableItemAttributeSet defines (such as Media and Documents), or you can define your own. If you want to define a custom attribute, be as specific as possible in your definition and use the contentTypeTree property so that your custom attribute can inherit from a known type. I tried to index a custom attribute with the following code: class mySpotlightDelegate:NSCoreDataCoreSpotlightDelegate { static let myCustomAttr = CSCustomAttributeKey(keyName: "myCustomAttr")! override func attributeSet(for object: NSManagedObject) -> CSSearchableItemAttributeSet? { if let myObject = object as? MyObject { let attributeSet = CSSearchableItemAttributeSet(contentType: .bookmark) attributeSet.title = myObject.name attributeSet.setValue( NSString(string: myObject.myAttr), forCustomKey: mySpotlightDelegate.myCustomAttr ) return attributeSet } return nil } } But later I couldn't either search with the custom attribute nor get the value of that custom attribute in the CSSearchQuery foundItemsHandler. (The search returns nil and when searched with title it was fine, but when I tried to get the value of custom attribute of returned items with item.attributeSet.value(forCustomKey: mySpotlightDelegate.myCustomAttr), the value is always nil) I've read through all official document regarding this and also searched everywhere but can't find an example of this anywhere, execept 2 other developers complaining about this problem. Is this a bug, or I'm doing it wrong? What's the right way to do it?
Posted
by
Post not yet marked as solved
0 Replies
237 Views
I created an ImportExtension using the template in Xcode, and implemented the -[ImportExtension updateAttributes:forFileAtURL:error:] method. I have tried searching for the corresponding file in Spotlight and the method is not called. How can I make this method be called? Xcode Version: 13.2.1 iOS Version: iOS 15.2
Posted
by
Post not yet marked as solved
1 Replies
335 Views
Hello, sometimes if I use NSMetadataQuery to obervse my file changes on macOS, it crash for this reason, its odd and i have no clue for this problem becuse in my code I never get results using index, anyone help? thanks! Application Specific Information: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSMetadataQueryResultArray objectAtIndex:]: index (251625) out of bounds (251625)' terminating with uncaught exception of type NSException abort() called
Posted
by
Post not yet marked as solved
0 Replies
260 Views
I was trying to access a website that ends with .wiki. The URL was registered to the DNS server. However, instead of going to the actual website, Siri suggestion took me to a Wikipedia page that was totally irrelevant. Since Siri suggestion came at the top, everyone who tried to access the website almost cannot get it right for the first time. This contamination occurs after upgrading to Monterey. Is there anyway to let the devs know the situation?
Posted
by
Post not yet marked as solved
0 Replies
371 Views
I created a CSImportExtension in my UIDocument-based app to make the content of my documents searchable. Now I can successfully search for the content from the iOS home-screen search. But when I try the same search in the Files.app or from the document browser in my app, no results are shown. In the update attributes function in the extension, I am populating the following fields of the passed-in CSSearchableItemAttributeSet: keywords, contentDescription, displayName Does anybody know what I have to do to make the content searchable from all locations? I tried the same within the Pages, Numbers and Keynote apps and their document contents is found beautifully from the Files.app or from their document browsers. So it seems to work in principle. Thanks and cheers Frank
Posted
by
Post not yet marked as solved
1 Replies
250 Views
I am wanting to not only surface my content in the system-level Spotlight search results but also to utilize the same index for my in-app search screen. The very few examples or tutorials I could find all craft a CSSearchQuery string using just the "title" attribute. I can't figure out where to look to understand how to search across other attributes. My most pressing need is to be able to perform a CSSearchQuery looking for a search term in the .htmlContentData attribute. If I search for this term in the system search field it returns results, so I know it's being indexed. However when I use a search query (in my app) like htmlContentData == "someSearchTerm" I get zero results. This frustration has led to some more general questions like: How do you know what attribute names are available to use in the search query? Is it just a string literal that's exactly the same as the CSSearchableItemAttributeSet property in Swift? e.g. property .htmlContentData is referred to as "htmlContentData" in the query string? Also, is there any way to just search across all attributes with CSSearchQuery? Obviously using the system Spotlight search (from Home Screen) you don't have to specify if you're searching the title or htmlContentData, it just finds it in either. Yet for CSSearchQuery I have to know up-front which fields I want to look in?
Posted
by
Post not yet marked as solved
0 Replies
316 Views
I've implemented Core Spotlight indexing of my app's Core Data without an index extension (CSIndexExtensionRequestHandler), and it seems to be working fine. Would it still be useful to have one? It is described in the documentation, but I'm not sure how to implement things like reindexAllSearchableItems for Core Data. The Showcase App Data in Spotlight sample code associated with the WWDC21 session does not have an index extension, or override the default reindexAllSearchableItems method of NSCoreDataCoreSpotlightDelegate. Does that mean that this is no longer needed?
Posted
by
Post not yet marked as solved
0 Replies
306 Views
It seems to me that setting the thumbnailData and thumbnailURL attributes on the CSSearchableItemAttributeSet has no function in macOS. The Spotlight interface will only ever show the application icon in search results. Is this the expected behaviour? Is setting this attribute useful in any way?
Posted
by
Post not yet marked as solved
0 Replies
317 Views
I've implemented Core Spotlight indexing of the Core Data in my macOS app, using NSCoreDataCoreSpotlightDelegate, and it seems to be working. Any new or changed Core Data objects and attributes seem to be added to the index automatically and immediately, but searchable items for deleted objects won't be automatically removed. I guess this is working as expected? I've implemented the willSave: method in the relevant NSManagedObject subclasses, where I check the deleted property and run deleteSearchableItemsWithIdentifiers on the default Searchable Index. I also delete searchable items for deleted Core Data objects in my QuickLook extension's preparePreviewOfSearchableItemWithIdentifier method. I suppose what I'm asking is: Am I understanding this right and is this the best way to do it?
Posted
by
Post not yet marked as solved
2 Replies
476 Views
I have added the contents of my app to iOS Spotlight via the CSSearchableItemAttributeSet and it is very easy to find them from spotlight in use. I'd like to achieve a similar effect in the app via CSSearchQuery, but I'm currently running into a problem. In the system's spotlight, users can use fuzzy queries to find the information they want. I can't enter Chinese characters in the forum, 'hello' should be Chinese characters for example, if my content is in Chinese, 'hello', users can find the content not only by 'hello' but also by using 'nihao' to find the same content.('nihao' is the Latin pinyin equivalent of the Chinese word 'hello'). However, I am unable to achieve a similar effect in CKSearchQuery. At the moment CKSearchQuery only has [cdwt] four ways, is there any other means to achieve the above query capability. Or perhaps Apple does not have this capability open in CKSearchQuery.
Posted
by
Post not yet marked as solved
4 Replies
1.2k Views
On iOS14, the thumbnails set for CSSearchableAttributeSet saved in the app are no longer displayed when searching in Spotlight. Oddly enough, the thumbnails are displayed when validated in the simulator, but only when done on an actual device, the app icon is displayed. Is this issue due to the change in Spotlight search specs in iOS14?
Posted
by