ContentType

在元素上设置此属性指示将元素的内容视为指定 MIME 类型/内容类型的 base64 编码,并且使用该内容类型的处理程序编制索引。

<element
    sc:ContentType= "application/hta" | "application/mac-binhex40" | "application/vnd.ms-xpsdocument"
        | "application/windows-appcontent+xml" | "application/x-compress" | "application/x-compressed" 
        | "application/x-gzip" | "application/x-jtx+xps" | "application/x-latex"
        | "application/x-mplayer2" | "application/x-ms-wmz" | "application/x-stuffit"
        | "application/x-tar" | "application/x-wmplayer" | "application/x-zip-compressed"
        | "application/xml" | "audio/aiff" | "audio/basic" | "audio/mid" | "audio/midi"
        | "audio/mp3" | "audio/mpeg" | "audio/mpegurl" | "audio/mpg" | "audio/wav"
        | "audio/x-aiff" | "audio/x-mid" | "audio/x-midi" | "audio/x-mp3" 
        | "audio/x-mpeg" | "audio/x-mpegurl" | "audio/x-mpg" | "audio/x-ms-wax" 
        | "audio/x-ms-wma" | "audio/x-wav" | "image/bmp" | image/gif" 
        | "image/jpeg" | "image/pjpeg" | "image/png" | "image/vnd.ms-photo"
        | "image/x-emf" | "image/x-icon" | "image/x-png" | "image/x-wmf"
        | "midi/mid" | "model/vnd.dwfx+xps" | "model/vnd.easmx+xps" 
        | "model/vnd.edrwx+xps" | "model/vnd.eprtx+xps" | "pkcs7-mime"
        | "text/css" | "text/html" | "text/plain" | "text/xml"
        | "video/avi" | "video/mpeg" | "video/mpg" | "video/msvideo" 
        | "video/quicktime" | "video/x-mpeg" | "video/x-mpeg2a" 
        | "video/x-ms-asf" | "video/x-ms-asf-plugin" | "video/x-ms-wm"
        | "video/x-ms-wmv" | "video/x-ms-wmx" | "video/x-ms-wvx"
        | "video/x-msvideo"
        xmlns:sc="http://schemas.microsoft.com/Search/2013/ApplicationContent">
</element>

数据类型

此属性接受以下值之一:

  • application/hta
  • application/mac-binhex40
  • application/vnd.ms-xpsdocument
  • application/windows-appcontent+xml
  • application/x-compress
  • application/x-compressed
  • application/x-gzip
  • application/x-jtx+xps
  • application/x-latex
  • application/x-mplayer2
  • application/x-ms-wmz
  • application/x-stuffit
  • application/x-tar
  • application/x-wmplayer
  • application/x-zip-compressed
  • application/xml
  • audio/aiff
  • audio/basic
  • audio/mid
  • audio/midi
  • audio/mp3
  • audio/mpeg
  • audio/mpegurl
  • audio/mpg
  • audio/wav
  • audio/x-aiff
  • audio/x-mid
  • audio/x-midi
  • audio/x-mp3
  • audio/x-mpeg
  • audio/x-mpegurl
  • audio/x-mpg
  • audio/x-ms-wax
  • audio/x-ms-wma
  • audio/x-wav
  • image/bmp
  • image/gif
  • image/jpeg
  • image/pjpeg
  • image/png
  • image/vnd.ms-photo
  • image/x-emf
  • image/x-icon
  • image/x-png
  • image/x-wmf
  • midi/mid
  • model/vnd.dwfx+xps
  • model/vnd.easmx+xps
  • model/vnd.edrwx+xps
  • model/vnd.eprtx+xps
  • pkcs7-mime
  • text/css
  • text/html
  • text/plain
  • text/xml
  • video/avi
  • video/mpeg
  • video/mpg
  • video/msvideo
  • video/quicktime
  • video/x-mpeg
  • video/x-mpeg2a
  • video/x-ms-asf
  • video/x-ms-asf-plugin
  • video/x-ms-wm
  • video/x-ms-wmv
  • video/x-ms-wmx
  • video/x-ms-wvx
  • video/x-msvideo

示例

此示例演示一个简单的 appcontent-ms 文件,该文件描述名为"Sample 1"的项。

请注意,该文件包含 appcontent-ms 架构未定义的元素: 和 IndexerSampleInformationIndexerSampleSpecificElement。 appcontent-ms 文件必须具有一个根节点,该根节点封装要编制索引的所有数据,但你可以将节点命名为任何需要的名称。

<?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 属性告知 Search 为内容编制索引。 在上一示例中,Windows将索引 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-ms 文件,而不是从另一个位置复制这些文件。)

/// <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&#39;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&#39;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 &amp;&amp; WinJS.log(output, "sample", "status");
    });
}

有关完整代码,请参阅 索引器示例

要求

最低受支持的客户端

Windows 8.1 [仅桌面应用]

最低受支持的服务器

Windows Server 2012 R2 [仅桌面应用]

请参阅

索引器示例

Windows。存储。搜索