在 Windows Vista 及更高版本中,用户可以将搜索另存为搜索文件夹,该文件由 XML 文件生成,该文件以 Windows 搜索子系统可以使用的表单存储查询。 本主题介绍文件格式(*.search-ms),并包含以下部分:
- 保存的搜索 概述
- <viewInfo> 元素
- <查询> 元素
- 元素<>属性
- search-ms 文件格式 的完整规范
- 保存的搜索 示例
已保存搜索概述
用户可以将搜索查询另存为搜索文件夹,该文件夹显示在“搜索”文件夹下的 Windows 资源管理器中。 打开搜索文件夹会运行保存的搜索,并显示 up-to日期结果。 保存的搜索文件以 Windows 搜索可以处理的格式存储查询,指定要搜索的内容、搜索位置以及如何显示结果。
保存的搜索是从 %userprofile%\Search 文件夹中的 XML 文件(*.search-ms)生成的。 数据分为 XML 文件中的三个主要元素:
- <viewInfo> 指定演示文稿信息
- <查询> 指定(搜索查询信息)
- <属性> 指定 *.search-ms 文件本身的属性
以下示例显示了保存的搜索文件的概要结构。
<?xml version="1.0"?>
<persistedQuery version="1.0">
<viewInfo ...>
...
</viewInfo>
<query>
...
</query>
<properties>
...
</properties>
</persistedQuery>
<viewinfo> 元素
<viewInfo> 元素指定如何向最终用户显示结果。 下面的示例演示元素的结构。
...
<viewInfo viewMode=""
iconSize=""
stackIconSize=""
autoListFlags=""
folderFlags=""
taskFlags=""
displayName="">
<visibleColumns>
<column viewField=""/>
</visibleColumns>
<frequentlyUsedColumns>
<column viewField= ""/>
</frequentlyUsedColumns>
<columnChooserColumns >
<column viewField=""/>
</columnChooserColumns >
<groupBy viewField=""
direction=""/>
<stackList>
<stack viewField=""/>
</stackList>
<sortList>
<sort viewField=""
direction=""/>
</sortList>
</viewInfo>
...
<viewinfo> 属性
下表描述了 <viewInfo> 元素的属性。
| 属性 | 描述 | 值 |
|---|---|---|
| viewMode | 指定文件夹视图。 | 详细信息 |图标 |瓷砖 |
| iconSize | 控制不堆叠时项的图标和缩略图的默认大小。 | 介于 16 和 256 之间的整数 |
| stackIconSize | 仅供内部使用。 请勿使用。 | n/a |
| displayName | 仅供内部使用。 请勿使用。 | n/a |
| autoListFlags | 仅供内部使用。 请勿使用。 | n/a |
| folderFlags | 仅供内部使用。 请勿使用。 | n/a |
| taskFlags | 仅供内部使用。 请勿使用。 | n/a |
<viewinfo> 子元素
<viewInfo> 元素的子元素指定 Windows 资源管理器搜索结果中显示的列以及结果的分组和排序方式。 每个子元素都包含一组有序的列,这些列由系统属性的规范名称(例如 System.DisplayName)标识。 如果未在保存的搜索文件中定义,则搜索结果将显示一组适合所显示的文件类型的默认列。
| 元素 | 描述 | 值 |
|---|---|---|
| visibleColumns | 指定要显示在结果视图中的列的有序列表。 用户可以更改此列表。 | 任何系统属性。 |
| frequentlyUsedColumns | 仅供内部使用。 请勿使用。 | n/a |
| columnChooserColumns | 仅供内部使用。 请勿使用。 | n/a |
| groupBy | 指定要对其结果进行分组的单个系统属性。 用户可以更改此值。 | 任何系统属性。 |
| sortList | 指定要按其对结果进行排序的列的有序列表。 | 最多四个系统属性。 用户可以更改此列表。 |
| stackList | 仅供内部使用。 请勿使用。 | n/a |
<query> 元素
<查询> 元素指定定义如何查询结果的属性。 下面的示例演示元素的结构。
...
<query>
<providers>
<provider clsid=""/> <!-- Do not use -->
</providers>
<subQueries>
<subQuery path=""/> <!-- Do not use -->
<subQuery knownSearch=""/> <!-- Do not use -->
</subQueries>
<scope>
<include path="" nonRecursive=""/> <!-- [path of location to include] -->
<include knownFolder="" nonRecursive=""/> <!-- Known folder ID -->
<exclude path="" nonRecursive=""/> <!-- [path of location to exclude] -->
<exclude knownFolder="" nonRecursive=""/> <!-- Known folder ID -->
</scope>
<kindList>
<kind name=""/> <!-- Kind value -->
</kindList>
<conditions>
<condition type="" ...> <!-- andCondition | orCondition | notCondition | leafCondition -->
<attributes>
<attribute attributeID="" .../> <!-- Do not use -->
</attributes>
</condition>
</conditions>
</query>
...
<查询> 子元素
下表描述了 <范围> 元素的子元素。
| 元素 | 描述 | 价值 |
|---|---|---|
| 供应商 | 仅供内部使用。 请勿使用。 | n/a |
| subQueries | 仅供内部使用。 请勿使用。 | n/a |
| Scope | 标识要包括在搜索中或排除的位置。 | 要包含或排除的位置的路径或 已知文件夹 ID。 此元素还可以指定搜索是否应包括/排除子路径(浅搜索或深度搜索)。 |
| kindList | 标识要搜索的文件类型。 | 任何 System.Kind 值。 |
| 条件 | 指定筛选结果的规则。 例如,结果可能仅限于由特定人员或特定人员发送的电子邮件。 | andCondition、 orCondition, notCondition, leafCondition. |
<scope> 元素
<范围> 元素标识要从搜索中包括或排除的位置。 <范围> 元素必须至少包含一个 <包含> 子元素,零个或多个 <排除> 元素。 这些位置可以指定为路径(支持环境变量)或 已知文件夹标识符。 此外,可以通过将非递归设置为“true”或“false”(默认值为递归)来指定这些位置以深度或浅层搜索。 可以通过指定排除元素来排除包含的位置列表的各个部分。
下面显示了一个 <范围> 元素,该元素将搜索文档特殊文件夹,而不是其子文件夹、“E:”卷及其子目录,而不是“E:\windows”目录或其任何子目录:
...
<query>
...
<scope>
<include knownFolder="{FDD39AD0-238F-46AF-ADB4-6C85480369C7}" nonRecursive="true"/>
<include path="E:\"/>
<exclude path="E:\Windows" nonRecursive="false"/>
</scope>
...
</query>
...
<kindlist> 元素
这些元素定义应出现在库中的项的“种类”的并集。 有效值为:
- 日历
- 通信
- 联系
- 文档
- 电子邮件
- 信息提要
- 文件夹
- 游戏
- instantmessage
- 日志
- 链接
- 电影
- 音乐
- 注意
- 图片
- 程序
- recordedtv
- searchfolder
- 任务
- 视频
- webhistory
- 项
- 其他
<conditions> 元素
条件是与搜索结果进行比较的筛选器。 例如,可以筛选满足某些条件的结果,例如作者名称或文件大小。 条件集内置于具有逻辑 AND、OR 和 NOT 分支的单个条件树中。
以下示例显示了 <条件> 元素的结构。
...
<query>
...
<conditions>
<condition type="" ...>
<attributes>
<attribute attributeID="" .../>
</attributes>
</condition>
</conditions>
</query>
...
条件类型可以是下列条件之一:
| 类型 | 描述 | 可用属性 |
|---|---|---|
| andCondition | 两个或多个子条件的结合 | n/a |
| orCondition | 取消两个更多儿童条件 | n/a |
| notCondition | 对子条件的否定 | n/a |
| leafCondition | 将属性与值进行比较 | property, propertyType, 运算符, 值, valuetype |
<leafCondition> 元素的属性标识筛选结果的属性和值。
示例: <conditions> 元素
以下示例筛选 John 创作的所有未读项目的结果。 也就是说,System.IsRead 属性为 false,字符串“john”将显示在 System.Author 或 System.ItemAuthors 属性中。
...
<query>
...
<conditions>
<condition type="andCondition">
<condition type="leafCondition"
property="System.IsRead"
operator="eq"
value="FALSE"/>
<condition type="orCondition">
<condition type="leafCondition"
property="System.Author"
propertyType="string"
operator="wordmatch"
value="John"
valueType="System.StructuredQueryType.String"/>
<condition type="leafCondition"
property="System.ItemAuthors"
propertyType="string"
operator="wordmatch"
value="John"
valueType="System.StructuredQueryType.String"/>
</condition>
</condition>
</conditions>
</query>
...
<properties> 元素
<属性> 元素描述已保存的搜索本身的属性。 保存的搜索文件支持四个属性:<作者>、<类型>、<说明>和 <标记>。 这些仅供内部使用。
search-ms 文件格式的完整规范
下面是保存的搜索文件的完整 XML 示例。
<?xml version="1.0"?>
<persistedQuery version="1.0">
<!-- The viewInfo section defines how results are displayed to the end user -->
<viewInfo viewMode="" <!-- details | icons | tiles -->
iconSize="" <!-- Integer -->
stackIconSize="" <!-- Do not use -->
displayName="" <!-- Do not use -->
folderFlags="" <!-- Do not use -->
taskFlags="" <!-- Do not use -->
autoListFlags=""> <!-- Do not use -->
<visibleColumns>
<column viewField=""/> <!-- System.[propertyname] -->
</visibleColumns>
<frequentlyUsedColumns>
<column viewField= ""/> <!-- Do not use -->
</frequentlyUsedColumns>
<columnChooserColumns >
<column viewField=""/> <!-- Do not use -->
</columnChooserColumns >
<groupBy viewField="" <!-- System.[propertyname] -->
direction=""/> <!-- ascending | descending -->
<stackList>
<stack viewField=""/> <!-- Do not use -->
</stackList>
<sortList>
<sort viewField="" <!-- System.[propertyname] -->
direction=""/> <!-- ascending | descending -->
</sortList>
</viewInfo>
<!-- The query section defines what gets searched (locations, file kinds) -->
<query>
<providers>
<provider clsid=""/> <!-- Do not use -->
</providers>
<subQueries>
<subQuery path=""/> <!-- Do not use -->
<subQuery knownSearch=""/> <!-- Do not use -->
</subQueries>
<scope>
<include path="" nonRecursive=""/> <!-- [path of location to include] -->
<include knownFolder="" nonRecursive=""/> <!-- Known folder ID -->
<exclude path="" nonRecursive=""/> <!-- [path of location to exclude] -->
<exclude knownFolder="" nonRecursive=""/> <!-- Known folder ID -->
</scope>
<kindList>
<kind name=""/> <!-- Kind value -->
</kindList>
<conditions>
<condition type="" ...> <!-- andCondition | orCondition | notCondition | leafCondition -->
<attributes>
<attribute attributeID="" .../> <!-- Do not use -->
</attributes>
</condition>
</conditions>
</query>
<!-- The properties section identifies properties of the saved search file itself. -->
<properties>
... <!-- Do not use -->
</properties>
</persistedQuery>
保存的搜索示例
下面是 *.search-ms 文件的示例。
Recent documents.search-ms
<?xml version="1.0"?>
<persistedQuery version="1.0">
<viewInfo viewMode="details" iconSize="16">
<sortList>
<sort viewField="System.DateModified" direction="descending"/>
</sortList>
</viewInfo>
<query>
<conditions>
<condition type="leafCondition" valuetype="System.StructuredQueryType.DateTime" property="System.DateModified" operator="imp" value="R00UUUUUUUUZZXD-30NU" propertyType="wstr" />
</conditions>
<kindList>
<kind name="Document"/>
</kindList>
<subQueries>
<subQuery knownSearch="{4f800859-0bd6-4e63-bbdc-38d3b616ca48}"/>
</subQueries>
</query>
</persistedQuery>
Recent music.search-ms
<?xml version="1.0"?>
<persistedQuery version="1.0">
<viewInfo viewMode="details" iconSize="16">
<sortList>
<sort viewField="System.DateModified" direction="descending"/>
</sortList>
</viewInfo>
<query>
<conditions>
<condition type="leafCondition" valuetype="System.StructuredQueryType.DateTime" property="System.DateModified" operator="imp" value="R00UUUUUUUUW-1WNNU" propertyType="wstr"/>
</conditions>
<kindList>
<kind name="Music"/>
</kindList>
<subQueries>
<subQuery knownSearch="{4f800859-0bd6-4e63-bbdc-38d3b616ca48}"/>
</subQueries>
</query>
</persistedQuery>
最近由 me.search-ms 共享
<?xml version="1.0"?>
<persistedQuery version="1.0">
<viewInfo viewMode="details" iconSize="16">
<visibleColumns>
<column viewField="System.ItemNameDisplay"/>
<column viewField="System.DateModified"/>
<column viewField="System.Keywords"/>
<column viewField="System.SharedWith"/>
<column viewField="System.ItemFolderPathDisplayNarrow"/>
</visibleColumns>
<frequentlyUsedColumns>
<column viewField="System.Author"/>
<column viewField="System.Kind"/>
<column viewField="System.Size"/>
<column viewField="System.Title"/>
<column viewField="System.Rating"/>
</frequentlyUsedColumns>
<sortList>
<sort viewField="System.SharedWith" direction="descending"/>
</sortList>
</viewInfo>
<query>
<conditions>
<condition type="andCondition">
<condition type="leafCondition" property="System.IsShared" operator="eq" value="true"/>
<condition type="leafCondition" property="System.FileOwner" operator="eq" value="[Me]"/>
</condition>
</conditions>
<kindList>
<kind name="item"/>
</kindList>
<scope>
<include knownFolder="{5E6C858F-0E22-4760-9AFE-EA3317B67173}"/>
<include knownFolder="{DFDF76A2-C82A-4D63-906A-5644AC457385}"/>
</scope>
</query>
</persistedQuery>