Bagikan melalui


Skema konten aplikasi

Konten Aplikasi, atau appcontent-ms, skema untuk aplikasi Windows memungkinkan pengembang untuk meningkatkan pencarian dalam aplikasi dengan memberikan informasi tambahan tentang konten aplikasi Anda ke Indeks Pencarian Windows.

Cara kerjanya

Untuk meminta agar Windows mengindeks data aplikasi Anda untuk pencarian dalam aplikasi, buat folder bernama "Terindeks" di bawah LocalFolder dan simpan file yang ingin Anda indeks di sana. Windows mengindeks konten file dan metadata (properti) di folder "Terindeks" ini dan semua subfoldernya.

Untuk menggunakan skema appcontent-ms untuk mengindeks info tentang file atau item, buat file appcontent-ms dan tambahkan ke folder LocalFolder\Indexed aplikasi Anda (Anda perlu melakukan ini saat runtime, setelah aplikasi Anda diinstal). Saat aplikasi Anda menggunakan API Windows.Storage.Search untuk melakukan kueri di folder Terindeks, Pencarian akan menyertakan informasi dari file appcontent-ms Anda.

Info dalam file appcontent-ms hanya digunakan saat aplikasi yang berisinya menggunakan Windows.Storage.Search API untuk melakukan pencarian; info tidak akan muncul di Windows UI atau di aplikasi lain, misalnya.

Contoh ini menunjukkan file appcontent-ms sederhana yang menjelaskan item bernama "Sampel 1".

Perhatikan bahwa file berisi elemen yang tidak ditentukan oleh skema appcontent-ms: IndexerSampleInformation dan IndexerSampleSpecificElement. File appcontent-ms Anda harus memiliki simpul akar yang merangkum semua data yang akan diindeks, tetapi Anda dapat memberi nama simpul tersebut apa pun yang Anda inginkan.

<?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>

Anda bahkan dapat memberi tahu Windows Search untuk mengindeks konten elemen arbitrer. Cukup gunakan atribut IndexableContent untuk memberi tahu Search untuk mengindeks konten. Dalam contoh sebelumnya, Windows Search akan mengindeks konten IndexerSampleSpecificElement karena atribut IndexableContent diatur ke 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>

Pencarian akan memperlakukan konten sebagai konten teks secara default; jika kontennya adalah base64, gunakan atribut ContentType untuk menentukan jenis MIME.

Contoh berikutnya menunjukkan cara menyalin file appcontent-ms ke folder LocalFolder\Indexed aplikasi Anda. Kode menyalin file apa pun yang ditemukannya di folder appcontent-ms aplikasi ke folder LocalFolder\Indexed. (Anda juga dapat membuat file appcontent-ms baru langsung di folder Terindeks daripada menyalinnya dari lokasi lain.)

/// <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");
    });
}

Untuk kode lengkapnya, lihat sampel Pengindeks.

Referensi elemen

Tabel berikut ini mencantumkan semua elemen dalam skema ini, diurutkan menurut abjad berdasarkan nama.

Elemen Deskripsi
AdditionalProperties

Berisi properti tambahan yang menjelaskan item.

Komentar

Berisi System.Comment yang menjelaskan item.

Kata kunci

Salah satu System.Keywords yang menjelaskan item.

Kata kunci

Berisi System.Keywords yang menjelaskan item.

Nama

Menentukan System.ItemName \System.ItemNameDisplay item.

Properti

Berisi properti yang menjelaskan item ke Indeks Pencarian Windows.

Properti

Properti yang menjelaskan item.

Nilai

Nilai yang akan diindeks untuk properti .

 

Atribut untuk elemen khusus aplikasi

Gunakan atribut ini untuk mengindeks konten di elemen XML khusus aplikasi Anda sendiri.

Atribut Deskripsi

ContentType

Mengatur properti ini pada elemen menunjukkan bahwa konten elemen diperlakukan sebagai pengodean base64 dari jenis MIME/ jenis konten yang ditentukan dan diindeks menggunakan handler untuk jenis konten tersebut.

IndexableContent

Menunjukkan bahwa teks elemen harus diindeks untuk pencarian, tetapi tidak terkait dengan properti . Perhatikan bahwa properti dapat diambil nanti berdasarkan kunci properti, tetapi konten teks tidak bisa.

 

Sampel pengindeks

Windows.Storage.Search

Menambahkan pencarian (HTML)

Menambahkan pencarian (XAML)