在 SharePoint Server 中管理查詢規則

適用于:yes-img-132013 yes-img-16 2016yes-img-192019 yes-img-se訂閱版本 no-img-sopMicrosoft 365 中的 SharePoint

在不使用任何自訂程式碼的情況下,搜尋服務應用程式系統管理員、網站集合管理員或網站擁有者可以藉由建立和管理查詢規則來改善傳統搜尋結果。 查詢規則可協助搜尋回應使用者的意圖。

在查詢規則中,您可指定條件和相關聯的動作。 當查詢符合查詢規則的條件時,搜尋系統會執行規則中指定的動作,以改進搜尋結果的相關性,例如縮減結果或變更結果的顯示順序。 舉例來說,查詢規則中的條件可以是查詢中的字詞符合 SharePoint Server 字詞組中的某個特定字詞,或者是查詢經常執行於搜尋系統中的某個特定結果來源,例如視訊。 當滿足查詢規則中的條件後,相關聯的動作可能是在搜尋結果的頂端顯示特定項目。

您可以針對一或多個結果來源設定查詢規則,還可以指定查詢規則發生作用的時段。

注意事項

查詢規則也會在下列情況下影響SharePoint Server 2019的新式搜尋體驗

  • 規則中的動作是將個別結果升階至搜尋結果的頂端。
  • 規則是針對預設結果來源所定義。
  • 規則是在搜尋服務應用層級定義的。

只有在下列情況下,使用者才會在新式搜尋體驗中看到這類升級的結果:

  • 他們已在所有 SharePoint 中搜尋結果。
  • 搜尋結果頁面會篩選為預設檢視) (所有結果類型

在 SharePoint Server 伺服器陣列的不同層級建立查詢規則

您可以建立 Search Service 應用程式、網站集合或網站的查詢規則。 下表顯示每個案例中建立查詢規則所需的權限,以及可在何處使用查詢規則。

查詢規則的層級和權限

在此層級建立查詢規則 您必須具備此權限 可使用查詢規則的地方
Search Service 應用程式
Search Service 應用程式管理員
Web 應用程式中使用 Search Service 應用程式的所有網站集合
網站集合
網站集合管理員
網站集合中的所有網站
網站
網站擁有人
該網站

To add or edit a query rule, you must go to the Manage query rules page. Depending on the level at which you are creating the query rule, use one of the following procedures to go to the Manage query rules page.

移至 Search Service 應用程式的管理查詢規則頁面

  1. 確認執行此程序的使用者帳戶為否為 Search Service 應用程式管理員。

  2. 在管理中心中,按一下 [應用程式管理] 區段的 [管理服務應用程式]

  3. 按一下您要新增查詢規則的 Search Service 應用程式。

  4. 在 Search Service 應用程式的 [搜尋管理] 頁面上,在 [快速啟動] 中,按一下 [查詢與結果] 區段中的 [查詢規則]

移至網站集合的管理查詢規則頁面

  1. 確認執行此程序的使用者帳戶為網站集合管理員。

  2. 在網站集合的 [設定] 功能表中,按一下 [網站設定]

  3. 在 [網站設定]頁面上,按一下 [網站集合管理] 區段中的 [搜尋查詢規則]

移至網站的管理查詢規則頁面

  1. 請確認執行此程序的使用者帳戶為網站擁有人群組的成員。

  2. 在網站的 [設定] 功能表上,按一下 [網站設定]

  3. 在 [網站設定] 頁面上,按一下 [網站管理] 區段中的 [查詢規則]

建立查詢規則

  1. 指定此查詢規則的結果來源。 Use the Select a Result Source menu, on the Manage Query Rules page.

  2. 按一下 [新增查詢規則]

  3. Give the query rule a name. Use the Rule name field on the Add Query Rule page.

  4. If relevant, restrict this rule to queries performed on a particular result source. Click to expand the Context section, and under Query is performed on these sourcesselect one of the following:

  • 若要將查詢規則套用至所有的結果來源,請選取 [所有來源]

  • To restrict the query rule to one or more specific result sources, select One of these sources. By default, the result source that you specified in step 1 is selected.

  1. If relevant, restrict the rule to be performed from a particular category —for example, that a query rule should fire only when a term from your managed navigation term set is included in the query. In the Context section, under Query is performed from these categories select one of the following:
  • To restrict the query rule to a particular category, click One of these categories and then add the category. 在 [ 從分類法 匯入] 對話方塊中,選取一個字詞,當您將其包含在查詢中時,將會引發查詢規則,然後按一下 [ 儲存]

  • 若要移除任何限制,請按一下 [所有類別]

  1. If relevant, restrict the rule to be performed by a particular user segment. In the Context section, under Query is performed by these user segments select one of the following::
  • To restrict the query rule to a particular user segment, click One of these user segments and then add the user segment. Enter a title for the user segment and then click Add user segment term. 在 [ 從分類法 匯入] 對話方塊中,選取一個字詞,當您將其包含在查詢中時,將會引發查詢規則,然後按一下 [ 儲存]

  • 若要移除任何限制,請按一下 [所有使用者區段]

  1. Specify when a query makes this rule fire. You can have more than one condition, and the rule will fire when any condition is true. In the Query Conditions section do one of the following:
  • 選取 [會觸發規則的條件概觀] 中所列的其中一個條件。

  • 新增其他條件。

  • Click Remove Condition to configure this query rule to fire for every query that users type at the level at which you are creating the rule. For example, if you are creating this rule for a site collection, click Remove Condition if you want this rule to fire for every query that users type inside any search box in the site collection.

  1. Specify the action to take when the query rule fires. In the Actions section you can:
  • Promote individual results so that they appear towards the top of search results. You can add several individual promoted results. When there is more than one promoted result, you can specify the relative ranking. To promote, click Add Promoted Result (in SharePoint 2010 Products this was called Best Bets). 在 [ 新增升級的結果 ] 對話方塊中,為升級的結果指定名稱,然後輸入要升階之結果的 URL。 You can define that the URL is rendered as a banner instead of as a hyperlink.

  • Promote a group of search results, click Add Result Block. For more information, see Create and display a result block later in this article.

  • Change ranked search results, click Change ranked results by changing the query. For more information, see Change ranked search results later in this article.

  1. 若要在特定時間期間啟用查詢規則,請按一下 [發佈],然後指定期間。

會觸發規則的條件概觀

查詢條件 描述 設定 範例
查詢完全符合關鍵字
若您希望當查詢完全符合您指定的字詞或片語時觸發查詢規則,請選取此選項。
在 [查詢完全符合這些片語之一] 文字方塊中,輸入一或多個片語,並以分號隔開。
You type "picture; pic" in the Query contains one of these phrases box. The query rule will fire when a user types "picture" or "pic" in a search box. The rule will not fire if a user types "pictures" or "sunny picture."
查詢包含動作字詞
若您希望當查詢包含指出使用者要進行之動作的字詞時,會觸發查詢規則,請選取此選項。 字詞必須位於查詢的開頭或結尾。
動作字詞可以是您輸入的數個詞句之一。 或者也可以是字典 (可以匯入字詞) 中的項目。
您在 [動作字詞是這些文句之一] 文字方塊中輸入 "download"。 當使用者在搜尋方塊中輸入「下載 Contoso Electronics 資料工作表」時,使用者可能不會搜尋包含「下載」、「Contoso」、「電子」和「資料工作表」等字組的檔。相反地,使用者可能會嘗試下載 Contoso Electronics 資料工作表。 當使用者在搜尋方塊中輸入 "download Contoso Electronics datasheet" 時,會觸發搜尋規則,並且僅會將 "Contoso"、"Electronics" 及 "datasheet" 傳送至搜尋索引。
查詢完全符合字典
若您希望當查詢完全符合字典項目時觸發查詢規則,請選取此選項。
From the ** Query contains an entry in this dictionary ** menu, select a dictionary. 若要指定不同的字典,請按一下 [ 從分類法匯入],然後從 [ 從分類 法匯入] 對話方塊中選取字片語中的字詞,然後按一下 [ 儲存]
使用者在搜尋方塊中輸入的文字符合預先設定之「人員姓名」字典中的項目。
經常在來源查詢
若要在使用者於您指定的其他結果來源經常發出查詢時引發查詢規則,請選取此選項。
在 [查詢比較可能會用於這個來源] 功能表中,選取結果來源。
In the Query is more likely to be used in this source menu, you select Local Video Results. The query rule will fire if a user types the word "training" in a search box and that word was frequently typed in a search box in the Videos vertical.
常點選的結果類型
若您希望當其他使用者在輸入相同查詢後,經常點選特定結果類型時觸發查詢規則,請選取此選項。
在 [常點選的結果與結果類型相符] 功能表中選取結果類型。
In the Commonly clicked results match result type box, you select SharePoint MicroBlog post. If users frequently click a microblog post in search results, then in the Actions section, you might want to configure the most recent microblog post as the first promoted result, and the next most recent microblog post as the second promoted result.
進階查詢文字比對
若您希望使用會觸發查詢規則的規則運算式、片語或字典項目,請選取此選項。
若要比對某特定格式的所有電話號碼,可在 [查詢符合此規則運算式] 方塊中指定規則運算式。
若要比對所有格式為 nnn-nnn-nnnn 的電話號碼,請指定正則運算式 「 (? (\d {3}) ) ?-? (\d {3}) - (\d {4}) 」。

建立及顯示結果區塊

結果區塊是顯示為一個群組的多筆搜尋結果。 例如,針對含有「Fabrikam 銷售報告」的查詢,查詢規則可使用分類字典,將「Fabrikam」識別為客戶,然後顯示來自您的客戶關係管理 (CRM) 系統,且與「Fabrikam」有關的結果區塊。

就如同您可將特定的結果升階一樣,也可在指定的查詢條件適用時將結果區塊升階。

當您設定查詢以執行結果區塊時,可以使用「查詢變數」。 查詢變數是您指定查詢時,為不知道的值所保留的預留位置。 不過在執行查詢後,當系統將查詢傳送至索引時,便可得知及使用這項資訊。 例如,{User.Name} 代表輸入查詢之使用者的顯示名稱,或是 {searchBoxQuery} 代表使用者在搜尋方塊中輸入的查詢。 如需可用的查詢變數清單,請參考 Query variables in SharePoint Server

若您不熟悉查詢變數,可以使用「查詢建立器」來設定查詢 (請參閱下列程序中的步驟 3)。

建立結果區塊

  1. 在先前程序的步驟 8 中,在 [新增查詢規則] 頁面,按一下 [動作] 區段中的 [新增結果區塊]

  2. Enter the title that shall appear in the result block in the Title field in the Block Title section. Enter a title for each language that's relevant.

  3. Configure the query that gives results for the block. In the Query section, click Launch Query Builder, and on the BASIC tab do the following:.

  • 從 [選取查詢] 區段中的下拉式清單內選取結果來源,以選取要搜尋的內容。

  • Specify your query in the Query text box. You can select pre-defined query variables from the Keyword filter drop-down list, and then add them to the Query text box by clicking Add keyword filter.

  • If relevant, use property filters to query the content of managed properties that are set to queryable in the search schema. You can select managed properties from the Property filter drop-down list. Click Add property filter to add the filter to the query.

  • 按一下 [測試查詢] 來加以測試。

  1. Specify how the search results within your result block should be sorted. Sorting of search results is case sensitive. On the SORTING tab, in the Sort by drop-down list, select a managed property, and then select Descending or Ascending. The list only contains managed properties that are set as sortable in the search schema. You can also sort by rank. To add more sorting levels, click Add sort level:

  2. 若您選擇按順位排序,也可以:

  • Select which model to use for ranking search results (this selection is optional). Use the Ranking Model drop-down list.

  • Define rules for dynamically changing the ordering of results. In the Dynamic ordering section, define when to change ranking by selecting a condition from the drop-down list and then specifying whether to promote or demote the result. To add more rules, click Add dynamic ordering rules

  1. 預覽 [ 測試 ] 索引標籤上內容搜尋網頁元件將執行的最終查詢。預覽是以原始查詢範本為基礎,其中動態變數會以目前的值取代。 查詢的其他變更可能必須做為查詢規則的一部分。 按一下 [顯示更多] 以顯示其他資訊。
  • [查詢範本] 方塊會顯示套用到查詢的查詢範本內容。

  • The Query template variables section shows the query variables that will be applied to the query, and the values of the variables that apply to the current page. You can type other values to test the effect they will have on the query. Click the Test Query button to preview the search results.

  1. Define which result source this result block should be applied to. Use the Search this Source drop-down list in the Query section.

  2. Define how many results ro show in the result block. Use the In the Items drop-down list, in the Query section.

  3. The result block will only display the number of search results that you specified in the previous step. 但您可以在結果區塊底部新增 [顯示更多] 連結,以顯示結果區塊的所有搜尋結果。 To add a SHOW MORE link, expand the Settings section, select "More" link goes to the following URL, and then type a URL. 您可以在此 URL 中使用查詢變數,http://www.< 例如 site > /search/results.aspx?k={subjectTerms}

  4. 略過 [路由] 區段。

  5. 按一下 [確定]

變更排名的搜尋結果

排名模型會計算搜尋結果的排名順序。 您可以升級或降級搜尋結果中的項目,以變更此排名。 例如,針對包含 "download toolbox" 的查詢,可以建立能夠辨識字詞 "download" 為動作字詞的查詢規則,並變更排名的搜尋結果,以升級您內部網路中特定下載網站的 URL。 您也可以根據一些變數,例如副檔名或特定關鍵字,動態變更搜尋結果排序。 以變更查詢的方式變更排名的搜尋結果之優點為,結果是經過安全性調整且可精簡。 此外,若不再提供文件時,甚至不會顯示搜尋結果。

透過變更查詢來變更排名的搜尋結果

  1. 在程序<建立查詢規則>的步驟 8 中,在「新增查詢規則」頁面的 [動作] 區段中,按一下 [以變更查詢的方式變更排名後的結果]。 [ 建置您的查詢] 對話方塊隨即出現。

  2. 在 [基本] 索引標籤上執行下列動作:

  • 從 [選取查詢] 區段中的下拉式清單內選取結果來源,以選取要搜尋的內容。

  • Specify your query in the Query text box. You can select pre-defined query variables from the Keyword filter drop-down list, and then add them to the Query text box by clicking Add keyword filter.

  • If relevant, use property filters to query the content of managed properties that are set to queryable in the search schema. You can select managed properties from the Property filter drop-down list. Click Add property filter to add the filter to the query.

  • 按一下 [測試查詢] 來加以測試。

  1. Specify how the search results within your result block should be sorted. Sorting of search results is case sensitive. On the SORTING tab, in the Sort by drop-down list, select a managed property, and then select Descending or Ascending. The list only contains managed properties that are set as sortable in the search schema. You can also sort by rank. To add more sorting levels, click Add sort level:

  2. 若您選擇按順位排序,也可以:

  • Select which model to use for ranking search results (this selection is optional). Use the Ranking Model drop-down list.

  • Define rules for dynamically changing the ordering of results. In the Dynamic ordering section, define when to change ranking by selecting a condition from the drop-down list and then specifying whether to promote or demote the result. To add more rules, click Add dynamic ordering rules

  1. 預覽 [ 測試 ] 索引標籤上內容搜尋網頁元件將執行的最終查詢。預覽是以原始查詢範本為基礎,其中動態變數會以目前的值取代。 查詢的其他變更可能必須做為查詢規則的一部分。 按一下 [顯示更多] 以顯示其他資訊。
  • [查詢範本] 方塊會顯示套用到查詢的查詢範本內容。

  • The Query template variables section shows the query variables that will be applied to the query, and the values of the variables that apply to the current page. You can type other values to test the effect they will have on the query. 按一下 [測試查詢] 按鈕預覽搜尋結果。

停用查詢規則

取用 Search Service 應用程式之 Web 應用程式中的網站集合及網站會繼承在 Search Service 應用程式層級建立的查詢規則。 同樣地,網站集合中的網站也會繼承在網站集合層級建立的查詢規則。 若不要將繼承而來的查詢規則套用至網站,可針對網站將查詢規則設為停用。

停用網站的查詢規則

  1. 請確認執行此程序的使用者帳戶為網站擁有人群組的成員。

  2. 在網站集合的 [設定] 功能表中,按一下 [網站設定]

  3. 在 [網站設定] 頁面上,按一下 [搜尋] 區段中的 [查詢規則]

  4. 在「管理查詢規則」頁面的 [選取結果來源] 功能表中,選取包含您要停用之查詢規則的結果來源。

  5. 在 [名稱] 欄中指向您要停用的查詢規則,按一下出現的箭頭,然後按一下 [變為已停用]

排名查詢規則

當啟用 Search Service 應用程式、網站集合或網站的多個查詢規則時,可以針對在該層級上執行的查詢觸發多個規則。 根據預設,不會依照指定的順序觸發規則。 您可以藉由將建立的查詢規則新增至查詢群組,以控制規則觸發的順序。 若要執行此操作,請選取要新增至群組的規則,然後指定群組中的規則要觸發的順序。 您也可以使群組中最低排名的查詢規則,即使受到觸發也不會被觸發。

為網站集合排名查詢規則

  1. 確認執行此程序的使用者帳戶為網站集合管理員。

  2. In the site collection, on the Settings menu, click Site Settings.

  3. 在 [網站設定]頁面上,按一下 [網站集合管理] 區段中的 [搜尋查詢規則]

  4. 在「管理查詢規則」頁面的 [選取結果來源] 功能表中,選取包含您要加入群組之查詢規則的結果來源。

  5. 針對您所建立且要新增至群組的每個查詢規則,指向規則,並選取核取方塊。

    注意事項

    您針對此網站集合建立的查詢規則會列在 [已針對此網站集合定義] 區段中。

  6. 按一下 [順序選取規則]

  7. 在 [ 排序選取的規則] 對話方塊中,執行下列其中一項,然後按一下 [ 確定]

  • 選取 [將規則移至具有此名稱的新群組],然後輸入群組名稱。

  • 選取 [將規則移至現有群組],然後在下拉式清單中選取群組。

  1. 在 [管理查詢規則] 頁面上,執行下列操作:

  2. 若要變更群組中規則的觸發順序,請變更規則的號碼順序。

  3. 若要使群組中最低排名的查詢規則不會被觸發,請在要最後觸發的群組查詢規則的該列中,在 [動作] 欄中的 [繼續/停止] 下拉式清單中選取 [停止]

另請參閱

概念

在 SharePoint Server 中規劃轉換查詢和順序結果

SharePoint Server 中的搜尋結果排名概觀

Query variables in SharePoint Server