Partager via


Overview of the Search SQL Syntax

Microsoft Windows Search query is similar to a standard Structured Query Language (SQL) query. It is shown in the following syntax:

SELECT <columns>
FROM <catalogs>
WHERE <conditions>
RANK BY <conditions>
ORDER BY <columns>
GROUP ON <columns>

In the following query example, the document size, title, and relevance ranking are returned for documents that are larger than 10,000 bytes long and are part of the Portal Content scope. Each matching file is assigned the rank value of 1000 by Windows Search, and the results are sorted in ascending size order.

SELECT 
System.Document.PageCount,
System.CreateDate,
FROM SYSTEMINDEX
WHERE (System.Document.PageCount > 50)
ORDER BY System.Document.PageCount
GROUP ON System.Author OVER (SELECT System.CreateDate)

The Windows Search query syntax supports many options, enabling more complicated queries.

The following table describes each clause in the SELECT statement and the features it supports.

Clause Description
SELECT Specifies the columns returned by the query.
FROM Specifies the location to search. You can request that Windows Search check for matching documents in a given content index, in the specified folder only, or the specified folder and in all subfolders.
WHERE Specifies what constitutes a matching document. This clause has many options, enabling rich control over the search conditions. For example, you can match against words, phrases, inflectional word forms, strings, numeric and bitwise values, and multi-valued arrays. You can also apply statistical weights to the matching conditions, and combine matching conditions with Boolean operators.
RANK BY Specifies modifications to the normal methods for calculating rank. Allows you to specify weights for specific matching conditions, and to multiply or add values to the normal calculated rank results.
ORDER BY Specifies the sort order for the results returned by the query. You can specify more than one field on which the results are sorted, and you can use ascending or descending ordering.
GROUP ON Specifies how to group results returned by the query. You can specify the ranges by which to group and specify more than one column for grouping. For example, you can group results over a range of file sizes (size < 100, 100 <= size < 1000; 1000 <= size) and nest groupings.