IndexableContent
指示应为搜索索引元素的文本,但不与属性关联。 请注意,稍后可以基于属性键检索属性,但不能检索文本内容。
<element
sc:IndexableContent= "true" | "false" | "1" | "0"
xmlns:sc="http://schemas.microsoft.com/Search/2013/ApplicationContent">
</element>
数据类型
此属性接受布尔值:
true
false
1
0
示例
此示例显示了一个简单的 appcontent 文件,该文件描述名为 "Sample 1" 的项。
请注意,该文件包含未由 appcontent-ms 架构定义的元素: IndexerSampleInformation
和 IndexerSampleSpecificElement
。 Appcontent 文件必须有一个根节点,该节点封装要编制索引的所有数据,但您可以将该节点命名为所需的任何内容。
<?xml version="1.0" encoding="utf-8"?>
<IndexerSampleInformation>
<Properties xmlns="http://schemas.microsoft.com/Search/2013/ApplicationContent">
<Name>Sample 1</Name>
<Keywords>
<Keyword xml:lang="en-US">Sample 1 - keyword 1</Keyword>
<Keyword>Sample 1 - keyword 2</Keyword>
</Keywords>
<Comment>Sample 1 comment</Comment>
<AdditionalProperties>
<Property Key="System.Title">Sample 1 Title</Property>
<Property xml:lang="en-US" Key="System.Contact.EmailAddresses">
<Value>bryan@contoso.com</Value>
<Value>vincent@contoso.com</Value>
</Property>
</AdditionalProperties>
</Properties>
<IndexerSampleSpecificElement sc:IndexableContent="true"
xmlns:sc="http://schemas.microsoft.com/Search/2013/ApplicationContent">
The text included here will be indexed, enabling full-text search.
</IndexerSampleSpecificElement>
</IndexerSampleInformation>
甚至可以告诉 Windows 搜索来为任意元素的内容编制索引。 只需使用 IndexableContent 特性告诉搜索来为内容编制索引。 在前面的示例中,Windows Search 将为 IndexerSampleSpecificElement 的内容编制索引,因为IndexableContent属性设置为true:
<IndexerSampleSpecificElement sc:IndexableContent="true"
xmlns:sc="http://schemas.microsoft.com/Search/2013/ApplicationContent">
The text included here will be indexed, enabling full-text search.
</IndexerSampleSpecificElement>
默认情况下,搜索将内容视为文本内容;如果内容为 base64,则使用 " ContentType " 属性指定 MIME 类型。
下一个示例演示如何将 appcontent-ms 文件复制到应用程序的 LocalFolder\Indexed 文件夹。 此代码会将在应用程序的 appcontent-ms 文件夹中找到的所有文件复制到 LocalFolder\Indexed 文件夹。 (您还可以在索引文件夹中直接创建新的 appcontent 文件,而不是从其他位置复制它们。 )
/// <summary>
/// For the purposes of this sample, the appcontent-ms files are stored in an "appcontent-ms" folder in the
/// install directory. These are then copied into the app's "LocalState\Indexed" folder, which exposes them
/// to the indexer.
/// </summary>
public async static Task<string> AddAppContentFilesToIndexedFolder()
{
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var installDirectory = Windows.ApplicationModel.Package.Current.InstalledLocation;
var outputString = "Items added to the \"Indexed\" folder:";
var appContentFolder = await installDirectory.GetFolderAsync("appcontent-ms");
var indexedFolder = await localFolder.CreateFolderAsync(
"Indexed", Windows.Storage.CreationCollisionOption.OpenIfExists);
var files = await appContentFolder.GetFilesAsync();
foreach (var file in files)
{
outputString += "\n" + file.DisplayName + file.FileType;
await file.CopyAsync(indexedFolder,
file.Name, Windows.Storage.NameCollisionOption.ReplaceExisting);
}
return outputString;
}
// For the purposes of this sample, the appcontent-ms files are stored in an "appcontent-ms" folder
// in the install directory. These are then copied into the app's "LocalState\Indexed" folder,
// which exposes them to the indexer.
function _addAppContentFilesToIndexedFolder() {
var localFolder = appData.localFolder,
appcontentFolder,
indexedFolder,
installDirectory = Windows.ApplicationModel.Package.current.installedLocation;
var output = "Items added to the \"Indexed\" folder:\n";
installDirectory.getFolderAsync("appcontent-ms").then(function (retrievedAppcontentFolder) {
appcontentFolder = retrievedAppcontentFolder;
return localFolder.createFolderAsync(
"Indexed", Windows.Storage.CreationCollisionOption.openIfExists);
}).then(function (retrievedIndexedFolder) {
indexedFolder = retrievedIndexedFolder;
return appcontentFolder.getFilesAsync(appcontentFolder);
}).then(function (files) {
var promiseArray = [];
for (var i = 0, len = files.length; i < len; i++) {
promiseArray[i] = files[i].copyAsync(indexedFolder,
files[i].name, Windows.Storage.NameCollisionOption.replaceExisting);
output += files[i].displayName + files[i].fileType;
if (i < len - 1) {
output += "\n";
}
}
return WinJS.Promise.join(promiseArray);
}).done(function () {
WinJS.log && WinJS.log(output, "sample", "status");
});
}
有关完整的代码,请参阅 索引器示例。
要求
最低受支持的客户端 |
Windows 8.1 [仅桌面应用] |
最低受支持的服务器 |
Windows Server 2012 R2 [仅桌面应用] |
请参阅