Search code examples
macossearchspotlight

Is it possible for a native OS X app to read and copy the Spotlight search index?


I don't want to alter the index in any way, simply read it, monitor it for changes, and replicate it. It would be with a native app/service, that would run in the background. I"m assuming I'd be targeting 10.6+, but that's not written in stone.

Where is the actual index? Can I read it in any semantically useful way?

Googling around, I haven't found any references to the actual Spotlight index location, or an API to read the whole thing. I did find the Search Kit Reference, which seems to explain how the underlying technology works and might be helpful, but doesn't explain how one might retrieve the entire index, or monitor the index over time.

I also noticed an app called Houdah that portends to provide an improved frontend to Spotlight, which may of interest, though I don't know how they acheived their effect - if it's literally just a frontend that calls the same Search Kit API's as Spotlight against the same index, that's not quite what I'm after...

Edit: Can't believe I hadn't read the wikipedia article on Spotlight - good reference, but I think my question stands.

(I'm a front-end web guy, apologies for noobishness.)

UPDATE: An OS X developer friend thought it would be stored in an SQLite database in a hidden file, but couldn't locate the actual file in the few minutes he spent looking. He did find a hidden .spotlight directory, but this was empty.


Solution

  • On Mac OS X 10.7 -- previous versions are significantly different -- the Spotlight index is stored in /.Spotlight-V100/Store-V2. The storage format is undocumented, but is definitely not SQLite.

    I doubt that there's any useful way to extract data from the Spotlight index without an impractical amount of reverse engineering. Even if you did, it'd be likely to break with new releases of Mac OS X.