Become a Windows Search ninja with Advanced Query Syntax

Microsoft has been evolving Windows Search for a long time, starting with an MSN-based add-on to Windows XP about five years ago. The version in Windows 7 has a whole bunch of surprising (in a good way) and useful stuff under the hood (like a GREP search engine that is able to handle some types of searches that were difficult in Windows Vista). We spend two full chapters in Windows 7 Inside Out on Windows Explorer and Windows Search. It was an eye-opener for me to research and write those chapters, and I recommend them to everyone who buys the book.

This week I got a request from a reader that initially stumped me. Here’s the question:

I want to be able to search for all jpg files in a particular folder where the filename starts with an S.

It would be the equivalent of dir s*.jpg.  These files have several descriptive words in them, however, and if I type s or s* in the search box I get every file that has an s somewhere in it or that has a word embedded in it that starts with S.  I have a hard time believing that Windows 7 search isn’t up to the task!  What am I missing?

The answer, it turns out, is Advanced Query Syntax. Here’s how we introduce it in the book:

You might not consider yourself a search ninja, but if you’ve typed a keyword or two in the search box and built a point-and-click search filter, you’ve taken the first steps on that path. To become a search ninja, you must master Advanced Query Syntax (AQS), which is the official name for the set of rules that Windows Search follows when interpreting what you type in the search box. (You’ll find detailed documentation of AQS at http://w7io.com/0903.)

I use AQS all the time, especially to find e-mail. If I click Start and type from:carl sent:this week in the Search box, I find every message anyone named Carl sent me this week. And if I enter type:doc name:ch* I get every Word document, PDF, or text file, that contains a word beginning with ch anywhere in its name, whether it’s saved on my hard disk or as an attachment in Outlook. So I can find Chapter 1.docx as well as an e-mail whose subject contains the word check and that contains a text attachment.

So how do I get the results my questioner was asking for? As he correctly observes, the asterisk wildcard doesn’t work. The first problem is that the index includes all text in every indexed file and its properties. Thus, typing s*.jpg finds every file that has the .jpg extension and includes any word beginning with s.

For his request, we whip out AQS and use the name: operator to restrict our request to just file names, ignoring file properties and contents. And we add the obscure .. operator. That’s two dots, used between two values to indicate a range. To find JPEG files that begin with the letter s, use this syntax in the Start menu Search box or in the Search box in the upper right corner of a library in Windows Explorer:

type:JPEG name:s..t

Ta-da! That does the trick by finding any file in the JPEG format (whether it uses the .jpg or .jpeg extension) and it restricts the list to files whose names are in a range that starts with the letter s and ends with t. (If you want to be a purist, you could make the range s..szzzz and eliminate the change of accidentally including a file named t.jpg in your results.)

If you have Windows 7 Inside Out, take a look at Chapters 8 and 9 for much more on how you can become a search Ninja. The AQS stuff begins on page 325.

13 thoughts on “Become a Windows Search ninja with Advanced Query Syntax

    1. That will mostly work. However, it turns up any .jpg file whose name ENDS in s. It misses JPEG files with a .jpeg extension. And it turns up files that contain that phrase within them, like my draft of this blog post. It also goes haywire with Outlook messages.

  1. Why there isn’t an interface for this? Why do I have to learn and memorize complex query syntax to perform simple search tasks?!

    The search GUI in Windows 7 is very much nothing, it’s just a search box, simple but not easy. (I hope people can differentiate between ‘simple’ and ‘easy’ terms)

    In XP things were better, in Vista they trimmed it a bit more and in Windows 7 they trimmed most of the search GUI, and now it’s all syntax and command like it was back in the DOS days, what the heck?

    At least the basics and a little bit beyond the basic should be provided in GUI, then for more advanced stuff one can learn the complicated AQS thing, don’t you think?

    -M

    1. Mike, there IS an interface for this stuff. A very nice one, in fact, which I spend a lot of time documenting in the book. You just click in the search box and you get to set all available properties. Once you learn how it works I think you’ll never wanbt that fill-in form again.

  2. It appears to me that OneNote has its own search engine. Between the two (Office search is now even better with your tips) I can find things super-fast. I also enable Indexing in services. Is that redundant, or not?

  3. As Ed says, using the properties from the search box is too good an experience. I use it to search for the pictures based on dates.

    1. I certainly didn’t mean to imply that this is new. In fact, AQS in various forms has been around for years, including as an add-on for Windows XP beginning in 2005. But there are still a lot of changes in search for Windows 7 that anyone who uses it should know about.

  4. Ed, I’ve been reading Windows 7 Inside Out. I must congratulate you and your fellow co-authors for a great job. I found the writing formal but very informative, comprehensive, and all-encompassing. I especially liked Chaters 8, 9 and 10: I discovered lots of new things about Windows that I thought I already knew. Moreover, when it was necessary for you to use technical jargon, it was always explained in a manner that could be understood even my a neophyte. Many kudos.

  5. @suc: AQS has been around since Vista, but searching using properties is something new in windows 7. That is way better compared to using AQS.

  6. Thanks, I too like the book

    Slightly off-topic but readers (and EB in next edition of book?) please note that in my W7 installation at least, in
    Control Panel, Indexing Options, Advanced, File Types tab: I needed to add a check to get search in contents for rich text format files ( .rtf ) as this was not set by default.

    BTW – I agree that W7 search has a lot to offer but also agree that there should have been a GUI like the W98 interface. Try telling my mother that with careful study of two chapters of a book she will be able to find all sorts of things. One short paragraph would be pushing it.

Comments are closed.