3

I have a sandboxed, Mavericks only, Core Data, non-document, Mac application.

For one attribute of one entity I selected „Index in Spotlight“,
and in a second attempt I selected „Index in Spotlight“ and „Store in External Record File“.

Following Apples Core Data Spotlight Integration Programming Guide i am at the first point, Your program:

There are three processes involved in creating and maintaining the Spotlight index:

  • Your program. Within your program, the Core Data framework maintains the persistent store and creates the external record files to trigger the spotlight indexing

  • The Spotlight importer. [...]

  • Core Data External Record daemon. [...]

I assume, now, there must be some place where metadata (that a Spotlight Importer could index) or external record files will be generated if I run the application and add data in it.
I can nowhere find such metadata or external record files. I searched everywhere in- and outside the sandbox container of my application. (Note, i am not trying to build the Spotlight Importer yet — i am merely looking for the metadata to be indexable.)

Where would this spotlight indexable metadata normally be found?
What could be the reasons no spotlight indexable metadata is generated?

MartinW
  • 4,966
  • 2
  • 24
  • 60

3 Answers3

2

External record data is stored in the same directory as your primary Core Data files (i.e. your SQLite file), but in a hidden subdirectory. The naming convention for the subdirectory is .ApplicationName_SUPPORT/_EXTERNAL_DATA .

For non-document-based applications, Core Data creates a directory structure within ~/Library/Caches/Metadata for the application. The directory structure may vary with the OS version, Core Data version, etc. At some level there should be an application-specific directory within that structure, and inside that should be the external records file(s) created by Core Data.

If you cannot find these files, use kqueue events, lsof, or libdispatch to monitor the filesystem for changes while you run your application. You should be able to see what locations on the file system are being accessed easily. If external records files are not being created, or are being created in some new location, that too should be obvious.

Spotlight metadata is not stored in discrete files but in Spotlight's own data. You can inspect the metadata of a file by using the mdls command from a terminal.

Example: mdls /Applications/Maps.app

You can also use the mdimport command to tell Spotlight to index something on demand.

Example: mdimport ~/Documents/MyAwesomeStuff

mdimport also has a command line option to use a specific importer rather than a system importer. This can be very useful for development. Both mdls and mdimport will print out help messages detailing these arguments if asked.

quellish
  • 21,123
  • 4
  • 76
  • 83
  • That’s the kind of information i am looking for — yet, in my case no hidden `.ApplicationName_SUPPORT/_EXTERNAL_DATA` directory exists in the same directory as my Core Data files. If i have a non-document core data app, on which file would i use the `mdls` command? – MartinW Jun 19 '14 at 08:55
  • I have not found the solution to my problem yet, but you gave me great hints about how to further investigate my problem. – MartinW Jun 22 '14 at 11:51
  • @MartinW I'm having a similar problem. Did you by chance happen across a solution or useful information? – Vervious Jul 01 '14 at 00:05
  • @Vervious Sadly no, but I did not yet have time to further investigate. I will post here as soon as I know something new. – MartinW Jul 02 '14 at 17:23
2

The directory for the external records has to be in ~/Library/CoreData (or the equivalent in a sandboxed application). You must create it.

Also don't forget to set the store options for your PersistentStoreCoordinator, in the Application Delegate, like this in - (NSPersistentStoreCoordinator *) persistentStoreCoordinator :

//creating the External Records Directory
error = nil;

NSString *externalRecordsSupportFolder = [@"~/Library/CoreData/YOUR_EXTERNAL_RECORD_DIRECTORY" stringByExpandingTildeInPath];
[fileManager createDirectoryAtPath:externalRecordsSupportFolder
       withIntermediateDirectories:YES
                        attributes:nil
                             error:&error];

if(error){
    [NSApp presentError:error];
}

//options for your main Persistent Store Coordinator   
NSDictionary *storeOptions = @{
                              NSExternalRecordExtensionOption:@"YOUR_EXTERNAL_RECORD_EXTENSION",
                                NSExternalRecordsDirectoryOption:externalRecordsSupportFolder,
                                NSExternalRecordsFileFormatOption:NSXMLExternalRecordType
                                };

Then you pass the storeOptions

NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:storeOptions error:&error]) {
    [[NSApplication sharedApplication] presentError:error];
    return nil;
}
mghez
  • 106
  • 1
  • 3
0

In the core data model editor, you can check the spotlight indexing for each individual attribute.

  • Select the attribute and open the Data Model inspector
  • Check "Index in Spotlight"

enter image description here

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • That was the origin of my question. I did check „Index in Spotlight“ and could not register any effect of doing so.. – MartinW Jun 16 '14 at 21:35