Using Spotlight as the "database" of an application
Asked Answered
S

1

6

I'm developing an OS X application to organize "things" (as iTunes is to music and iPhoto to photos). Instead of having my own database and index, I'm considering using Spotlight to essentially serve this purpose.

Has anyone tried this? Is it wise?

The main benefit, as I see it, would be simplicity and avoiding redundancy. It seems a bit wasteful to implement my own index machinery when OS X comes with one built in.

I have little experience working with Spotlight, however. From a user's perspective, I do know that it has been slow and imprecise in older versions of OS X. I also have a gut-feeling that since it's aimed at searching the whole filesystem, using it for "local" purposes becomes hackish.

Obviously, my applications's index needs to constantly be up-to-date. Can mdimport be used for this?

Smokechaser answered 2/4, 2010 at 1:4 Comment(0)
C
6

Several apps ship this way. I believe there is at least one company that puts all their customer data into text files to use Spotlight to find information. I save notes with keywords all the time with full confidence that Spotlight will be able to find it later!

In general, you don't need to prod Spotlight to keep the index up to date. It is very good about watching file changes and indexing rapidly.

The key, really, is figuring out your file format. If you go with something that Spotlight can index -- say, text files -- then you don't have to write an importer. If not, you do. Also, have a look at Core Data as it has excellent Spotlight support, too.

One caveat; there are those users that manually turn off spotlight indexing on a particular volume. Rare, but possible.

Coalition answered 2/4, 2010 at 1:57 Comment(2)
Aha! So THAT'S how you customize what's displayed in the search results (kMDItemDisplayName). Thanks for the answer, it's quite enlightening.Smokechaser
FWIW, writing a spotlight importer isn't really a daunting task. For most apps it can be done in hours.. (just finished to write my first importer for an ancient Carbon app in about 3 hours)Boer

© 2022 - 2024 — McMap. All rights reserved.