應用程式內容結構描述

Windows apps 的應用程式內容(或 appcontent ms)架構可讓開發人員將應用程式內容的額外資訊提供給 Windows Search 索引,以增強應用程式內搜尋。

運作方式

若要要求 Windows 為應用程式資料編制應用程式內搜尋的索引,請在LocalFolder底下建立名為「已編制索引」的資料夾,並儲存您想要編制索引的檔案。 Windows 會在此 "Indexed" 資料夾及其所有子資料夾中,編制檔案內容和中繼資料 (屬性) 的索引。

若要使用 appcontent-ms 架構來編制檔案或專案的相關資訊,請建立 appcontent ms 檔案,並將它新增至您應用程式的 LocalFolder\Indexed 資料夾 (您需要在執行時間執行此動作時,請在應用程式安裝) 之後執行此動作。 當您的應用程式使用Windows 時儲存體。搜尋api,以在索引資料夾上執行查詢,搜尋會包含 appcontent-ms 檔案中的資訊。

只有當包含這些檔案的應用程式使用 Windows 時,才會使用 appcontent-ms 檔案中的資訊。儲存體。搜尋API 以執行搜尋;例如,資訊不會顯示在 Windows UI 或其他應用程式中。

此範例顯示一個簡單的 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");
    });
}

如需完整的程式碼,請參閱 索引子範例

項目參考

下表列出此架構中的所有元素,並依名稱的字母順序排序。

元素 描述
AdditionalProperties

包含描述專案的其他屬性。

註解

包含描述專案的 系統批註

關鍵字

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

關鍵字

包含描述專案的 system.object

名稱

\指定此專案的ItemNameDisplay

屬性

包含描述 Windows Search 索引之專案的屬性。

屬性

描述專案的屬性。

將為屬性編制索引的值。

 

應用程式專屬元素的屬性

使用這些屬性可在您自己的應用程式專屬 XML 專案中為內容編制索引。

屬性 描述

ContentType

在專案上設定此屬性,表示專案的內容會被視為指定之 MIME 類型/內容類型的 base64 編碼,而且會使用該內容類型的處理常式來編制索引。

IndexableContent

指出專案的文字應針對搜尋進行索引,但不會與屬性相關聯。 請注意,您稍後可以根據屬性索引鍵來抓取屬性,但是文字內容則不能。

 

索引子範例

Windows。儲存體。搜索

新增搜尋 (HTML)

新增搜尋 (XAML)