Select Page
NOTE: This is a static archive of an old blog, no interactions like search or categories are current.

A friend installed his new Tiger today and found that only the files that was on his drives at first boot is in the spotlight database, nothing new was being added.
At first glance everything looked fine, but this very simple test will confirm if spotlight is working or not:

[rip@temptation]% touch test
[rip@temptation]% mdls test
test -------------
kMDItemAttributeChangeDate = 140116-07-24 20:14:56 +0000
kMDItemFSContentChangeDate = 2005-04-30 00:10:37 +0100
kMDItemFSCreationDate      = 2005-04-30 00:10:37 +0100
kMDItemFSCreatorCode       = 0
kMDItemFSFinderFlags       = 0
kMDItemFSInvisible         = 0
kMDItemFSLabel             = 0
kMDItemFSName              = "test"
kMDItemFSNodeCount         = 0
kMDItemFSOwnerGroupID      = 501
kMDItemFSOwnerUserID       = 501
kMDItemFSSize              = 0
kMDItemFSTypeCode          = 0
kMDItemID                  = 531254
kMDItemLastUsedDate        = 2005-04-29 23:10:37 +0100
kMDItemUsedDates           = (2005-04-29 23:10:37 +0100)

This creates a new file and then asks spotlight to list the metadata for this file, if spotlight isn’t indexing then nothing will be displayed after the second command. This was the case for this user.
Spotlight has a command line control tool called mdutil(1) that can start, stop and display current indexing state among other things, I turned indexing off and back on for the / volume on his machine and all was fine.

[rip@temptation]% sudo mdutil -i off /
Password:
/:
Indexing disabled for volume.
[rip@temptation]% sudo mdutil -i on /
/:
Indexing enabled for volume.

After that the simple test above should work. Note though that the new files may not immediately show up in search results since its likely that your machine may be now importing quite a few files into the datbase in a low priority background task, but things should be back to normal eventually.
In some cases though it seems not even this kicks the bugger back to life. So it is time to get a bit tough on it, so you can completely whipe the spotlight data store for a volume which will cause a immediate resync.

$ mdutil -E /

After this your spotlight will not work for a while, it will be like right after a fresh install, once it is done rebuilding and your spotlight icon lets you run searches it seems a reboot is in order, when you are back from the reboot it should all be good.
A quick test is to run a search for something in the spotlight GUI, click on ‘Show All’ and while this window is open make a folder or something that will match your query in a terminal, your spotlight results should dynamically update to include the new match.
UPDATE: You can also force a re-index by adding your whole harddrive to the Spotlight ‘private’ list and then removing it from the list after a while. Using this method you wont need a reboot or anything, plus it’s reachable by the GUI.