共用方式為


關鍵字

描述專案的其中一個 系統關鍵字

元素階層

<屬性>
<關鍵字>
<關鍵字>

語法

<Keyword>

  string

</Keyword>

屬性和項目

屬性

無。

子元素

無。

父項目

Parent 項目 描述
關鍵字

包含描述專案的 system.object

 

範例

此範例顯示一個簡單的 appcontent-ms 檔案,其描述名為「範例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 Search 為任意元素的內容編制索引。 您只需使用 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-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。儲存體。搜索

需求

Namespace http://schemas.microsoft.com/Search/2013/ApplicationContent