Freigeben über


New Mansions in Search - Advanced Query Syntax

With the Windows Vista General Availability behind us, it's time to call attention to one of the useful features of the new search facilities in Vista.

I am sure that you have noticed that there are "search boxes" sprinkled in strategic places across the user interface, in particular:

  • In the Start menu (this one is a bit special)
  • In the Search Home (you go there by Start > Search)
  • In any Windows Explorer folder.

There are many things to say about how to use these search boxes but I will focus on one of them: the Advanced Query Syntax (AQS) that you can use in all of them. Often all you need to do to find something is simply typing in one or more words that you recall from that document, e-mail or whatever in a search box and in a jiffy you have found it. But sometimes that returns way too many results to wade through so you need to be more precise, or you need to search on something other than words, like a date. That is when AQS comes in very handy.

Terminology: I'll write item when I mean any kind of document, e-mail, image, text file or other searchable thing on your computer.

Terminology: Items have properties that can be textual (author, title, name, tags, etc), numeric (size, importance, etc), date/time (when created, modified, or sent, etc), and so on. They also usually have some form of content which often is searchable, such as the text of a document, or the body of an e-mail message.

Me lazy boy: As you have probably figured out on your own, when you type, say, 'ste' in the search box, Vista will actually search for anything beginning with 'ste'. But it would get very tedious to write "search for words beginning with blah, blah" all over this post, so unless I specifically say otherwise, when I write "search for blah, blah" below, I mean "search for words beginning with blah, blah".

Here are a couple of examples of queries that illustrate some of the abilities of AQS:

  • author:Darrell
  • modified:Jan 2006
  • taken:yesterday
  • date:6/29/2004..10/10/2006
  • genre:rock year:<1990 NOT artist:jack
  • folder:"Sample Music" barra*
  • filename:M?c?o*ft
  • tags:(hamster baseball religion)
  • from:(Bill OR Steve)
  • from:Bill OR to:Ray
  • importance:high
  • kind:docs

And here are some facts about AQS that were illustrated above:

  • If you just type arbitrary words, they will be searched for in the content of items as well as in the properties of those items. But if you write a property followed by a colon and then a word, Vista will look for the word in that property only. So 'author:Darrell' searches for items that have the word Darrell somewhere in the author property.
  • You can search for items by date and/or time and there are various date/time properties to use. The property 'date' is "some useful date associated with the item" and every item has it so when you are searching for items of any kind by date, it's a handy property to use.
  • When specifying a date, you can either use an absolute date (as in '10/15/2007' or 'Jan 2006') or a relative date (as in 'yesterday', 'last week' or 'this month'). You can also specify an explicit range, as in '6/29/2004..10/10/2006'. (Go ahead, try 'yesterday..tomorrow' or '9/24/2000..next year', they work too.)
  • You can stick an operation such as '<', '>', '<=', '>=' in front of a value to look for anything before or after (inclusive or not) that value, so 'year:<1990' will find songs published before 1990.
  • If you want to exclude items that contain some word, use NOT, which must then be in upper case (so you can search for the word 'not' by writing it in lower case). Actually you can use NOT not only for words but also together with date/time, etc, so 'date: NOT 2006' or 'NOT date:2006' will find items with a primary date that is not in 2006.
  • If you write more than one condition, Vista will only return items that satisfy all conditions. So 'genre:rock year:<1990 NOT artist:jack' will return items that have a genre of 'rock', were published before 1990, and that do not contain the word 'jack' in the artist property. You could also stick the word AND (in upper case) between the conditions but if conditions simply follow each other, AND is what we assume anyway.
  • You can search for a phrase by enclosing it in doublequotes. So "Kurt Bloch" (with the doublequotes) will search for items that have the word 'Kurt' somewhere immediately followed by the word 'Bloch'. Here we really mean the words 'Kurt' and 'Bloch', not words beginning with 'Kurt' and 'Bloch'. If you want to search for items that have a word beginning with 'Kurt' immediately followed by a word beginning with 'Bloch', type "Kurt Bloch"* (with the star immediately following the closing doublequote).
  • If you put a star '*' immediately after a word, it means to search for anything beginning with that word. So 'barf' and 'barf*' both search for anything beginning with 'barf'. How silly, you might think, but actually one can turn off the automatic "partial matching" in the Folder and Search Options, and then it's very handy to have a way of getting the "partial matching" when you really want it.
  • So, 'folder:"Sample Music" barra*' will find any item that resides in a folder with a name that has the word 'Sample' (really) followed by the word 'Music' (really), and that has some word beginning with 'barra'.
  • If you think you miss good old DOS wildcards, the good news is that you can use them, too: '?' matches one arbitrary character, '*' matches any number of characters. The bad news is that such queries run much, much slower than others (exception: just a '*' at the end of a word, as above, doesn't bring the speed down). But sometimes this is just what you want, so go buy a short, nonfat latte while the computer finds every item that has a file name matching 'M?c?o*ft' (actually it only has to begin with that, just like for regular words).
  • Using parentheses you can group together multiple words, which will all be searched for. So 'tags:(hamster baseball religion)' finds items that have all three tags 'hamster', 'baseball' and 'religion', in any order. It would find exactly the same things as the query 'tags:hamster tags:baseball tags:religion'. If you stick extra parentheses around things, they are simply ignored, so 'tags:(((latex)))' is the same query as 'tags:latex'.
  • If you put OR between words, we will search for items that contain either. This often requires using parentheses if only a certain property is to be searched. 'from:(Bill OR Steve)' will find all your items that have a sender with either the word 'Bill' or the word 'Steve' in them.
  • OR can go between larger chunks as well, so 'from:Bill OR to:Ray' finds items that either have 'Bill' in the sender or 'Ray' in the recipient. Sometimes you want to use them with parentheses to be sure there is no misunderstanding, as in '(from:Bill OR to:Ray) tags:bowling' that will find items with 'bowling' among the tags and that are either from 'Bill' or to 'Ray'. On a bit of a tangent, note that 'from:Bill Ramsey' will not look for items with 'Bill Ramsey' as sender. It will look for items having a sender with 'Bill' in it and 'Ramsey' anywhere (in the contents, for example). To really look for items with Bill Ramsey as sender, try 'from:(Bill Ramsey)' or 'from:"Bill Ramsey"', depending on how exact a match you want.
  • Finally, some properties contain special values that you don't really want to keep track of what they are but search for anyway. So you can write 'importance:high' and not have to know that this looks for a value of 5 in the importance property. Or you can write 'kind:docs' and not have to care that it actually will search for items with a kind containing 'document'.

When you use "Advanced Search" in the Search Home, pay attention to the search box. As you compose a query in the "query builder", it will put the corresponding AQS in the search box. Another time you might try simply typing an AQS query yourself if it saves you time!

My final tip is that AQS works also when searching in Outlook 2007, though only for Outlook properties.

And if the title reminded you of something in your CD collection, you rock!

Comments

  • Anonymous
    March 13, 2007
    There is a major difference between file search on Windows XP and desktop search on Windows Vista (or