Thursday, August 11, 2005

Boolean searching in OS X Mail.app

Macintouch - Mail.app (Part 17)

This is an interesting claim -- that Spotlight and Mail.app support Boolean search with the C-style logical operators of & and |. I'll test and verify as an update. Lack of Boolean operators has been a common complaint.
Boolean Searching

Kees Huyser

... According to mail->help->searching:

Use the words 'and,' 'or,' 'not,' and parentheses to refine your search:

'cat and dog' finds email containing both 'cat' and 'dog'
'cat or dog' finds email containing either 'cat' or 'dog'
'cat not dog' finds email containing 'cat' but not 'dog'
'cat and (dog or newt)' finds email containing both 'cat' and 'dog' and email containing both 'cat' and 'newt'

You can also use boolean expressions in the search box:

A & B yields A AND B
A | B yields A OR B
A ! B yields A NOT B.

This also works in Spotlight btw.

Jim Elliott

Kees Huyser's tip about Boolean searches in Mail and Spotlight adds a vast dimension of power to Tiger, with one big caveat: I can't get it to work using the words ("and", "or", even though that's indeed what the Help shows). These words seem to be treated as any other search terms. For example, if I search for "tiger and behavior" I get 12 hits, whereas "tiger behavior" gets me 14, and "tiger or behavior" nets 9. Clearly it's not a Boolean search.

If, however, I use the C-style logical operator symbols ("&", "|") it works beautifully! "tiger & behavior" gets 14 results, the same as "tiger behavior", while "tiger | behavior" yields 2062 hits. (I also tried the words individually and did the arithmetic to verify that Boolean logic added up.)

This is awesome! I had believed that there was no way to tap this power of the Spotlight API from the normal user interface. I am thrilled to find I was wrong. Now I just hope that Apple fixes their help text so that other power users, who haven't been following MacInTouch, can learn how to find exactly what they're looking for.
Update 8/12
Jim Elliott

I left out one crucial detail in my excitement yesterday, and I hope this will help explain why other users were reporting that Boolean searches were not working for them:

You can only perform advanced searches like this when you have chosen "Entire Message" (rather than "From", "To" or "Subject") as the search context. Otherwise it seems to do some sort of stemming "or" search regardless of the punctuation you include. I should also note that this mode, too, contradicts Apple's own help which claims things work in a completely different way. The documenters seem to have been utterly baffled about how Search is supposed to work in this version of Mail, and are compounding our confusion and frustration.

Ron Kaplan

This is related to the extremely useful Boolean search discussion of the last few days. It is now clear that a Boolean formula can be used to search one field of a Mail search, and that the result can be saved as a smart mailbox.

But it seems that it is not possible to use Boolean combinations of criteria across different fields to filter what shows up in that mailbox. You get only top-level "all" (= AND) or "any" (= OR). So suppose you want to have the conditions [Message is in Inbox] AND ([From contains John] OR [Any recipient contains John])

Is there anyway to get nested conditions?


Stephen Hart

Is it possible that some users are getting confused with the quotation marks writers use to indicate what to type? The following two entries yield different results for me in both the Finder and Mail (presumably both using the Spotlight search engine): bird and song "bird" and "song"

The former returns many more hits than the latter, which returns just what I'd expect on my hard drive.

No comments: