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 檔案,其描述名為「範例1」的專案。
請注意,此檔案包含未由 appcontent-ms 架構定義的元素: IndexerSampleInformation
和 IndexerSampleSpecificElement
。 您的 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'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 [僅限桌面應用程式] |
另請參閱