了解 SharePoint Server 中搜尋結果的顯示方式Understanding how search results are displayed in SharePoint Server

摘要:了解 SharePoint Server 2016 與 SharePoint Server 2013 的搜尋結果的顯示方式。Summary: Learn how search results are displayed in SharePoint Server 2016 and SharePoint Server 2013.

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

預設搜尋結果的顯示方式How search results are displayed by default

當您搜尋搜尋中心內的某個項目時,您的結果會以不同方式顯示。例如,下列螢幕擷取畫面中,注意到每個搜尋結果的 Word、 PDF 及 Excel 圖示的顯示方式。When you search for something in a Search Center, your results are displayed differently. For example, in the following screen shot, notice how the icons for Word, PDF, and Excel are displayed for each of the search results.

預設內文搜尋結果

由停留第一個搜尋結果,會顯示結果的詳細資訊。By hovering over the first search result, more information about the result is displayed.

預設 PPT 動態顯示面板

由停留第四個結果,顯示的資訊與您所見時您之上一段的第一個結果不同。By hovering over the fourth result, the information that is displayed differs from what you saw when you hovered over the first result.

預設 PDF 動態顯示面板

項目將要在這裡和項目會進行搜尋結果顯示讓不同?這是本文的主旨。What's going on here, and what's making the search results display so differently? That is the subject of this article.

關於控制搜尋結果的顯示方式About controlling how search results are displayed

搜尋結果會顯示在搜尋結果網頁組件中。下列螢幕擷取畫面顯示如何 SharePoint 使用兩個顯示範本來控制如何顯示搜尋結果的相關資訊:Search results are displayed in a Search Results Web Part. The following screen shot shows how SharePoint uses two display templates to control how information about search results is displayed:

  1. 此項目顯示範本控制項內文的搜尋結果網頁組件資訊的顯示方式。The item display template controls how the information in the body of the Search Results Web Part is displayed.

  2. 在動態顯示面板顯示範本控制項中動態顯示面板的資訊的顯示方式。The hover panel display template controls how the information in the hover panel is displayed.

    Where 結果

有可用的 90 預設搜尋顯示範本。這可能會看起來像是很多,並稍後會說明有太的原因。現在,若要查看所有的顯示範本的預設搜尋,移至 [網站設定 --> 主版頁面與版面配置。在主版頁面圖庫中,按一下 [顯示範本 --> 搜尋There are 90 default search display templates available. This might seem like a lot, and the reasons there are so many will be explained later. For now, to see all the default search display templates, go to Site settings --> Master pages and page layouts. In the Master Page Gallery, click Display Templates --> Search.

這個資料夾、 只有 HTML 檔案和每個顯示範本的 JavaScript 檔案。In this folder, there is an HTML file and a JavaScript file for each display template.

搜尋資料夾

若要檢視或編輯顯示範本,請使用 HTML 檔案中。時將其上傳,SharePoint 自動將 HTML 檔案轉換成相關聯的 JavaScript 檔案。因為這兩個檔案有相關聯,對 HTML 檔案中所做的任何變更將會自動更新相關聯的 JavaScript 檔案。To view or edit a display template, use the HTML file. SharePoint automatically transforms the HTML file into an associated JavaScript file when you upload it. Because the two files are associated, any changes that you make to the HTML file will automatically update the associated JavaScript file.

顯示範本工時稍後的這一系列的提供如何詳細資料。現在,我們移至結果類型。Details about how display templates work will be provided later in this series. For now, let's move on to result types.

關於結果類型About result types

如果使用者可以直接在搜尋結果頁面上看見搜尋結果的相關資訊,這會將它們儲存按一下並開啟每個項目] 以了解其相關的麻煩。如果您在查看回預設搜尋結果的顯示方式,您可以輕鬆看見前兩個結果的 PowerPoint 簡報和第三個結果是 Word 文件。If a user can see information about search results directly on the search results page, this will save them the trouble of having to click and open each item to see what it's about. If you look back at How search results are displayed by default, you can easily see that the first two results are PowerPoint presentations, and the third result is a Word document.

若要以不同方式顯示搜尋結果,搜尋結果必須排序成不同的結果類型。結果類型區分另一個搜尋結果。例如,如果 Microsoft Word 文件中找到的搜尋結果,該搜尋結果是屬於Microsoft Word結果類型。如果 PDF 檔案中找到的搜尋結果, PDF結果類型是屬於該搜尋結果。To display search results differently, search results have to be sorted into different result types. A result type distinguishes one search result from another. For example, if a search result is found in a Microsoft Word document, that search result belongs to the Microsoft Word result type. If a search result is found in a PDF file, that search result belongs to the PDF result type.

有 31 預設結果類型。若要查看,前往 [網站設定 --> 結果類型There are 31 default result types. To see them, go to Site Settings --> Result Types.

如需預設結果類型的概觀,請參閱結果類型和,用來顯示在 SharePoint Server 中的搜尋結果的顯示範本。您不需要擔心指定預設搜尋結果的方式。它 「 內部 」 在 SharePoint Server 2016 發生的情況。For an overview of the default result types, see Result types and display templates that are used to display search results in SharePoint Server. You don't have to worry about how default search results are specified. It happens "inside" in SharePoint Server 2016.

您不可以編輯任何預設結果類型。但是,您可以將它,複製並新增其他設定。這會清楚稍後的這一系列,但前,請務必了解結果類型和顯示範本如何彼此相連。It is not possible to edit any of the default result types. But, you can copy them, and add additional configurations. This will be explained later in this series, but first, it's important to understand how result types and display templates are connected.

關於結果之間的連線輸入與顯示範本About the connections between a result type and display templates

這些連線的機制不是非常官方轉寄且更容易理解,但是讓我們看逐步說明的方式。The mechanics of these connections are not very straight forward and easy to understand, but let's take a look in a step-by-step manner.

  1. 每個結果類型包含的項目顯示範本,例如Item_PowerPoint的參照。Each result type contains a reference to an item display template, for example, Item_PowerPoint .

  2. 每個項目顯示範本包含以動態顯示面板顯示範本,例如Item_PowerPoint_HoverPanel的參照。Each item display template contains a reference to a hover panel display template, for example, Item_PowerPoint_HoverPanel .

    連線 1

    讓我們開始使用的第一個連線。如需結果類型和項目顯示範本之間的連線,請移至 [網站設定 --> 結果類型。選取 [檢視結果類型,例如Microsoft PowerPointLet's start with the first connection. To see the connection between a result type and an item display template, go to Site Settings --> Result Types. Select to view a result type, for example Microsoft PowerPoint.

    PPT 結果類型

    在 [結果類型] 頁面上 [顯示範本 URL ] 區段中有指向名為Item_PowerPoint.js檔案的 URL。On the Result Type page, in the Display template URL section, there's a URL that points to a file that is named Item_PowerPoint.js.

    顯示範本 URL

    此 URL 會是一個項目顯示範本參照。這表示屬於Microsoft PowerPoint結果類型的所有搜尋結果會都顯示使用Item_PowerPoint.js顯示範本。This URL is a reference to an item display template. This means that all search results that belong to the Microsoft PowerPoint result type will be displayed by using the Item_PowerPoint.js display template.

    如果您查詢主版頁面圖庫中,您會看到Item_PowerPoint.js檔案和相關聯的Item_PowerPoint.html檔案。If you look in the Master Page Gallery, you'll see the Item_PowerPoint.js file and the associated Item_PowerPoint.html file.

    PowerPoint 項目顯示範本

    現在的第二個的連線: 若要查看的項目顯示範本和動態顯示面板顯示範本之間的連線,請開啟 [ Item_PowerPoint.html。您會看到動態顯示面板顯示範本,在此例中Item_PowerPoint_HoverPanel.js的參照。Now for the second connection: to see the connection between an item display template and a hover panel display template, open Item_PowerPoint.html. You'll see a reference to a hover panel display template, in this case, Item_PowerPoint_HoverPanel.js.

    動態顯示範本參考

    在 [主版頁面圖庫中,您會發現Item_PowerPoint_HoverPanel.js檔案和相關聯的Item_PowerPoint_HoverPanel.html檔案。In the Master Page Gallery, you'll find the Item_PowerPoint_HoverPanel.js file and the associated Item_PowerPoint_HoverPanel.html file.

    動態顯示面板顯示範本

    現在您知道原因有賣許多搜尋顯示範本。那是因為四個顯示範本已連線至每個結果類型。So now you know why there are so many search display templates. It's because four display templates are connected to each result type.

    如需預設結果類型之間的連線的概觀,項目顯示範本,以及動態顯示面板顯示範本,請參閱結果類型及,用來顯示在 SharePoint Server 中的搜尋結果的顯示範本For an overview of the connection between the default result types, item display templates, and hover panel display templates, see Result types and display templates that are used to display search results in SharePoint Server.

    直線的正向,不過,我們不完全到尚未。連接至結果類型的顯示範本,除了有所有結果類型所使用的顯示範本。That was straight forward, however, we're not completely through yet. In addition to the display templates that are connected to a result type, there are display templates that are used by all result types.

關於顯示範本所使用的所有結果類型About display templates that are used by all result types

若要重溫:To recap:

  1. 每個結果類型會包含一個項目顯示範本的參照。Each result type contains a reference to an item display template.

  2. 每個項目顯示範本包含以動態顯示面板顯示範本的參照。Each item display template contains a reference to a hover panel display template.

    然後我們需要再加:and then we have to add:

  3. 每個項目顯示範本包含一般的項目顯示範本的參照。Each item display template contains a reference to a common item display template.

  4. 每個動態顯示面板顯示範本包含三個一般動態顯示面板顯示範本的參照。Each hover panel display template contains references to three common hover panel display templates.

    連線 1

    這些一般顯示範本位於相同的主版頁面圖庫資料夾專屬個別的結果類型的顯示範本。These common display templates are located in the same Master Page Gallery folder as the display templates that are specific to individual result types.

    一般顯示範本

    每個項目顯示範本指引常見的項目顯示範本。下列螢幕擷取畫面顯示如何使用Microsoft Excel結果類型的項目顯示範本指向一般顯示範本Item_CommonItem_BodyEach item display template points to the common item display template. The following screen shot shows how the item display template that was used for the Microsoft Excel result type points to the common display template Item_CommonItem_Body .

    一般項目參考

    每個動態顯示面板顯示範本指引三個一般動態顯示面板顯示範本。下列螢幕擷取畫面顯示如何使用Microsoft Excel結果類型的動態顯示顯示範本指向三個一般動態顯示面板顯示範本。Each hover panel display template points to three common hover panel display templates. The following screen shot shows how the hover display template that is used for the Microsoft Excel result type points to the three common hover panel display templates.

    一般動態顯示範本參考

    如果所有這些參考有點混淆,請不要擔心。即將推出本系列文章將會使用讓容易理解的範例。此時,務必要知道如何使用結果類型來分類不同類型的搜尋結果與結果類型如何連接至不同的顯示範本。If all these references are a bit confusing, don't worry. Upcoming articles in this series will use examples that will make it easier to understand. At this point, it's important to know how result types are used to categorize different types of search results, and how result types are connected to different display templates.

在搜尋結果網頁組件的顯示範本設定的相關About display template settings in the Search Results Web Part

現在的拼圖最簡單的一部分:搜尋結果網頁組件如何知道如何顯示不同的結果類型為基礎的搜尋結果?Now for the easiest part of the puzzle: how does the Search Results Web Part know how to display search results based on the different result types?

在 [搜尋結果] 頁面上按一下 [編輯搜尋結果網頁組件]。在網頁組件工具窗格中,展開 [顯示範本On the search results page, click to edit the Search Results Web Part. In the Web Part Tool Pane, expand Display Templates.

搜尋 WP 設定

您會看見預設會選取 [使用結果類型來顯示項目] 選項按鈕。這表示根據所屬的結果類型會顯示搜尋結果。這是它 !You'll see that the radio button Use result types to display items is selected by default. This means that search results will be displayed based on the result type that they belong to. That's it!

現在您了解機制的搜尋結果的顯示方式。我們將此系列中的下一篇文章 < 進入詳細的資訊項目顯示範本,並也解釋的結果醒目提示識別常數。So now you know about the mechanics of how search results are displayed. The next article in this series, we'll goes into detail about the item display template, and also explains the magic of hit highlighting.

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

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