OS X’s Search Kit Framework allows to create and access search indexes. However, it is not possible to access an existing search index when the name of that index is unknown. All functions of the framework which may be used to access an existing search index (SKIndexOpenWithData, SKIndexOpenWithMutableData, SKIndexOpenWithURL) ask for the index name. This is not the same as the file name of the file in which the search index data is stored.
When I try to access an existing search index file by calling SKIndexOpenWithURL without knowing the name of the index, the function doesn’t return a valid SKIndexRef. Passing NULL as index name (as suggested by the framework’s documentation) doesn’t work because then the Search Kit Framework only tries to use an index name of ‘IADefaultIndex’.
As an example, if I create an index file with an index name like this:
NSString *path = @"/Users/Tim/Desktop/searchindex.skindex";
NSURL *url = [NSURL fileURLWithPath: path];
NSString *name = @"myIndex";
SKIndexType type = kSKIndexInverted;
SKIndexRef skIndex;
skIndex = SKIndexCreateWithURL ((__bridge CFURLRef)url, (__bridge CFStringRef)name, (SKIndexType)type, (CFDictionaryRef)NULL);
// ..
I can later only open the file and access the stored index if I know the index name “myIndex”. If I try to open the file without having (or knowing) the index name, the following code sample will fail:
NSURL *skURL = [NSURL fileURLWithPath:@"/Users/Tim/Desktop/searchindex.skindex"];
SKIndexRef skIndex;
skIndex = SKIndexOpenWithURL((__bridge CFURLRef)skURL, NULL, true);
if (!skIndex) NSLog (@"couldn't open index!");
However, the name of the search index is surely inside that index file. Does anybody know of a way to retrieve that name or to otherwise access a search index file without knowing the search index name? I’m aware that according to the framework documentation there is no possibility of using the framework to get that index name, but it should nevertheless be possible.
Ok, after some research I figured out how to extract the index name from a search index file:
This may not work for every OS X version, but it is working for me with 10.7.