MacTechNotes

Tuesday, October 11, 2005

Spotlight Control

Overview
Spotlight currently has only minimal configuration options: result types to show and their order, and a list of folders not to search. Other folders can be searched which aren't by default, but this option is not exposed through System Preferences.
There are currently three property list files (.plist) which control Spotlight: _IndexPolicy.plist, _exclusions.plist, and _rules.plist.
These files reside in the directory named .Spotlight-V100 on the volume in question. This directory is readable only by root for the primary boot volume, so you'll need to be able to use sudo even to look at them. These, unlike application preference files, are still in plain text so can be viewed easily.

Read on for more detail


_IndexPolicy.plist
This file contains policy information, which is stored in just one key: Policy.
I've currently only figured out two possible settings for this so far:

  • Enabled
    Setting this to a 5 means Spotlight is enabled for the given volume

  • Disabled
    Setting this to a 3 means Spotlight is disabled for the given volume



Enabled example (this is how it should appear by default in most cases):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Policy</key>
<integer>5</integer>
</dict>
</plist>


_exclusions.plist
This contains information about which folders not to search, which are listed in one key: EXCLUSIONS. The value for this is an array of strings, each string being a path to exclude from Spotlight searching.

Example including several paths to not search (in this case, the folders are the DarwinPorts build directory, the system temporary directory, and my user temporary directory):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EXCLUSIONS</key>
<array>
<string>/opt/local/var/db/dports/build</string>
<string>/private/tmp</string>
<string>/Users/blb/tmp</string>
</array>
</dict>
</plist>


_rules.plist
_rules.plist includes both paths to include and to exclude (which makes it a bit redundant with _exclusions.plist). The paths to include are only for cases where Spotlight would otherwise ignore them (it has several paths which it is hardcoded to ignore, see the Known Exclusions section below).
When adding a path which is otherwise skipped, simply updating _rules.plist will not cause anything to happen. Once _rules.plist is as you like, you'll first need to restart mds by stopping it:

sudo killall mds

It will restart automatically. Then, you need to tell mds to import each new path:

sudo mdimport /path/to/files

This will then cause mds to import everything under /path/to/files. If there are many files, it could take some time. You'll need to do this for each new path.
This file can contain several keys:

  • EXCLUDE
    An array of strings, each string being a path to exclude (like EXCLUSIONS in _exclusions.plist).

  • INCLUDE
    Another array of strings, this time being paths to specifically search (to override the hardcoded exclusion list).

  • NOTE
    This is a note, read it and move on.


There are several other values which may be keys. The functionality of each has not yet been found, but some may be obvious (the *_USER ones at least): INCLUDE_USER, EXCLUDE_USER, INCLUDE_BOOTABLE, EXCLUDE_BOOTABLE, INCLUDE_GENERAL, EXCLUDE_GENERAL, CLASSIC_LOCATIONS.

My _rules.plist which gets the *nix path of /etc (AKA /private/etc on Mac OS X) and the whole suite of Xcode documentation:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EXCLUDE</key>
<array/>
<key>INCLUDE</key>
<array>
<string>/private/etc</string>
<string>/Developer/ADC Reference Library</string>
</array>
<key>NOTE<key>
<string>Specify paths to include or exclude, preceeding rules which target user-homes with ~/</string>
</dict>
</plist>


Known Exclusions
These are the paths I know to be excluded by default by Spotlight (there may be others I've missed):

/Developer/ADC Reference Library
/Developer/Documentation
/Previous Systems.localized
/Network
/Volumes
/private
/tmp
/var
/etc
/usr
/bin
/sbin
/dev
/automount
/cores
/mach.sym
/iPod_Control
/System Folder
/Classic
/System/System Folder
/Classic System Folder 9.2.2

Note the *nix paths are included, so don't expect to use Spotlight to search man pages or HTML docs which can be found in /usr/share/*.

2 Comments:

  • So if I wanted to spotlight a network share point, which rule would I want to include?

    By Blogger Michael, at October 31, 2005 at 1:38 PM  

  • So if I wanted to spotlight a network share point, which rule would I want to include?

    Simplest would be to use mdutil (it has a manpage) by using sudo mdutil -i /path/to/volume

    This ends up creating a new .Spotlight-V100 directory there where Spotlight looks for stuff specific to that particular volume.

    By Blogger Bryan, at November 1, 2005 at 1:58 PM  

Post a Comment

<< Home