QueryOptions Class

指定用于枚举存储文件夹内容的搜索查询的参数。

语法


var queryOptions = new Windows.Storage.Search.QueryOptions();
var queryOptions = new Windows.Storage.Search.QueryOptions(query);
var queryOptions = new Windows.Storage.Search.QueryOptions(query, fileTypeFilter);

特性

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

成员

QueryOptions类 具有这些类型的成员:

构造函数

QueryOptions类 具有这些构造函数。

构造函数说明
QueryOptions() Creates an instance of the QueryOptions class for enumerating storage items, and initializes it with the following default settings: QueryOptions.FolderDepth gets FolderDepth.Shallow and QueryOptions.IndexerOption gets IndexerOption.DoNotUseIndexer.
QueryOptions(CommonFileQuery, IIterable(String)) Creates an instance of the QueryOptions class for enumerating files and initializes it with values provided by the specified CommonFileQuery and an optional file type filter that determines which files to include in query results.
QueryOptions(CommonFolderQuery) Creates an instance of the QueryOptions class for enumerating subfolders and initializes it with values based on the specified CommonFolderQuery.

 

方法

The QueryOptions 类 具有这些方法。 对于 C#、Visual Basic 和 C++,它还继承方法于Object 类.

方法说明
LoadFromString Initializes the current instance of the QueryOptions class with search parameters specified by a string that was created by the SaveToString method.
SaveToString Converts the values of a QueryOptions object to a string that can be used to initialize the values of a QueryOptions object by calling LoadFromString.
SetPropertyPrefetch Specifies properties that the system should load in advance for all items in the query result set while the query is being executed (instead of retrieving them on a case-by-case basis).
SetThumbnailPrefetch Specifies the type and size of thumbnails that the system should start loading immediately when items are accessed (instead of retrieving them on a case-by-case basis).
StorageProviderIdFilter Gets the filter for storage provider identifiers.

 

属性

QueryOptions类 具有这些属性。

属性访问类型说明

ApplicationSearchFilter

读/写Gets or sets an application-defined Advanced Query Syntax (AQS) string for filtering files by keywords or properties. This property is combined with the UserSearchFilter to create the query's search filter.

DateStackOption

只读Gets the unit of time used to group files into folders if the QueryOptions object was created with a CommonFolderQuery based on date.

FileTypeFilter

只读Gets a list of file name extensions used to filter the search results. If the list is empty, the results include all file types.

FolderDepth

读/写Indicates whether the search query should produce a shallow view of the folder contents or a deep recursive view of all files and subfolder.

GroupPropertyName

只读Gets the name of the property used to group query results if the QueryOptions object was created using a CommonFolderQuery.

IndexerOption

读/写Gets or sets a value that specifies whether the system index or the file system is used to retrieve query results.

Language

读/写Gets or sets the Internet Engineering Task Force (IETF) language tag (BCP47 standard) that identifies the language associated with the query. This determines the language-specific algorithm used by the system to break the query into individual search tokens.

SortOrder

只读Gets the list of SortEntry structures that specify how to sort content (like files and subfolders) in query results.

UserSearchFilter

读/写Gets or sets a user-defined Advanced Query Syntax (AQS) string for filtering files by keywords or properties. This property is combined with the ApplicationSearchFilter to create the query's search filter.

 

备注

您可以创建自己有权访问任何文件夹的一个文件查询,并可以作为 StorageFolder 获取。

可以使用 QueryOptionsCreateFileQueryWithOptions 来创建让您获取依赖于另一个应用程序的处理程序的属性的索引备份文件查询。

有关演示如何使用 QueryOptions 的更多代码示例,请参见文件夹枚举示例文件系统搜索示例

有关访问属性的更多代码示例,请参见文件访问示例

Windows Phone 8

此 API 不实现,但是调用时会引发异常。请参见 Windows Phone 运行时 API

示例

此示例演示在如何在一个位置中使用 QueryOptions 查询文件。



// Set query options with filter and sort order for results
var fileTypeFilter = [".jpg", ".png", ".bmp", ".gif"];
var queryOptions = new Windows.Storage.Search.QueryOptions(search.CommonFileQuery.orderByName, fileTypeFilter);

// Create query and retrieve files
var query = Windows.Storage.KnownFolders.picturesLibrary.createFileQueryWithOptions(queryOptions);
query.getFilesAsync().done(function (files) {
    // Process results
    files.forEach(function (file) {
        // Process file
    });
});

前面的示例依赖于通过 PicturesLibrary 获取 StorageFolder 对象的图片库功能。要了解关于访问文件和文件夹的详细信息,请参见 Windows 应用商店应用中的文件访问和权限

此示例演示如何使用由系统索引支持的文件查询来检索依赖于另一应用程序的属性处理程序(如 Title 文档属性)的文件。



// Create index backed file query and get results
var documentsLibrary = Windows.Storage.KnownFolders.documentsLibrary;
var fileTypeFilter = [".docx"];
var queryOptions = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderByName, fileTypeFilter);
queryOptions.indexerOption = Windows.Storage.Search.IndexerOption.onlyUseIndexer;
var fileQuery = documentsLibrary.createFileQueryWithOptions(queryOptions);
fileQuery.getFilesAsync().then(function (files) {
    // Process resulting files
    if (files.size === 0) {
        // Perform tasks to handle no files found
    } else {
        // Access properties for each file
        files.forEach(function (file) {
            // Get document properties
            file.properties.getDocumentPropertiesAsync().done(function (documentProperties) {
                // Perform tasks with document properties
                var title = documentProperties.title;
            });
        });
    }
},
// Handle errors with an error function
function (error) {
    // Handle errors encountered while processing files
});

前面的示例依赖于通过 DocumentsLibrary 获取 StorageFolder 对象的文档库功能。要了解关于访问文件和文件夹的详细信息,请参见 Windows 应用商店应用中的文件访问和权限

在示例中,file 包含在表示文件以检索属性的 StorageFile

要求

最低支持客户端

Windows 8 [仅 Windows 应用商店应用程序]

最低支持服务器

Windows Server 2012 [仅 Windows 应用商店应用程序]

最低支持电话

Windows Phone 8 [未实现,请参见备注]

命名空间

Windows.Storage.Search
Windows::Storage::Search [C++]

元数据

Windows.winmd

 

 

显示:
© 2014 Microsoft