Spotlight is terrible. But at the same time, very useful. Let's hope Apple cleans it up a bit in a future release. But until then, here is some more help - to go along with the tons of Spotlight hints we already have here.
Spotlight saved searches, or "Smart Folders," are simply XML files with a .savedSearch extension. Within that XML file, which you can open using any text editor, there is a tag called RawQuery; immediately following that is another called (ambiguously) string. The string tag right after the RawQuery tag is the "code" for your search.
Since Spotlight limits what you can put in the query in various ways, sometimes it is hard to get what you want out of it. Boolean searches are well documented both on this site and others -- but they prove problematic and inconsistent. So this hint is intended to share some info about how to modify the "code" in the saved search to get what you want.
Let me start with a scenerio. I have a bunch of images in a folder named Images, and I want to mark some of them as Oregon. So I use the Batch Spotlight Comment action in Automator to mark them as Oregon in the Spotlight comments. Then they are easy enough to find using Spotlight; just type in Oregon and there they all are. But say I add another batch marked Mountains, and I want to find all images that are marked Mountains but not Oregon. Not so easy to do with Spotlight, at least as the interface allows. If I open a saved search for Oregon-coded pictures, I get this XML (line breaks in the string line are added for readability; there are none in the code):
<key>RawQuery</key>
<string>(* = "Oregon*"wcd || kMDItemTextContent = "Oregon*"cd) &&
(kMDItemContentType != com.apple.mail.emlx) &&
(kMDItemContentType != public.vcard)</string>
Well, that code isn't too helpful. But Apple's Developer documentation on query syntax and what can be queried are good references. I will highlight the important stuff here for a simple overview, and in case they change the URL of the pages.
First of all, comments in the Finder -- which are called by the UI name "Spotlight Comments" -- are stored in the kMDItemFinderComment key. So to search for Oregon anywhere in the comments, here is the simplest form:
<key>RawQuery</key>
<string>(kMDItemFinderComment == "*oregon*"cd )</string>
The operators are:
- == equal
- != not equal
- < less than
- > greater than
- <= less than or equal to
- >= greater than or equal to
- * is the wildcard:
- Placed at the beginning, like *oregon, gets anything that ends with oregon.
- Placed at the end, like oregon*, will get anything that starts with oregon.
- Placed on both sides, like *oregon* will return anything with oregon anywhere.
- w makes the comparison based on whole words
- c makes the comparison not case sensitive (ignore case)
- d makes the comparison diacritical insensitive. I had to look it up, but diacritical means "accents." So this would ignore any accent marks, I am assuming).
<key>RawQuery</key>
<string>(kMDItemFinderComment == "*mountain*"cd &&
kMDItemFinderComment != "*oregon*"cd )</string>
Again, the line break in the string line was added for legibility; remove it when entering the text in the file.
This one example should show you how you can easily edit saved searches to make them do more of what you want. This was just a small example -- I am sure someone will comment with the way to do that search in plain Spotlight. But the intent is to show you how the XML for the savedSearch works, and how to develop your own queries using it...

