Spotlight and Database Files

March 18th, 2007

One of the interesting things about Spotlight is that it only works on individual files. When it sees that a file has changed on disk, it uses the relevant importer to update the metadata store.

For each time it is called, a Spotlight importer can only provide data for a single item that will be shown in Spotlight’s results. A different approach is required for multiple items, such as bookmarks in your web browser or iCal events, that are contained in a database or single file (including file packages, because Spotlight won’t index the files inside).

It’s a very simple workaround, but seems a little clumsy, considering. Every time such an item is changed, you need to change a file on disk that can trigger Spotlight to invoke the appropriate importer.

To use iCal as an example, in ~/Library/Caches/Metadata, you’ll see a number of folders for different applications, including iCal itself. Looking in that folder, you’ll see a number of other folders with UUID-style file names that refer to the calendars in the application, and in those folders various files with .icalevent or .icaltodo extensions. These files contain data that the iCal importer will use to provide metadata to Spotlight. It’s iCal’s responsibility to ensure those files are created, updated and deleted as necessary.

In some cases, looking at files in the Metadata folder can reveal an surprising amount of duplicate data, with files filled with text. This is probably because it would be too much of an overhead, or too difficult for the importer to extract the actual data from the database.

If you’re designing a new application that uses a database or single-file format to contain multiple items that you want indexed by Spotlight, you should bear this in mind.

Leave a Reply