了解如何項目顯示範本和醒目提示在 SharePoint Server 中運作Understanding how item display templates and hit highlighting work in SharePoint Server

摘要:了解如何項目顯示範本並醒目提示 SharePoint Server 2016 和 SharePoint Server 2013 中的工作。Summary: Learn how item display templates and hit highlighting work in SharePoint Server 2016 and SharePoint Server 2013.

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

如何將對應網路磁碟機How to map your network drive

使用時顯示範本,您將生命更加容易讓您進行如果您將網路磁碟機對應。執行此動作,您將能夠使用 [Windows 檔案總管的顯示範本。指示,請參閱如何對應網路磁碟機When working with display templates, you'll make life a lot easier for yourself if you map your network drive. By doing this, you'll be able to work with display templates from Windows Explorer. For instructions, see How to map your network drive.

為什麼要選擇務必了解 managed 的屬性名稱Why it's important to know about managed property names

搜尋幾個字組中的運作方式] 區段中的這一系列的簡介主題說明如何網站欄及網站欄值"轉換"managed 屬性與 managed 屬性的值在編目期間。請務必了解找不到名稱的 managed 屬性代表站台] 欄中,因為將新的資訊新增至搜尋結果,您必須將 managed 的屬性名稱新增至項目顯示範本。如果您不確定如何名為 managed 的屬性,請參閱 <從 managed 屬性集的網站欄功能的?The How search works in a few words section of the introductory topic in this series explained how site columns and site column values are "transformed" into managed properties and managed property values during a crawl. It is important that you learn to find the name of the managed property that represents a site column, because to add new information to your search results, you'll have to add the managed property name to an item display template. If you are uncertain how managed properties are named, see From site column to managed property - What's up with that?.

混淆吗?不要失望。我們將為您示範如何尋找並新增 managed 的屬性名稱項目至步驟稍後這一系列的顯示範本。Confusing? Well, don't despair. We'll show you the steps of how to find and add a managed property name to an item display template later in this series.

關於項目中的重要項目顯示範本About important elements in the item display template

了解 SharePoint Server 中搜尋結果的顯示方式的文章說明 SharePoint Server 包含許多項目顯示範本。雖然這些顯示範本不是相同的 100%,因此皆包含控制搜尋結果的顯示方式某些項目。The article Understanding how search results are displayed in SharePoint Server explained that SharePoint Server includes many item display templates. Although these display templates are not 100% identical, they all contain certain elements that control how search results are displayed.

我們加入並開啟項目顯示範本,例如: Item_ExcelLet's dive in and open an item display template, for example: Item_Excel.

注意

因為我們對應至網路磁碟機,我們可以在我們最愛的 HTML 編輯器,例如[記事本] + +中開啟檔案。Because we have mapped a network drive, we can open the file in our favorite HTML editor, for example, Notepad++.

開啟項目顯示範本

關於<標題>標記About the <title> tag

顯示範本的頂端有<標題>標籤。在此標籤中的文字是執行動作時 SharePoint 使用者介面中的設定,當您設定的結果類型時將會顯示。The top of the display template has a <title> tag. The text in this tag is what will be shown when you do configurations in the SharePoint UI, for example, when you configure a result type.

下列螢幕擷取畫面顯示如何從文字<標題>中的項目顯示範本Excel 項目標籤會顯示在Microsoft Excel結果類型的設定。The following screen shot shows how the text from the <title> tag in the item display template, Excel Item, is shown in the configuration of the Microsoft Excel result type.

Excel 項目標題

關於 ManagedPropertyMapping 元素About the ManagedPropertyMapping element

之後<標題>標記、 有一組中的元素<mso:CustomDocumentProperties>標記,最重要的是<mso:ManagedPropertyMapping>After the <title> tag, there's a set of elements in a <mso:CustomDocumentProperties> tag, the most important of which is <mso:ManagedPropertyMapping>.

ManagedPropertyMapping元素包含可用來顯示搜尋結果的 managed 的屬性。下列的語法用來儲存這些屬性中的項目顯示範本:The ManagedPropertyMapping element contains the managed properties that can be used to display the search results. The following syntax is used to store these properties in the item display template:

'<Display template reference name>':<Managed property name>'

下列螢幕擷取畫面顯示Excel 項目顯示範本的預設ManagedPropertyMapping元素。The following screen shot shows the default ManagedPropertyMapping element for the Excel Item display template.

Managed 屬性對應

請注意顯示範本參考 (英文) 名稱會與相同的受管理的屬性名稱,例如'Title':'Title' or 'FileType':'FileType'。即使這可能會看起來元混淆第一次、 具有相同名稱會容易維護檔案。Notice that the display template reference name is the same as the managed property name, for example 'Title':'Title' or 'FileType':'FileType'. Even though this might seem a bit confusing at first, having identical names will make it easier to maintain the file.

根據預設,此項目中包含的 managed 的屬性有些許的不同項目顯示範本。但是,有兩個 managed 的屬性所包含的所有的顯示範本: HitHighlightedPropertiesHitHilightedSummary 。我們將探索本主題的 「 如何點擊醒目提示的運作-是魔法 ! 」 區段中的這兩個屬性。By default, the managed properties that are included in this element vary slightly for the different item display templates. But, there are two managed properties that are included in all display templates: HitHighlightedProperties and HitHilightedSummary . We'll explore these two properties in the "How hit highlighting works - it is magic!" section of this topic.

關於<本文>標記About the <body> tag

內部<本文>標記、 有<div>標籤與識別碼。根據預設,此識別碼<div>標籤找出檔案的名稱。在我們的案例,這是Item_ExcelInside the <body> tag, there is a <div> tag with an ID. By default, the ID for this <div> tag matches the name of the file. In our case, this is Item_Excel.

Div ID

任何 HTML 或顯示範本應使用來顯示搜尋結果的程式碼隨附內這<div>標籤。Any HTML or code that the display template should use to display search results is included inside this <div> tag.

在這個<div>標籤有一或多個組塊的開頭<!-#_且結尾為_ #->。JavaScript 程式碼區塊之外使用這些區塊和 HTML 內。您也可以使用這些區塊來控制使用設定格式化的條件陳述式的 HTML。我們將為您示範如何可以此更新的文章。In this <div> tag there are one or more blocks that begin with <!--#_ and end with _#-->. JavaScript code is used inside these blocks, and HTML outside the blocks. You can also use these blocks to control the HTML with conditional statements. We'll show you how you can do this in a later article.

關於動態顯示面板顯示範本變數About the hover panel display template variable

我們已使用此區塊內的一個變數,請考慮: var hoverUrl了解 SharePoint Server 中搜尋結果的顯示方式,在我們討論每個項目顯示範本如何包含動態顯示面板顯示範本的參照。變數var hoverUrl包含此參考 (英文)。We have to consider one variable that's used inside this block: var hoverUrl. In Understanding how search results are displayed in SharePoint Server, we covered how each item display template contains a reference to a hover panel display template. The variable var hoverUrl contains this reference.

下列螢幕擷取畫面顯示如何var hoverUrl點到Item_Excel_HoverPanel動態顯示面板顯示範本。The following screen shot shows how var hoverUrl points to the Item_Excel_HoverPanel hover panel display template.

var 動態顯示 URL

關於搜尋結果中顯示的圖示About the icon that shows in search results

我也要提及值ctx。CurrentItem.csr_Icon。此值會指向應該顯示每個搜尋結果,例如 Excel 圖示旁的圖示。I also want to mention the value ctx.CurrentItem.csr_Icon. This value points to the icon that should be displayed next to each search result, for example the Excel icon.

下列螢幕擷取畫面顯示如何值ctx。CurrentItem.csr_Icon指向圖示。The following screen shot shows how the value ctx.CurrentItem.csr_Icon points to an icon.

圖示值

稍後的這一系列中,我們將看看如何變更這個值,使其指向自訂的圖示。Later in this series, we'll look at how you can change this value so that it points to a custom icon.

關於常用項目參考顯示範本About the reference to the common item display template

尾端<div>、 非常重要一行程式碼是包含: #= ctx。RenderBody(ctx) = #。在了解 SharePoint Server 中搜尋結果的顯示方式,我們已經討論過如何在這是所有結果類型所使用的項目顯示範本參照。Toward the end of the <div>, a very important line of code is included: #=ctx.RenderBody(ctx)=#. In Understanding how search results are displayed in SharePoint Server, we looked at how this is a reference to the item display template that's used by all result types.

下列螢幕擷取畫面顯示如何#= ctx。RenderBody(ctx) = #會用於Item_Excel顯示範本。The following screen shot shows how #=ctx.RenderBody(ctx)=# is used in the Item_Excel display template.

一般項目參考

關於結果醒目提示About hit highlighting

即使您永不聽到的醒目提示之前,您所見功能的巨集指令,即使您可能不具備授與它更加思考。Even if you have never heard of hit highlighting before, you've seen the feature in action, even though you might not have given it much thought.

點擊醒目提示功能會在使用者只有在搜尋方塊中輸入並將它們中顯示的字粗體搜尋結果中。如此一來,使用者可以輕鬆掃描查看找到其查詢文字的內容的搜尋結果。例如,下列螢幕擷取畫面顯示的搜尋方塊中輸入 「 結果類型 」。在搜尋結果、"結果 」 和 「 類型 」 會以粗體顯示。The hit highlighting feature takes the words a user has entered in a search box and displays them in bold in the search results. That way, users can easily scan search results to see the context in which their query words are found. For example, the following screen shot shows that "result type" was entered in the search box. In the search results, "result" and "type" are displayed in bold.

命中項目醒目提示

如何瀏覽醒目提示的運作-是魔法 !How hit highlighting works - it is magic!

根據預設,針對特定的 managed 屬性啟用結果醒目提示。若要查看這些 managed 的屬性,在搜尋結果] 頁面上,編輯 [搜尋結果網頁組件]。在 [網頁組件工具窗格中展開 [顯示範本] 區段中。Hit highlight 屬性 (JSON)區段列出已啟用結果醒目提示的屬性。By default, hit highlighting is enabled for certain managed properties. To see these managed properties, on a search results page, edit the Search Results Web Part. In the Web Part Tool Pane expand the Display Templates section. The properties that are enabled for hit highlighting are listed in the Hit-highlighted properties (JSON) section.

命中項目醒目提示屬性網頁組件

有一點超過給它,但現在是重要您知道列示這些 managed 的屬性。There is a bit more to it than that, but for now it's important that you know where these managed properties are listed.

讓我們回到我們 」 結果類型 」 的搜尋及仔細接近第一個搜尋結果,其中。因為標題專案/檔案名稱] 欄中的值包含單字傳回我們尋找。Let's go back to our "result type" search and take a closer look at the first search result, which. was returned because the values in the Title and Project/File Name columns contained the words we were looking for.

搜尋結果中的項目

如已先前"需 ManagedPropertyMapping 元素 」 一節所述本主題的、 ManagedPropertyMapping元素中的項目顯示範本包含可用來顯示搜尋結果的 managed 的屬性。您可以在此基礎瞭解為何會顯示 [關於設定結果類型」。因為 [關於設定結果類型 」 的標題的清單項目中的值,且標題為其中一個 managed 屬性中的顯示範本的 ManagedPropertyMapping 元素中找到。粗體 (點擊醒目提示) 中顯示 「 結果類型 」 的字詞標題由於其中點擊醒目提示搜尋結果網頁組件中所列。As was previously explained in the "About the ManagedPropertyMapping element" section of this topic, the ManagedPropertyMapping element in the item display template contains the managed properties that can be used to display search results. Based on this, you can understand why "About configuring result types " is displayed. It is because "About configuring result types" is the value of Title in the list item, and Title is one of the managed properties found in the ManagedPropertyMapping element in the display template. The words "result type" are displayed in bold (hit highlighted) because Title is one of the hit highlighted listed in the Search Results Web Part.

但為什麼不完整"CSH_Configure_ result_types... "會顯示在搜尋結果吗?在清單項目我們可以看到這是專案/檔案名稱的值但ManagedPropertyMapping中的項目顯示範本中不包含該網站欄的 managed 的屬性。兩者都不是其列為其中一個瀏覽醒目提示搜尋結果網頁組件屬性。所以為何此值顯示?But why is "CSH_Configure_ result_types… "displayed in the search results? In the list item we can see that this is the value for Project/File Name, but the managed property for that site column is not included in the ManagedPropertyMapping element in display template. Neither is it listed as one of the hit highlighted properties in the Search Results Web Part. So why is this value displayed?

關於"魔法 summary"屬性About the "magical summary" property

若您猜測結果醒目提示,您可以正確。您正Hit highlight 屬性 (JSON)區段中的搜尋結果網頁組件的預設屬性,除了有屬性會包含每個項目的摘要。這是幾乎像魔法屬性,因為它儲存在搜尋索引中的每個項目的摘要。此摘要會建立深入 SharePoint 解析,所以您不必擔心的。重要的是,我搜尋的 「 結果類型 」 時,標題與此"魔法 summary"屬性中找到相符項目。If you guessed hit highlighting, you are correct. In addition to the default properties that you saw in the Hit-highlighted properties (JSON) section of the Search Results Web Part, there is a property that contains a summary for each item. This is almost like a magical property, because it stores a summary of each item in the search index. This summary is created under the SharePoint hood, so you don't have to worry about that. What's important is that when I searched for "result type," a match was found in both the Title and this "magical summary" property.

如果您現在想: hang !我了解顯示標題的值是因為標題為其中一個 managed 屬性中找到的ManagedPropertyMapping項目顯示範本。但我沒有看到的顯示範本的ManagedPropertyMapping元素中任何"魔法 summary"屬性。那要如何可以顯示值?If you are now thinking, hang on! I understand that the value for Title is displayed because Title is one of the managed properties found in the in the ManagedPropertyMapping element display template. But I don't see any "magical summary" property in the ManagedPropertyMapping element of the display template. So how can the value be displayed?

知名其中HitHighlightedPropertiesHitHilightedSummary兩個屬性是很有用。下圖不代表如何 SharePoint 實際處理這些屬性。但是您可以考慮它以下列方式:Well, that is where the two properties HitHighlightedProperties and HitHilightedSummary are useful. The diagram below does not represent how SharePoint actually handles these properties. However you can think about it in the following way:

命中項目醒目流程圖

  1. 列出搜尋結果網頁組件Hit highlight 屬性 (JSON)區段中的 managed 的屬性與"魔法 summary"屬性會傳遞至HitHighlightedProperties屬性。The managed properties that are listed in the Hit-highlighted properties (JSON) section of the Search Results Web Part and the "magical summary" property are passed to the HitHighlightedProperties property.

  2. 所有HitHighlightedProperties屬性的值會都傳遞至HitHighlightedSummary屬性。All values of the HitHighlightedProperties property are passed to the HitHighlightedSummary property.

  3. HitHighlightedSummary中的值是截斷會顯示在搜尋結果網頁組件。A truncated version of the values in HitHighlightedSummary is displayed in the Search Results Web Part.

如果您仔細查看搜尋結果中,您會發現許多的搜尋結果的顯示具有三個點狀線結束。If you look closely at the search results, you'll notice that many search results are displayed with three dots at the end.

結果點

這些點狀線表示這些HitHighlightedSummary屬性的值。These dots indicate that these are values from the HitHighlightedSummary property.

如果您只想要顯示的資訊的每個搜尋結果的長度下限,您可以依賴點擊醒目提示識別常數和可能與搜尋結果顯示的預設方法是 [確定]。但是,如果您想要顯示的每個搜尋結果的自訂資訊,您必須執行一些自訂。If you only want to display a minimum amount of information for each search result, you can rely on the hit highlighting magic and probably be OK with the default way search results are displayed. But, if you want custom information to be displayed for each search result, you'll have to do some customization.

下一篇文章在您將了解自訂搜尋結果的第一個步驟: 建立新的結果類型。In the next article you'll learn the first step in customizing search results: creating a new result type.

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

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