如何在 SharePoint Server 中建立新的結果類型How to create a new result type in SharePoint Server

摘要:了解如何在 SharePoint Server 中建立新的結果類型。Summary: Learn how to create a new result type in SharePoint Server.

在本文中,您將了解:In this article, you'll learn:

此系列中的搜尋中心範例的相關About the Search Center example in this series

若要協助說明我們可以在如何自訂顯示結果的外觀,我們會使用每日之間的內容發行者使用工具的範例: Microsoft 出版物內部清單。To help explain how we can customize the appearance of the displayed results, we'll use examples from a tool that is used daily among content publishers: an internal list of Microsoft publications.

當您知道 Microsoft 會跨 TechNet、 MSDN 和 Office.com 發佈千分位的文章。若要協助發佈程序中,我們使用多個 SharePoint 清單。在清單中的每個項目代表文章或媒體檔案。若要可輕鬆尋找特定清單項目的相關資訊,我們會建立可以搜尋整個這些清單的搜尋中心。As you know, Microsoft publishes thousands of articles across TechNet, MSDN, and Office.com. To help in the publishing process, we use several SharePoint lists. Each item in a list represents an article or a media file. To make it easy to find information about a particular list item, we created a Search Center that searches across these lists.

在 [搜尋中心我們第一版已同名顯示所有搜尋結果。這是因為根據預設,所有的清單項目屬於相同的 SharePoint 清單項目結果類型。我們想要變更此設定,讓只是由窺搜尋結果,我們可以區分發佈 technet 文章和發佈 MSDN 上的文章。我們也想要新增就是不必選取並開啟它可以看到每個搜尋結果的重要資訊。In our first version of the Search Center, all the search results were displayed identically. This was because by default, all list items belonged to the same SharePoint List Item result type. We wanted to change this so that just by glancing at the search results, we could differentiate between an article published on TechNet and an article published on MSDN. We also wanted to add important information about each search result that would be visible without having to select and open it.

我們進行了 SharePoint Server 中的任何項目之前,我們坐向下個規劃工作階段。第一個任務就是決定我們想要將搜尋結果的方式。我們隨附下列類別:Before we did anything in SharePoint Server, we sat down for a planning session. The first task was to decide how we wanted to categorize our search results. We came up with the following categories:

類別Category 定義Definition
TechNet 的內容TechNet content
發佈 TechNet 平台的文章Articles that are published on the TechNet platform
MSDN 內容MSDN content
MSDN 平台發佈的文章Articles that are published on the MSDN platform
Office.com 的內容Office.com content
發佈 Office.com 平台的文章Articles that are published on the Office.com platform
圖像內容Images content
出版物中所用的圖像Images that are used in publications
視訊內容Video content
出版物中所用的影片Videos that are used in publications
下載內容Download content
可下載內容Downloadable content

我們已定義的類別之後,我們需要知道另一個類別。在我們的清單中的項目包含名為通訊通道的網站欄。此網站欄包含平台的文章的發佈,例如TechNet 文件庫的值。After we had defined the categories, we needed to distinguish the categories from one another. Items in our list contain a site column named Distribution Channel . This site column contains the value of the platform to which an article is published, for example TechNet Library .

項目通路

我們決定我們會使用通訊通道網站欄的值從另一個區別類別。We decided that we would use values from the Distribution Channel site column to distinguish the categories from one another.

與手持這些決策,我們設定來建立新的結果類型的每個類別。建立新的結果類型的程序是所有類別的相同。如此,以節省空間,我們將僅查看建立TechNet 內容結果類型的方式。With these decisions in hand, we set out to create new result types for each category. The procedure for creating a new result type is identical for all categories. So, to save space, we'll only look at how TechNet content result type was created.

如何將複製的預設項目顯示範本How to copy a default item display template

在建立新的結果類型之前,您應建立新的結果類型將會使用新項目顯示範本。若要避免必須從頭開始建立新的項目顯示範本,您可以複製現有的欄位。嘗試將複製為盡可能接近至您的內容類型的項目顯示範本。以下是您應該執行的動作:Before you create a new result type, you should create a new item display template that your new result type will use. To avoid having to create a new item display template from scratch, you can copy an existing one. Try to copy an item display template that is as close as possible to the type of content that you have. Here's what you should do:

  1. 複製到預設項目顯示範本。Copy a default item display template.

    在我們的案例中,我們想要自訂搜尋結果的 SharePoint 清單項目。從參照表格中關於結果類型我們可以決定SharePoint 清單項目結果類型所使用的預設項目顯示範本是名為Item_Default的檔案。因為我們已經如何對應網路磁碟機,我們可以輕易地Item_Default檔案複製 Windows 檔案總管中。In our scenario, we wanted to customize search results for SharePoint list items. From the reference table in About result types we can determined that the default item display template that is used by the SharePoint List Item result type is the file that is named Item_Default . Because we have already How to map your network drive, we could easily copy the Item_Default file in Windows Explorer.

    複製項目預設

    透過重新整理 Windows 檔案總管中,我們看到 SharePoint Server 自動鎖建立關聯的 JavaScript 檔案。By refreshing Windows Explorer, we saw that SharePoint Server had automatically created an associated JavaScript file.

    Java 指令碼項目預設版本

  2. 重新命名新建立項目顯示範本。Rename your newly created item display template.

    在我們的案例中,我們已重新命名該TechNet 內容。同樣地,我們重新整理 Windows 檔案總管確認 JavaScript 檔案已隨之更新。In our scenario, we renamed it TechNet content . Again, we refreshed Windows Explorer to verify that the JavaScript file was updated accordingly.

    TechNet 內容檔案

  3. 開啟新的顯示範本,並變更<標題>標籤。請記住,在此標籤中的文字是執行 SharePoint Server 使用者介面中的組態時將會顯示。Open the new display template and change the <title> tag. Remember, the text in this tag is what will be shown when you do configurations in the SharePoint Server UI.

    在我們的案例中,我們已變更 <em>TechNet</em>內容的標籤。In our scenario, we changed the tag to <em>TechNet content</em> .

    TechNet 標題標記

  4. 儲存新的項目顯示範本。Save the new item display template.

    現在我們已建立新的項目顯示範本,我們可以開始建立新的結果類型。Now that we have created a new item display template, we could move on to creating a new result type.

如何建立結果類型How to create a result type

根據您的權限層級,您可以建立結果類型在兩個層級:Depending on your permission level, you create a result type on two levels:

權限等級Permission level 要新增結果類型Where the result type will be added
網站集合管理員Site collection administrator
若要在網站集合中的所有網站To all sites in a site collection
網站集合擁有者Site collection owner
在單一站台To a single site

若要儲存空間,我們將僅查看如何建立結果類型為網站集合管理員。To save space, we'll only look at how to create a result type as a Site collection administrator.

  1. 移至 [網站設定 --> 搜尋結果類型Go to Site settings --> Search Result Types.

    搜尋結果類型

    而不是從零開始建立新的結果類型,我們可以藉由複製現有的結果類型並變更其符合我們新的結果類型的位元更輕鬆地生命週期。如果我們執行這項作業時,我們必須複製非常類似我們想要建立新的結果類型的結果類型。Instead of creating a new result type from scratch, we can make life a bit easier by copying an existing result type and changing it to fit our new result type. If we do this, we must be sure to copy a result type that closely resembles the new result type we want to create.

  2. 在 [管理結果類型] 頁面上從結果類型] 功能表] 欄位中,選取 [複製On the Manage Result Types page, from the result type menu field, select Copy.

    在我們的案例中,我們想要自訂搜尋結果的 SharePoint 清單項目。因此,我們會複製SharePoint 清單項目結果類型。In our scenario, we wanted to customize search results for SharePoint list items. Therefore, we copied the SharePoint List Item result type.

    複製 SharePoint 清單項目

  3. 在 [新增結果類型] 頁面上,以下是要遵循的步驟:On the Add Result Type page, here are the steps to follow:

    • 在 [指定其名稱] 欄位中輸入新的結果類型的名稱。In the Give it a name field, enter a name for the new result type.

      在我們的案例中,我們輸入TechNet 內容In our scenario, we entered TechNet content .

    • 哪個來源結果應該符合] 功能表選取 [我們已使用我們搜尋結果網頁組件中設定的查詢的結果來源。From the Which source should results match menu, select the result source that we have used to configure the query in our Search Result Web Part.

    • 在 [內容類型應符合?您可以略過此規則來比對所有內容] 功能表中,所有列出預設結果類型。In the What types of content should match? You can skip this rule to match all content menu, all the default result type are listed.

      在我們的案例中,我們會選擇選取一個值In our scenario, we chose Select a value.

    • 按一下 [顯示更多條件]。Click Show more conditions.

      顯示更多條件

      如此會開啟我們可以在其中指定 managed 的屬性的值為基礎的結果類型] 功能表。This opens a menu where we can specify the result type based on managed property values.

      在我們的案例中,所有的清單項目包含稱為通訊通道的網站欄。當我們正開頭,這個網站欄會包含出版物平台值,例如TechNet 文件庫。我們使用此網站欄的值來指定我們新的結果類型應隸屬之清單項目。In our scenario, all list items contain a site column called Distribution Channel . As we saw at the beginning, this site column contains the publication platform value, for example TechNet Library . We used values from this site column to specify which list items should belong to our new result type.

    • 從 [應該符合的自訂屬性] 功能表選取 [ DistributionChannelOWSCHCSDistributionChannelOWSCHCS是代表通訊通道網站欄的 managed 的屬性。在下列欄位中我們輸入應該指定新的TechNet 內容結果類型的所有值。From the Which custom properties should match menu, we selected DistributionChannelOWSCHCS . DistributionChannelOWSCHCS is the managed property that represents the Distribution Channel site column. In the fields below, we entered all the values that should specify the new TechNet content result type.

      新增屬性

    • 從 [應該這些結果看起來是什麼] 功能表選取 [應使用此結果類型的顯示範本。From the What should these results look like menu, select the display template that should be used by this result type.

      在我們的案例中,選取 [新建TechNet 內容顯示範本。In our scenario, we selected the newly-created TechNet content display template.

      套用 TechNet 顯示範本

    • 按一下 [儲存]。Click Save.

      新建立結果類型現在會列在 [受管理的結果類型] 頁面上。The newly-created result type is now listed on the Managed Result Types page.

      在我們的案例中,我們可以看到已建立TechNet 內容結果類型。In our scenario, we could see that the TechNet content result type was created.

      已建立 TechNet

      所以現在,我們有新的結果類型下, 一個工作會變更此結果類型相關聯的顯示範本。有一個以上的方式執行這項作業。因此這一系列的下一步] 兩篇文章,我們將說明兩個不同的選項。So now that we have a new result type, the next task is to change the display template that is associated with this result type. There is more than one way to do this. Therefore in the next two articles of this series, we'll explain two different options.

本系列中的下一篇文章Next article in this series

如何顯示自訂受管理屬性的值在搜尋結果-選項 1 in SharePoint ServerHow to display values from custom managed properties in search results - option 1 in SharePoint Server