Windows 7 / Getting Started

Advanced Query Syntax

AQS is a syntax used for creating complex search queries using the Search feature of Windows 7. AQS is not case sensitive (except for the Boolean operators AND, OR, and NOT) and uses the implicit AND when multiple search terms are specified. Supported syntax includes the following:

  • Logical operators. AND (or + prefixed to term), OR, and NOT (or <;$MI> prefixed to term) plus parentheses for grouping. (No assumption should be made about the relative precedence between AND, OR, and NOT, so parentheses should always be used to make queries unambiguous.)
  • Individual words. By default partial matches are accepted, so a query sea will return items with "sea", "seal", "Seattle", etc. Partial matches will always be accepted, even when the Find partial matches setting is off, if a word ends with a wildcard character (*). Thus a query sea* will always return items containing any word beginning with "sea". Multiple words separated by punctuation but no white space will implicitly be treated like a phrase, so a query love/hate will search for the word "love" immediately followed by the word "hate". The search is done across all (string) properties.
  • Exact phrases enclosed in double quotes. For example, a query "Majestik MØØse" will return items containing those two words in sequence. (There is an indexing option controlling whether diacritics such as that in "Ø" need to be matched exactly.) If a wildcard character (*) follows immediately after the closing double quote, partial matches will be accepted for each word in the phrase, so a query "my dog"* will return items containing the phrase "mystic dogfood". The double quotes also make sure that the enclosed words are interpreted literally, rather than as AQS keywords. The search is done across all (string) properties.
  • Property searches on the form Property: Operation Value, where Operation is optional and one of those described below. Property is any term identifying a property of an item; in particular, the label of a property is a valid AQS keyword. For string-valued properties, Value is any word or phrase as described above, while for properties with other types of values (such as integer, date/time, or Boolean), values are recognized according to the user locale. An item is returned if Value is found in Property in the way specified by Operation (see below). If Operation is omitted, word search is used for string-valued properties and = is used for other properties. For example, a query tags:Michael returns documents where the Tags property contains (a word beginning with) "Michael", while a query taken:>2007 returns taken in the year 2007 or later.
  • Comparison operations include >, >=, <, <=, =, and <>, with the obvious meanings, and can be applied to numeric properties as well as string and date/time properties.
  • Character-based operations include ~< (value starts with), ~> (value ends with), and ~~ (value contains). For example, a query author:~>ing returns items for which the Author property ends with the characters "ing", while a query title:~~"ill a mock" returns items containing the character sequence "ill a mock" anywhere in the Title property (when used with these operations, the double quotes allow white space in the search string). The character operations are generally much slower than the word-based operations. The character operations can only be applied to specific properties; there is no syntax for searching for an arbitrary character sequence across all properties.
  • The fourth character-based operation is ~, which interprets the wildcard character (*) and the single wildcard character (?) like the file system does: matching zero or more arbitrary characters and matching one arbitrary character, respectively. For example, a query author:~?oe will return items in which the Author property is "joe" or "moe". (Note that the match will be against the whole value, so a more realistic query may be author:~"?oe *", which will return items where the second, third and fourth characters are "o", "e" and a space, respectively, with anything in the other characters.)
  • Word search and word prefix search can be specified explicitly using the operations $$ and $<, respectively (but because they are the default operations for string-valued properties, this is rarely necessary).
  • The special value [] represents "no value" or "null value." So the query tag:=[] returns all items that have no value for the Tags property, while the query tag:<>[] (or -tag:=[], or tag:-[]) returns all items that have a value for the Tags property.
  • For any property that has "symbolic" values, these strings can be used as values in AQS. For example, importance:normal returns all items where the Importance property is between 2 and 4, size:small returns all items with a Size between 10241 and 102400, kind:docs returns all items where Kind contains "document", and flashmode:flashredeye returns all images where the Flash mode property is 65.
  • There are also symbolic values for some relative date values: today, yesterday, tomorrow, this week, last week, next week, this month, last month, next month, this year, last year, and next year. These all denote the current, previous, or next complete calendar day/week/month/year. One can also specify the last day, the next day, the last week, the next week, the last month, the next month, the last year, and the next year. These denote a time period of the specified length beginning or ending at the current time. For example, modified:last month (or modified:lastmonth; the space is optional here) returns items where the Date Modified property has a value in the previous calendar month, while taken:the last week (or taken:thelastweek) returns pictures with Date taken in the previous 24 x 7 hours. As mentioned above, one can also use absolute date/time values expressed according to the user's locale; so if the user locale is Thai with the Thai solar calendar, a query created:19/6/2552 or created:19 2552 will return items created on the day that is June 19, 2009 in the Gregorian calendar.
  • A range of values can be specified as FirstValue .. LastValue. For example, taken:March 2007 .. June 2008 will return pictures taken between March 1, 2007 and June 30, 2008 (assuming a user locale that uses the Gregorian calendar).
  • Integer suffixes for kilobytes, Megabytes, etc., are recognized, so a query size:<=1MB will return items with a size that is at most 1,048,576 bytes.
  • There are some "virtual" properties for special purposes available only through AQS: before:DateTime and after:DateTime return items where the primary Date property is less than or greater than the specified date/time. from: searches over both sender name and address of messages; similarly, so does to:, cc:, bcc:, organizer:, required:, optional: and resources:. Likewise, file: will interpret its value as some combination of a path, a file name, and a file extension, and ? and * will be interpreted as wildcards. So the query file:report*.doc will return all documents having a name beginning with "report" and a "doc" extension; a query file:report?.doc will return all documents with a name consisting of "report" plus one character and a "doc" extension; a query file:\\lab\files\* will return all files with a path rooted in "\\lab\files"; while a query file:"C:\Program Files\SomeCompany\*\*.log" will return all files with extension "log" under the folder "C:\Program Files \SomeCompany".
  • One can delimit the scope of a search by placing restrictions on properties such as Folder, Folder path, File path, and File name. For example, folder:"My Stuff" returns items from any folder having the phrase "My Stuff" in the name, and folderpath:~<"C:\Budgets\2006\" returns items from "C:\Budgets\2006" and its subfolders.
  • What goes after Property: may actually be multiple values combined using AND, OR, and NOT, each with an optional operation; so a query kind:(communication -email) will return items that have Kind "communication" but not "email" (note that Kind is a multivalued property), and taken:(> last month < next month) would be a somewhat convoluted way of expressing the same query as taken:this month.
  • Property names and symbolic values must all be expressed in the user's default UI language to be recognized as such. In this way, users can express queries in a language consistent with the rest of their UI. This means that a query title:zoo will return items with "zoo" in the title for a user with English UI but not for one with Swedish UI. In order to make it possible to write queries (for programmatic use) that work regardless of the user's UI language, the synonyms for each property include the "canonical name" of that property. For example, the canonical form of the previous query is System.Title:zoo (or even System.Title:$<zoo to make sure that partial matching will be used).
  • A more relaxed form of AQS in which colons are not required after property names is activated by using the Use Natural Language Search option, which allows users to create queries that resemble natural language. When this option is turned on, a query music by REM will return items with Kind music created by REM (by is a synonym for the Creators property). This is a somewhat experiemental feature as it increases ambiguity (a word to be searched for may be misinterpreted as a property name, for example) and should be used with caution.

For more information on AQS, see http://msdn.microsoft.com/en-us/library/bb266512.aspx on MSDN and http://www.microsoft.com/windows/products/winfamily/desktopsearch/technicalresources/advquery.mspx. To build complex search queries without using AQS, use the Advanced Search pane described previously in this tutorial.

[Previous] [Contents] [Next]

In this tutorial:

  1. Managing Search
  2. Search and Indexing Enhancements
  3. Search in Windows XP
  4. Search in Windows Vista
  5. Search in Windows 7
  6. Understanding the Windows Search Versions
  7. Search Versions Included in Windows 7 and Windows Vista
  8. Search Versions Included in Windows Server 2008
  9. Search Versions Available for Earlier Versions of Windows
  10. How Windows Search Works
  11. Understanding Search Engine Terminology
  12. Windows Search Engine Processes
  13. Enabling the Indexing Service
  14. Windows Search Engine Architecture
  15. Understanding the Catalog
  16. Default System Exclusion Rules
  17. Understanding the FANCI Attribute
  18. Default Indexing Scopes
  19. Initial Configuration
  20. Understanding the Indexing Process
  21. Modifying IFilter Behavior
  22. How Indexing Works
  23. Rebuilding the index
  24. Viewing Indexing Progress
  25. Understanding Remote Search
  26. Managing Indexin
  27. Configuring the Index
  28. Configuring the Index Location Using Group Policy
  29. Configuring Indexing Scopes and Exclusions Using Group Policy
  30. Configuring Offline Files Indexing
  31. Configuring Indexing of Encrypted Files
  32. Configuring Indexing of Encrypted Files Using Control Panel
  33. Configuring Indexing of Similar Words
  34. Configuring Indexing of Text in TIFF Image Documents
  35. Other Index Policy Settings
  36. Using Search
  37. Configuring Search Using Folder Options
  38. Configuring What to Search
  39. Configuring How To Search
  40. Using Start Menu Search
  41. Searching Libraries
  42. Advanced Query Syntax
  43. Using Federated Search
  44. Deploying Search Connectors
  45. Troubleshooting Search and Indexing Using the Built-in Troubleshooter