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

摘要:了解在 SharePoint Server 中顯示自訂受管理屬性的值的一個選項。Summary: Learn one option for displaying values from custom managed properties in SharePoint Server.

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

如何在顯示的自訂圖示How to display a custom icon

了解如何在 SharePoint Server 中顯示搜尋結果中我們清楚 Word、 PDF 及 Excel 圖示的每個搜尋結果的顯示方式。在搜尋中心案例中,我們想要新增屬於新建的TechNet 內容結果類型的所有搜尋結果] 旁的下列自訂圖示:In Understanding how search results are displayed in SharePoint Server we explained how the icons Word, PDF, and Excel are displayed for each search result. In our Search Center scenario, we wanted to add the following custom icon next to all search results that belong to the newly created TechNet content result type:

TNTN

若要顯示搜尋結果,以下的自訂圖示應該怎麼做:To display a custom icon for search results, here's what you should do:

  1. 將自訂圖示加入至 SharePoint Server 文件庫。Add the custom icon to a SharePoint Server library.

    在搜尋中心案例中,我們加入自訂圖示的影像文件庫。In our Search Center scenario, we added the custom icon to the Images library.

    已新增圖示

  2. 開啟已從您要顯示的自訂圖示的結果類型參照的項目顯示範本。Open the item display template that is referenced from the result type for which you want to display a custom icon.

    在搜尋中心案例中,我們也移除了 if 陳述式:如果 (ctx。CurrentItem.IsContainer)In our Search Center scenario, we also removed the if statement: if (ctx.CurrentItem.IsContainer) .

    顯示範本自訂圖示

  3. 在 [搜尋] 頁面上輸入的查詢,將會觸發新的結果類型。On a search page, enter a query that will trigger the new result type.

  4. 我們可以在搜尋中心案例中,輸入 「 結果類型 」。現在是 TechNet 出版物的搜尋結果有旁邊的自訂圖示。更好 !In our Search Center scenario, we entered "result type." Search results that are TechNet publications now have a custom icon next to them. Great!

    已顯示圖示

讓我們搜尋中心的使用者無法立即輕鬆地區分 TechNet 發佈的搜尋結果。但是,我們也想要新增自訂網站欄中的資訊,讓使用者無法查看每個搜尋結果的重要資訊不必按一下它。So users of our Search Center could now easily distinguish the search results that were published on TechNet. But, we also wanted to add information from custom site columns so that users could see important information about each search result without having to click it.

了解如何在 SharePoint Server 中顯示搜尋結果中我們清楚的網站欄"轉換"managed 屬性在編目期間。我們同時說明可以在搜尋結果中顯示的項目顯示範本中所列僅受管理的屬性。因此,若要在搜尋結果中顯示自訂的資訊,您必須新增 managed 的屬性的項目顯示範本。所以,應該執行接下來是尋找您想要使用的自訂網站資料行對應的 managed 的屬性名稱。In Understanding how search results are displayed in SharePoint Server we explained that site columns are "transformed" into managed properties during crawl. We also explained that only managed properties that are listed in an item display template can be displayed in search results. So, to display custom information in your search results, you must have to add managed properties to an item display template. Hence, the next thing that you should do is find the managed property name that corresponds to the custom site column that you want to use.

如何尋找 managed 的屬性名稱How to find a managed property name

在開始搜尋的 managed 的屬性名稱之前,很重要則您位元了解受管理屬性的命名慣例。如需此的詳細資訊,請參閱關於自動建立編目屬性與 managed 屬性的命名慣例Before you start to search for a managed property name, it's important that you know a bit about the naming convention for managed properties. For more information about this, see About the naming convention for automatically created crawled and managed properties.

根據您的權限層級,您可以搜尋的三個地方的 managed 屬性:Depending on your permission level, you can search for managed properties from three places:

權限等級Permission level 從下列位置搜尋Search from this location
Search Service 應用程式管理員Search service application administrator
管理中心->受管理的服務應用程式-> Search Service 應用程式->搜尋結構描述Central Administration --> Managed Service Application --> Search Service Application --> Search Schema
網站集合管理員Site collection administrator
網站設定-> (在 [網站集合管理] 區段中) 的搜尋結構描述Site Settings --> Search Schema (in the Site Collection Administration section)
網站集合擁有者Site collection owner
網站設定-> (在 [搜尋] 區段中) 的結構描述Site Settings --> Schema (in the Search section)

以下是您應該處理的作業:Here's what you should do:

  1. 移至 [網站設定 --> 搜尋結構描述Go to Site settings --> Search Schema.

    Search Schema

  2. 在 [ Managed 屬性] 頁面上的Managed 屬性欄位中,輸入您想要尋找的 managed 的屬性名稱的網站欄名稱。請記得 managed 的屬性名稱不含空格。因此,如果您的網站欄名稱包含空格,省略它。On the Managed Properties page, in the Managed property field, type the name of the site column that you want to find the managed property name of. Remember that managed property names don't contain spaces. Therefore, if your site column name contains a space, leave it out.

    在搜尋中心案例中,我們要尋找的網站欄內容摘要的 managed 的屬性名稱。我們在 [ Managed 屬性] 欄位中輸入ContentSummary並按下綠色箭頭圖示。In our Search Center scenario, we wanted to find the managed property name for the site column Content Summary . We entered ContentSummary in the Managed property field, and clicked the green arrow icon.

    搜尋內容摘要

    傳回一個搜尋結果: ContentSummaryOWSMTXTOne search result was returned: ContentSummaryOWSMTXT .

    內容摘要

    因為內容摘要網站欄類型多行文字的所以我們知道這是我們想要使用的 managed 的屬性名稱。Because the Content Summary site column is of type Multiple lines of text , we knew this was the managed property name we wanted to use.

  3. 重複此程序來尋找您想要在搜尋結果中顯示的 managed 屬性的所有名稱的步驟。Repeat the steps of this procedure to find the names of all of the managed properties that you want to display in your search results.

現在您已經找到您想要在搜尋結果中顯示的 managed 屬性的名稱下, 一步就是變更的項目顯示範本。Now that you have found the names of the managed properties that you want to show in your search results, the next step is to change the item display template.

若要變更要顯示的自訂值的項目顯示範本的 managed 屬性集的方式的選項 1How to change an item display template to show values from custom managed properties - option 1

了解 SharePoint Server 中搜尋結果的顯示方式我們提及有幾種方法來變更項目顯示範本,以顯示自訂受管理屬性的值。本節所述的選項是很簡單。我們將會涵蓋這一系列的下一份文件中的第二個選項。它不包含任何如果未套用陳述式,以及結果醒目提示。In Understanding how search results are displayed in SharePoint Server we mentioned that there are several ways to change an item display template to show values from custom managed properties. The option explained in this section is very simple. We'll cover the second option in the next article of this series. It doesn't include any if statements, and hit highlighting is not applied.

以下是您應該處理的作業:Here's what you should do:

  1. 開啟您要自訂搜尋結果的結果類型所屬的項目顯示範本。Open the item display template that belongs to the result type for which you want to customize search results.

    在搜尋中心案例中,這是TechNet 內容In our Search Center scenario, this was TechNet content .

  2. 在項目ManagedPropertyMapping標籤中顯示範本,新增您想要顯示自訂受管理的屬性使用下列語法:In the item display template, in the ManagedPropertyMapping tag, use the following syntax to add the custom managed properties that you want to display:

    '<Current item property name>':<Managed property name>'
    

    在搜尋中心案例中,我們要從ContentSummaryOWSMTXTowstaxIdTechnicalSubject managed 屬性的值顯示在搜尋結果中。若要讓檔案更容易維護,我們名為目前的項目屬性的 managed 屬性相同。In our Search Center scenario, we wanted the values from the managed properties ContentSummaryOWSMTXT and owstaxIdTechnicalSubject to be displayed in the search result. To make the file easier to maintain, we named the current item properties the same as the managed properties.

    新增 MP

  3. 內的第二個<div>標記中<本文>,若要新增程式碼會顯示自訂受管理屬性的值,請使用下列語法:Inside the second <div> tag in the <body>, use the following syntax to add code that will display the value of the custom managed property:

    _#= ctx.CurrentItem.<Current item property name> =#
    

    在搜尋中心案例中,我們新增下列項目顯示範本:In our Search Center scenario, we added the following to the item display template:

    <div>_#= ctx.CurrentItem. ContentSummaryOWSMTXT =#_</div>
    <div>_#= ctx.CurrentItem. owstaxIdTechnicalSubject =#></div>
    

    顯示兩個新的 MP

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

    注意

    您不需要執行此步驟如果您使用 SharePoint Online。移至 [網站設定 --> 搜尋結果類型。請注意屬性同步處理通知會顯示。You don't have to do this step if you are using SharePoint Online. Go to Site settings --> Search Result Types. Notice that a Property Sync alert is displayed.

    屬性同步處理警示

    顯示此警示是因為我們 (什麼我們並未在步驟 2) 項目顯示範本新增 managed 的屬性。若要以新加入的 managed 屬性更新結果類型,按一下 [更新]。This alert is displayed because we added managed properties to an item display template (what we did in step 2). To update the result types with the newly added managed properties, click Update.

    已更新 MP

    重要

    如果您不執行此更新,新加入的 managed 的屬性將不會顯示在搜尋結果中。If you don't do this update, the newly added managed properties won't display in your search results.

    我們在使用者適用的搜尋中心] 中輸入查詢時進行這項變更後,請ContentSummaryOWSMTXT值和owstaxIdTechnicalSubject的值被顯示在搜尋結果。After we made this change, when users entered a query in our Search Center, both the value of ContentSummaryOWSMTXT and the value for owstaxIdTechnicalSubject were displayed in the search results.

    搜尋結果清單項目

    即使兩個自訂屬性現在已顯示搜尋結果中,結果未完全右邊。例如,我們想要顯示的兩個自訂屬性之間的標題和連結或不低於連結幾點目前大小寫。Even though two custom properties were now displayed in the search results, the result wasn't completely right. For example, we wanted to display the two custom properties between the title and the link, and not below the link as was currently the case.

若要更容易理解為何搜尋結果所顯示的交易的方式,我們看接近自訂項目顯示範本:To better understand why the search results were displayed the way that they were, let's take a closer look at the customized item display template:

顯示範本流程

  1. ctx.CurrentItem.csr_Icon指向 「 我的自訂圖示的位置。此變數會使用Item_CommonItem_Body顯示範本。ctx.CurrentItem.csr_Icon points to the location of my custom icon. This variable is used by the Item_CommonItem_Body display template.

  2. _#=ctx.RenderBody(ctx)=#_呼叫Item_CommonItem_Body顯示範本。(請記住了解如何項目顯示範本及瀏覽 SharePoint Server 中的醒目提示工時Item_CommonItem_Body顯示範本會顯示 [自訂] 圖示、 標題和連結項目。)_#=ctx.RenderBody(ctx)=#_ calls the Item_CommonItem_Body display template. (Remember Understanding how item display templates and hit highlighting work in SharePoint Server. The Item_CommonItem_Body display template displays the custom icon, title, and the link to the item.)

  3. _#= ctx.CurrentItem.ContentSummaryOWSMTXT =#__#= ctx.CurrentItem.owstaxIdTechnicalSubject =#_顯示兩個受管理的內容、 ContentSummaryOWSMTXT以及owstaxIdTechnicalSubject的值。_#= ctx.CurrentItem.ContentSummaryOWSMTXT =#_ and _#= ctx.CurrentItem.owstaxIdTechnicalSubject =#_ display the values of the two managed properties, ContentSummaryOWSMTXT and owstaxIdTechnicalSubject .

若要顯示標題和連結之間的自訂屬性,您可能需要不在播放Item_CommonItem_Body顯示範本刪除參考 (英文) 以_#=ctx.RenderBody(ctx)=#_從自訂顯示範本。您接著可以增加屬性要加以顯示,例如,如下所示的順序排列:To display the custom properties between the title and the link, you could take the Item_CommonItem_Body display template out of play by deleting the reference _#=ctx.RenderBody(ctx)=#_ from your custom display template. You could then add the properties in the order that you want them to display, for example as follows:

移除參考

搜尋結果會再看起來如下:The search result would then look like this:

沒有一般參考的結果

使用更多在樣式上,您可能有足夠良好的結果。但刪除參考_#=ctx.RenderBody(ctx)=#_Item_CommonItem_Body顯示範本不再用來顯示結果。Item_CommonItem_Body顯示範本包含自動將可改善搜尋結果的相關性某些功能。因此,在刪除之前_#=ctx.RenderBody(ctx)=#_參考 (英文),您應該考慮是否自動改進的相關性為搜尋網站的使用者會受益的某個項目。By working a bit more on the styling, you could have a good enough result. But, by deleting the reference to _#=ctx.RenderBody(ctx)=#_ ,the Item_CommonItem_Body display template is no longer used to display results. The Item_CommonItem_Body display template contains some functionality that will automatically improve the relevancy of your search results. So, before you delete the _#=ctx.RenderBody(ctx)=#_ reference, you should consider whether automatically improved relevancy is something that the users of your search site would benefit from.

關於即追蹤並自動改進的相關性About click tracking and automatically improved relevancy

Item_CommonItem_Body顯示範本包含追蹤使用者按一下行為onlick方法。此追蹤這會影響搜尋結果的相關性。例如,通常會按下使用者所擁有的搜尋結果將會自動顯示更向上搜尋結果中。The Item_CommonItem_Body display template contains an onlick method that tracks the click behavior of users. This tracking influences the relevancy of search results. For example, a search result that is often clicked by users will automatically be displayed higher up in the search results.

重要

如果您想要接收自動改進的相關性根據使用者按一下行為在搜尋結果時,請勿刪除參考_#=ctx.RenderBody(ctx)=#_從項目顯示範本。If you want your search results to receive automatically improved relevancy based on the click behavior of users, do not delete the reference to _#=ctx.RenderBody(ctx)=#_from the item display template.

下一篇文章 < 中我們將說明如何保留此參考資料、 搜尋結果中顯示的標題和連結之間的自訂屬性及也適用於您的自訂屬性的結果醒目提示。In the next article, we'll explain how you can keep this reference, display custom properties between the title and link in the search results, and also apply hit highlighting to your custom properties.

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

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