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.