在 SharePoint Server 中自訂搜尋結果類型Customize search result types in SharePoint Server

在 SharePoint Server 2016 和 SharePoint Server 2013 中建立和設定自訂的搜尋結果類型,讓使用者可以輕鬆地區別並預覽搜尋結果清單中不同類型的項目。Create and configure custom search result types in SharePoint Server 2016 and SharePoint Server 2013 so that users can readily distinguish and preview different kinds of items in a list of search results.

搜尋「結果類型」是一種規則,可讓不同類型的搜尋結果以不同方式顯示。其由下列項目組成:A search result type is a rule that causes distinct kinds of search results to be displayed in different ways. It consists of the following:

  • 一或多個要用來比較每個搜尋結果的特性或條件,例如結果來源或是搜尋結果的內容類型One or more characteristics or conditions to compare each search result against, such as the result source or content type of the search result

  • 當搜尋結果符合條件時所要使用的「顯示範本」。顯示範本會控制所有符合條件的結果在搜尋結果頁面上的顯示方式與行為。A display template to use for search results that meet the conditions. The display template controls the way in which all results that meet the conditions appear and behave on a search results page.

搜尋系統已預先設定一些結果類型,這些也是它預設會使用的結果類型。您可以在 [管理結果類型] 頁面上檢視它們。例如,預先設定的結果類型 [人員]**** 指定如果搜尋結果是來自結果來源 [本機人員結果]*,則使用 [人員項目]* 顯示範本來顯示結果。[人員項目]**** 顯示範本會在搜尋結果中顯示特定使用者設定檔資訊,並在動態顯示面板中提供連結,以供連至該人員所編寫的文件。The search system has preconfigured result types that it uses by default. You can view them on the Manage Result Types page. For example, a preconfigured result type named Person specifies that if a search result comes from the result source Local People Results, then use the People Item display template to display the result. The People Item display template shows certain user-profile information in the search result and provides links in the hover panel for documents that the person has authored.

身為網站集合管理員或網站擁有者,您可以使用預設結果類型作為建立自訂結果類型的起點。例如,預先設定的 Microsoft Excel 結果類型指定了一個條件:搜尋結果副檔名為 XLS 或 XLSX。您可以將此結果類型複製過來進行自訂,讓它再包含一個條件: ContentType 受管理屬性值為 Sales Report。這樣一來,使用者就可以馬上找出銷售報表類型的特定 Excel 搜尋結果。As a site collection administrator or site owner, you can use the default result types as starting points for creating custom result types. For example, the pre-configured Microsoft Excel result type specifies the condition that the file extension of the search result is XLS or XLSX. You could copy this result type and customize it so that it also includes the condition that the value of the ContentType managed property is Sales Report. That way, users will readily be able to identify certain Excel search results as sales reports.

您也可以針對此用途,自訂預設的 [Excel 項目]**** 顯示範本。顯示範本會指定如何顯示搜尋結果的受管理屬性,例如項目標題、副檔名、路徑和摘要。這可協助使用者輕鬆區別結果。顯示範本也會控制文件或網站將會如何出現在搜尋結果右邊的預覽窗格 (也稱為「動態顯示面板」)。這可讓使用者還未按一下結果來開啟結果,就知道搜尋結果是否對自己有用。例如,[Excel 項目]**** 顯示範本可以在動態顯示面板中顯示 Excel 文件的相關圖表、工作表和表格,並讓使用者能夠直接前往文件中的那些位置。如需各搜尋結果類型適用之顯示範本的詳細資訊,請參閱:You could also customize the default Excel Item display template for this purpose. A display template specifies how to display managed properties of a search result, such as item title, file extension, path, and summary. This helps users to distinguish results easily. The display template also controls how a document or site will appear in the preview pane (also called the hover panel) to the right of the search result. This helps users to know whether a search result will be useful to them before they click the result to open it. For example, the Excel Item display template can display relevant charts, worksheets, and tables from an Excel document in the hover panel and enable users to go directly to those sections in the document. For more information about display templates for search result types, see:

注意

因為 SharePoint Server 在 Internet Information Services (IIS) 中以網站形式運作,所以管理員與使用者均依賴瀏覽器提供的協助工具功能。SharePoint Server 支援所支援瀏覽器的協助工具功能。如需詳細資訊,請參閱下列資源:Because SharePoint Server runs as websites in Internet Information Services (IIS), administrators and users depend on the accessibility features that browsers provide. SharePoint Server supports the accessibility features of supported browsers. For more information, see the following resources:

  1. 執行下列其中一項動作,移至 [管理結果類型] 頁面:Go to the Manage Result Types page by doing one of the following:

    • 若要為網站集合建立結果類型:If you want to create a result type for a site collection:

      • 確定您是網站集合的管理員。Ensure that you are an administrator for the site collection.

      • 在網站集合中,移至 [設定] **** > [網站設定]*,然後按一下 [網站集合管理]* 區段中的 [搜尋結果類型]****。In the site collection, go to Settings > Site settings, and then in the Site Collection Administration section, click Search Result Types.

    • 若要為網站建立結果類型:If you want to create a result type for a site:

      • 確定您是網站的網站擁有者。Ensure that you are a site owner for the site.

      • 在網站上,移至 [設定] **** > [網站設定]*,然後按一下 [搜尋]* 區段中的 [結果類型]*On the site, go to *Settings > Site settings, and then in the Search section, click Result Types.

  2. 若要建立結果類型,請在 [管理結果類型] 頁面執行下列其中一項動作:To create a result type, do one of the following on the Manage Result Types page:

    • 按一下 [新增結果類型]*Click *New Result Type.

    • 在現有結果類型清單中,按一下結果類型的名稱 (例如 [人員]*),然後按一下 [複製],以便可以修改複本來建立新的結果類型。In the list of existing result types, click the name of a result type, such as **Person, and then click **Copy* so that you can modify the copy to create a new result type.

      提示

      建立結果類型時,建議您使用複製方法,以便將現有結果類型中的設定當成引導,來完成整個設定程序。When you create a result type, we recommend that you use the copy method, so that the settings in an existing result type can help guide you through the configuration process.

  3. 在 [新增結果類型] 頁面的 [一般資訊]**** 區段中,於 [指定名稱]**** 文字方塊中輸入新結果類型的名稱。On the Add Result Type page, in the General Information section, in the Give it a name text box, type a name for the new result type.

  4. 在 [新增結果類型] 頁面的 [條件]**** 區段中,執行下列動作:On the Add Result Type page, in the Conditions section, do the following:

    • 在 [結果應該符合哪個來源?]**** 下拉式清單中,選取結果來源 (例如 [所有來源]**** 或 [文件]*)。In the *Which source should results match? drop-down list, select a result source such as All Sources or Documents.

      對於任何一個搜尋結果,如果搜尋結果是來自您在此下拉式清單中選取的結果來源,則符合此條件。For any given search result, this condition will be met if the search result is from the result source that you selected from this drop-down list.

    • (選用) 在 [應該符合哪些類型的內容?]**** 下拉式清單中,執行下列動作:(Optional) In the What types of content should match? drop-down list, do the following:

    • 選取內容的類型,例如 [Microsoft Word]*Select a type of content, such as *Microsoft Word.

      注意

      如果您未選取內容的類型,則所有來自您在 [結果應該符合哪個來源?]**** 區段中指定之結果來源的結果,皆會符合此結果類型。If you do not select a type of content, all results from the result source that you specified (in the Which source should results match? section) will match this result type.

    • 視需要按一下 [新增值]**** 並選取另一種類型的內容 (此動作可重複任何次數)。As many times as appropriate, click Add Value and select another type of content.

  5. (選用) 在 [新增結果類型] 頁面上,展開 [顯示更多條件]**** 區段,然後執行下列動作:(Optional) On the Add Result Type page, expand the Show more conditions section, and then do the following:

    • 在 [應該符合哪些自訂屬性?]**** 區段中,[選取屬性]**** 下拉式清單中的項目是可擷取的受管理屬性。請選取您想要搜尋系統比對的屬性,例如 [作者]*In the *Which custom properties should match? section, the items in the Select a property drop-down list are retrievable managed properties. Select a property that you want the search system to perform a match on, such as Author.

    • 在第二個下拉式清單中,指定運算子,例如 [等於下列任一項目]*In the second drop-down list, specify the operator, such as *Equals any of.

    • 在文字方塊中,指定搜尋系統應該用來搜尋相符項目的值。In the text box, specify the value against which the search system should search for a match.

      請使用分號隔開多個值。或者,也可以視需要按一下 [新增值]*,並在顯示的新文字方塊中輸入另一個值 (此動作可重複任何次數)。Separate multiple values with semicolons. Alternatively, as many times as appropriate, click *Add Value and type another value in the new text box that appears.

      例如,如果您選取 [作者]**** 屬性並選取運算子 [等於下列任一項目]**** ,然後指定多個值 (例如 Kara 和 Silas),則條件會是「作者等於 Kara 或 Silas」。For example, if you select the Author property and you select the operator Equals any of, then if you specify multiple values such as Kara and Silas, the condition will be “author equals Kara or Silas”.

    • 若要新增另一個要比對的屬性,請按一下 [新增屬性]*To add another property to match, click *Add Property.

  6. 在 [新增結果類型] 頁面的 [動作]**** 區段中,執行下列動作:On the Add Result Type page, in the Actions section, do the following:

    • 在 [這些結果應該看來如何?]**** 下拉式清單中,按一下顯示範本,例如 [Office 文件項目]**** 或 [PDF 項目]*In the *What should these results look like? drop-down list, click a display template such as Office Document Item or PDF Item.

      在網站集合的主版頁面庫中,搜尋結果的顯示範本是位於 Search 資料夾中。[顯示範本 URL]**** 方塊會自動顯示與所選取顯示範本對應的顯示範本 URL。Display templates for search results are in the Search folder in the master page gallery for the site collection. The Display template URL box automatically displays the URL of the display template that corresponds to the display template that you selected.

    • 如果您預期此結果類型會經常出現在搜尋結果中,請選取 [最佳化以經常使用]**** 核取方塊。Select the Optimize for frequent use check box if you expect this result type to appear frequently in search results.

另請參閱See also

概念Concepts

Result types and display templates that are used to display search results in SharePoint ServerResult types and display templates that are used to display search results in SharePoint Server

在 SharePoint Server 中顯示範本參考Display template reference in SharePoint Server