在 SharePoint Server 中管理查詢規則Manage query rules in SharePoint Server

摘要: 了解如何建立和管理查詢規則以改善搜尋結果。Summary: Learn how to improve search results by creating and managing query rules.

Search Service 應用程式管理員、網站集合管理員和網站擁有者不需要使用任何自訂程式碼,即可建立「查詢規則」,而協助確保搜尋更貼近使用者的本意。在查詢規則中,您可指定條件和相關聯的動作。當查詢符合查詢規則中的條件時,搜尋系統就會執行規則中指定的動作,以提高搜尋結果的相關性,例如縮小結果的範圍或變更結果顯示的順序。舉例來說,查詢規則中的條件可以是查詢中的字詞符合 SharePoint 字詞組中的某個特定字詞,或者是查詢經常執行於搜尋系統中的某個特定結果來源,例如視訊。當滿足查詢規則中的條件後,相關聯的動作可能是在搜尋結果的頂端顯示特定項目。Search Service 應用程式管理員、網站集合管理員和網站擁有者不需要使用任何自訂程式碼,即可建立「查詢規則」 ,而協助確保搜尋更貼近使用者的本意。在查詢規則中,您可指定條件和相關聯的動作。當查詢符合查詢規則中的條件時,搜尋系統就會執行規則中指定的動作,以提高搜尋結果的相關性,例如縮小結果的範圍或變更結果顯示的順序。舉例來說,查詢規則中的條件可以是查詢中的字詞符合 SharePoint Server 字詞組中的某個特定字詞,或者是查詢經常執行於搜尋系統中的某個特定結果來源,例如視訊。當滿足查詢規則中的條件後,相關聯的動作可能是在搜尋結果的頂端顯示特定項目。Without using any custom code, Search service application administrators, site collection administrators, and site owners can help searches respond to the intent of users by creating query rules. In a query rule, you specify conditions and correlated actions. When a query meets the conditions in a query rule, the search system performs the actions specified in the rule to improve the relevance of the search results, such as by narrowing results or changing the order in which results are displayed. For example, a query rule condition could be that a term in a query matches a particular term in a SharePoint Server term set, or that a query is frequently performed on a particular result source in a search system, such as videos. When the query rule condition is satisfied, a correlated action could be to show a specific item at the top of the search results.

您可以針對一或多個結果來源設定查詢規則,還可以指定查詢規則發生作用的時段。You can configure query rules for one or more result sources, and you can specify the time period during which the query rule is active.

在 SharePoint Server 伺服器陣列的不同層級建立查詢規則Creating query rules at different levels in a SharePoint Server farm

您可以建立 Search Service 應用程式、網站集合或網站的查詢規則。下表顯示每個案例中建立查詢規則所需的權限,以及可在何處使用查詢規則。You can create a query rule for a Search service application, a site collection, or a site. The following table shows the permissions that are required to create a query rule in each case, and where the query rule can be used.

查詢規則的層級和權限Levels and permissions for query rules

在此層級建立查詢規則When you create a query rule at this level 您必須具備此權限You must have this permission 可使用查詢規則的地方The query rule can be used in
Search Service 應用程式Search service application
Search Service 應用程式管理員Search service application administrator
Web 應用程式中使用 Search Service 應用程式的所有網站集合All site collections in web applications that consume the Search service application
網站集合Site collection
網站集合管理員Site collection administrator
網站集合中的所有網站All sites in the site collection
網站Site
網站擁有人Site owner
該網站The site

若要新增或編輯查詢規則,您必須前往「管理查詢規則」**** 頁面。根據您要建立查詢規則的層級,使用下列程序之一前往「管理查詢規則」**** 頁面。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 應用程式的管理查詢規則頁面To go to the Manage query rules page for a Search service application

  1. 確認執行此程序的使用者帳戶為否為 Search Service 應用程式管理員。Verify that the user account that performs this procedure is an administrator for the Search service application.

  2. 在管理中心中,按一下 [應用程式管理]**** 區段的 [管理服務應用程式]*In Central Administration, in the *Application Management section, click Manage service applications.

  3. 按一下您要新增查詢規則的 Search Service 應用程式。Click the Search service application to which you want to add query rules.

  4. 在 Search Service 應用程式的 [搜尋管理] 頁面上,在 [快速啟動] 中,按一下 [查詢與結果]**** 區段中的 [查詢規則]*On the Search Administration page for the Search service application, in the Quick Launch, in the *Queries and Results section, click Query Rules.

    移至網站集合的管理查詢規則頁面To go to the Manage query rules page for a site collection

  5. 確認執行此程序的使用者帳戶為網站集合管理員。Verify that the user account that performs this procedure is a site collection administrator.

  6. 在網站集合的 [設定]**** 功能表中,按一下 [網站設定]*On the *Settings menu for the site collection, click Site Settings.

  7. 在 [網站設定]**** 頁面上,按一下 [網站集合管理]**** 區段中的 [搜尋查詢規則]*On the *Site Settings page, in the Site Collection Administration section, click Search Query Rules.

    移至網站的管理查詢規則頁面To go to the Manage query rules page for a site

  8. 請確認執行此程序的使用者帳戶為網站擁有人群組的成員。Verify that the user account that performs this procedure is a member of the Owners group for the site.

  9. 在網站的 [設定]**** 功能表上,按一下 [網站設定]*On the *Settings menu for the site, click Site Settings.

  10. 在 [網站設定]**** 頁面上,按一下 [網站管理]**** 區段中的 [查詢規則]*On the *Site Settings page, in the Site Administration section, click Query Rules.

建立查詢規則Create a query rule

  1. 指定此查詢規則的結果來源。使用 [管理查詢規則]**** 頁面上的 [選取結果來源]**** 功能表。Specify a result source for this query rule. Use the Select a Result Source menu, on the Manage Query Rules page.

  2. 按一下 [新增查詢規則]*Click *New Query Rule.

  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 apply the query rule to all result sources, select *All sources.

    • 若要將查詢規則套用至一或多個特定的結果來源,請選取 [這些來源之一]*。根據預設,系統會選取您在步驟 1 中指定的結果來源。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.

  5. 若與某類別相關,請限制只針對特定類別執行此規則:例如,當您受管理導覽字詞組的字詞包含在查詢中時,才會觸發查詢規則。在 [內容]**** 區段中的 [針對下列類別執行查詢]**** 底下,選取下列其中一項: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. In the Import from Taxonomy dialog box, select a term that when you include it in a query will cause the query rule to fire, and then click Save.

    • 若要移除任何限制,請按一下 [所有類別]*To remove any restrictions, click *All categories.

  6. 若與某使用者區段相關,請限制只按特定使用者區段執行規則。在 [內容]**** 區段中的 [按下列使用者區段執行查詢]**** 底下,選取下列其中一項: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. In the Import from Taxonomy dialog box, select a term that when you include it in a query will cause the query rule to fire, and then click Save.

    • 若要移除任何限制,請按一下 [所有使用者區段]*To remove any restrictions, click *All user segments.

  7. 指定查詢何時會觸發此規則。您可以指定不只一項條件;這樣在符合任何一項條件時,就會觸發規則。在 [查詢條件]**** 區段中,執行下列其中一項操作︰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:

    • 選取 [會觸發規則的條件概觀] 中所列的其中一個條件。Select one of the conditions listed in Overview of conditions that make a query rule fire.

    • 新增其他條件。Add an alternate condition.

    • 按一下 [移除條件]*,即可設定只要使用者在您建立該規則的層級輸入查詢,皆會觸發此查詢規則。例如,如果您針對網站集合建立此規則,則按一下 [移除條件]* 就會使得使用者於網站集合的任何搜尋方塊中輸入查詢時,皆會觸發此規則。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.

  8. 指定查詢規則觸發時要採取的動作。在 [動作]**** 區段中,您可以:Specify the action to take when the query rule fires. In the Actions section you can:

    • 將個別結果升階,使其顯示在搜尋結果的頂端。您可以新增多項個別的升階結果。當有多項升階的結果時,您可以指定相對的排名。若要升階,請按一下 [新增升階的結果]**** (在 SharePoint 2010 產品中這稱為「首選」)。在 [新增升階的結果]**** 對話方塊中為升階的結果命名,然後輸入待升階結果的 URL。您可以定義使 URL 呈現為橫幅,而不是超連結。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 SharePointAll_1st_14 this was called Best Bets). In the Add Promoted Result dialog box give the promoted result a name and enter the URL of the result to promote. 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.

  9. 若要在特定時間期間啟用查詢規則,請按一下 [發佈]*,然後指定期間。To make the query rule active during a particular time period, click *Publishing, and then specify the period.

會觸發規則的條件概觀Overview of conditions that make a query rule fire

查詢條件Query condition 描述Description 設定Configuration 範例Example
查詢完全符合關鍵字Query Matches Keyword Exactly
若您希望當查詢完全符合您指定的字詞或片語時觸發查詢規則,請選取此選項。Select this option if you want the query rule to fire when a query exactly matches a word or phrase that you specify.
在 [查詢完全符合這些片語之一]**** 文字方塊中,輸入一或多個片語,並以分號隔開。In the Query exactly matches one of these phrases text box, type one or more phrases separated by semicolons.
您在 [查詢包含這些片語之一]**** 文字方塊中輸入 "picture; pic"。當使用者在搜尋方塊中輸入 "picture" 或 "pic" 時,會觸發搜尋規則。若使用者輸入 "pictures" 或 "sunny picture" 時,則不會觸發規則。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."
查詢包含動作字詞Query Contains Action Term
若您希望當查詢包含指出使用者要進行之動作的字詞時,會觸發查詢規則,請選取此選項。字詞必須位於查詢的開頭或結尾。Select this option if you want the query rule to fire when a query contains a term that indicates something that the user wants to do. The term must be at the beginning or end of the query.
動作字詞可以是您輸入的數個詞句之一。或者也可以是字典 (可以匯入字詞) 中的項目。 The action term can be one of several phrases that you enter. Alternatively the action term can be an entry in a dictionary, where you import the term.
您在 [動作字詞是這些文句之一]**** 文字方塊中輸入 "download"。當使用者在搜尋方塊中輸入 "download Contoso Electronics datasheet" 時,使用者可能不是要搜尋含有 "download"、"Contoso"、"Electronics" 及 "datasheet" 字詞的文件。使用者其實是要嘗試下載 Contoso Electronics 資料工作表。當使用者在搜尋方塊中輸入 "download Contoso Electronics datasheet" 時,會觸發搜尋規則,並且僅會將 "Contoso"、"Electronics" 及 "datasheet" 傳送至搜尋索引。You type the word "download" in the Action term is one of these phrases text box. When a user types "download Contoso Electronics datasheet" in a search box, the user is probably not searching for a document that contains the words "download," "Contoso," "Electronics," and "datasheet." Instead, the user is probably trying to download a Contoso Electronics datasheet. When a user types "download Contoso Electronics datasheet" in a search box, the query rule fires, and only the words "Contoso," "Electronics," and "datasheet" are passed to the search index.
查詢完全符合字典Query Matches Dictionary Exactly
若您希望當查詢完全符合字典項目時觸發查詢規則,請選取此選項。Select this option if you want the query rule to fire when the query exactly matches a dictionary entry.
[查詢包含此字典中的一個項目] 功能表選取字典。若要指定其他字典,請按一下 [從分類匯入]*,然後在 [從分類匯入]* 對話方塊中,從字詞組選取字詞,再按一下 [儲存]*From the* Query contains an entry in this dictionary menu, select a dictionary. To specify a different dictionary, click Import from taxonomy, and then from the Import from taxonomy dialog box, select a term from a term set, and then click Save.
使用者在搜尋方塊中輸入的文字符合預先設定之「人員姓名」字典中的項目。A word that a user types in a search box matches an entry in the pre-configured People Names dictionary.
經常在來源查詢Query More Common in Source
若要在使用者於您指定的其他結果來源經常發出查詢時引發查詢規則,請選取此選項。Select this option if you want the query rule to fire if the query was frequently issued by users on a different result source that you specify.
在 [查詢比較可能會用於這個來源]**** 功能表中,選取結果來源。In the Query is more likely to be used in this source menu, select a result source.
在 [查詢比較可能會用於這個來源]**** 功能表中,選取了 [本機視訊結果]*。若使用者在搜尋方塊中輸入 "training",且該字詞經常輸入在視訊垂直中的輸入方塊,即會觸發查詢規則。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.
常點選的結果類型Result Type Commonly Clicked
若您希望當其他使用者在輸入相同查詢後,經常點選特定結果類型時觸發查詢規則,請選取此選項。Select this option if you want the query rule to fire if other users frequently clicked a particular result type after they typed the same query.
在 [常點選的結果與結果類型相符]**** 功能表中選取結果類型。In the Commonly clicked results match result type menu, select a result type.
在 [常點選的結果與結果類型相符]**** 方塊中,選取 [SharePoint 微型部落格文章]*。如果使用者經常在搜尋結果中點選微型部落格文章,則建議您在 [動作]* 區段中將最新的微型部落格文章設定為第一個升級的結果,而將次新的微型部落格文章設定為第二個升級的結果。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.
進階查詢文字比對Advanced Query Text Match
若您希望使用會觸發查詢規則的規則運算式、片語或字典項目,請選取此選項。Select this option if you want to use a regular expression, a phrase, or a dictionary entry that will cause the query rule to fire.
若要比對某特定格式的所有電話號碼,可在 [查詢符合此規則運算式]**** 方塊中指定規則運算式。To match all phone numbers that are in a certain format, you specify a regular expression in the Query matches this regular expression box.
若要比對格式為 nnn-nnn-nnnn 的所有電話號碼,您可以指定規則運算式為 "(?(\d{3}))?-?(\d{3})-(\d{4})"。To match all phone numbers that are in the format nnn-nnn-nnnn, you specify the regular expression "(?(\d{3}))?-?(\d{3})-(\d{4})".

建立及顯示結果區塊Create and display a result block

結果區塊是顯示為一個群組的多筆搜尋結果。例如,針對含有「Fabrikam 銷售報告」的查詢,查詢規則可使用分類字典,將「Fabrikam」識別為客戶,然後顯示來自您的客戶關係管理 (CRM) 系統,且與「Fabrikam」有關的結果區塊。A result block is several search results that are displayed as a group. For example, for a query that contains "Fabrikam sales report", a query rule might use a taxonomy dictionary to recognize "Fabrikam" as a customer, and then display a result block with pertinent results about Fabrikam from your customer relationship management (CRM) system.

就如同您可將特定的結果升階一樣,也可在指定的查詢條件適用時將結果區塊升階。In the same manner as you can promote a specific result, you can promote a result block when a specified query condition applies.

當您設定查詢以執行結果區塊時,可以使用「查詢變數」。查詢變數是您指定查詢時,為不知道的值所保留的預留位置。不過在執行查詢後,當系統將查詢傳送至索引時,便可得知及使用這項資訊。例如,{User.Name} 代表鍵入查詢之使用者的顯示名稱;或是 {searchBoxQuery} 代表使用者在搜尋方塊中鍵入的查詢。如需可用的查詢變數清單,請參考 Query variables in SharePoint ServerWhen you configure the query to run for a result block, you can use query variables. Query variables are placeholders for values that you don't know when you specify the query. However, when the query is run, this information is known and can be used when the system sends the query to the index. Examples are {User.Name}, which represents the display name of the user who typed the query, or {searchBoxQuery}, which represents the query that a user typed in a search box. See Query variables in SharePoint Server for a list of available query variables.

若您不熟悉查詢變數,可以使用「查詢建立器」來設定查詢 (請參閱下列程序中的步驟 3)。If you're not familiar with query variables, you can use the Query Builder to configure the query (see step 3 in the following procedure).

建立結果區塊To create a result block

  1. 在先前程序的步驟 8 中,在 [新增查詢規則]**** 頁面,按一下 [動作]**** 區段中的 [新增結果區塊]*In step 8 of the previous procedure, on the *Add Query Rule page, in the Actions section, click Add Result Block.

  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:.

    • 從 [選取查詢]**** 區段中的下拉式清單內選取結果來源,以選取要搜尋的內容。Select which content to search by selecting a result source from the drop-down list in the Select a query section.

    • 在 [查詢文字]**** 方塊中指定查詢。您可從 [關鍵字篩選]**** 下拉式清單中選取預先定義的查詢變數,然後按一下 [新增關鍵字篩選]*,將其新增到 [查詢文字]* 方塊中。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.

    • 若與某搜尋結構描述相關,請使用屬性篩選,以查詢搜尋結構描述中設為可查詢之 Managed 屬性的內容。您可以從 [屬性篩選]**** 下拉式清單中選取 Managed 屬性。按一下 [新增屬性篩選]*,將篩選新增到查詢中。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.

    • 按一下 [測試查詢]**** 來加以測試。Test the query by clicking Test query.

  4. 指定要如何排序結果區塊中的搜尋結果。搜尋結果的排序會區分大小寫。在 [排序]**** 索引標籤上、[排序依據]**** 下拉式清單中,選取 Managed 屬性,然後選取 [遞減]**** 或 [遞增]*。該清單只會包含搜尋結構描述中已設定為可排序的 Managed 屬性。您也可以按順位排序。若要新增更多排序層級,請按一下 [新增排序層級]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:

  5. 若您選擇按順位排序,也可以:If you chose to sort by rank, you can optionally:

    • 選取要使用哪個模型來排名搜尋結果 (此為選用選項)。請使用 [排名模型]**** 下拉式清單。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

  6. 在 [測試]**** 索引標籤中,預覽「內容搜尋網頁組件」所執行的最終查詢。預覽會以將動態變數取代為目前值的原始查詢範本為依據,因此其他查詢變更就可能必須以查詢規則的形式來進行。按一下 [顯示更多]**** 以顯示其他資訊。Preview the final query that will be run by the Content Search Web Part, on the TEST tab. The preview is based on the original query template where dynamic variables are substituted with current values. Other changes to the query may have to be made as part of query rules. Click Show more to display additional information.

    • [查詢範本]**** 方塊會顯示套用到查詢的查詢範本內容。The Query template box shows the content of the query template that is applied to the query.

    • [查詢範本變數]**** 區段會顯示查詢將套用的查詢變數,以及套用至目前頁面的變數值。您可輸入其他值來測試這些值在查詢方面的效果。按一下 [測試查詢]**** 按鈕預覽搜尋結果。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.

  7. 定義應該將此結果區塊套用到到哪個結果來源。使用 [查詢]**** 區段中的 [搜尋此來源]**** 下拉式清單。Define which result source this result block should be applied to. Use the Search this Source drop-down list in the Query section.

  8. 定義結果區塊中要顯示多少結果。使用 [查詢]**** 區段中的 [項目]**** 下拉式清單。Define how many results ro show in the result block. Use the In the Items drop-down list, in the Query section.

  9. 結果區塊只會顯示您在先前步驟中所指定的搜尋結果數目。但您可以在結果區塊底部新增 [顯示更多]**** 連結,以顯示結果區塊的所有搜尋結果。若要新增 [顯示更多]**** 連結,請展開 [設定]**** 區段、選取 [下列 URL 可有「更多」連結]***,然後鍵入 URL。您可以在 URL 中使用查詢變數,例如 *http://www.<site>/search/results.aspx?k={subjectTerms}The result block will only display the number of search results that you specified in the previous step. However, you can add a SHOW MORE link at the bottom of the result block that will show all search results for the result block. To add a SHOW MORE link, expand the Settings section, select "More" link goes to the following URL, and then type a URL. You can use query variables in this URL — for example, http://www./search/results.aspx?k={subjectTerms}.

  10. 略過 [路由]**** 區段。Skip the Routing section.

  11. 按一下 [確定]*Click *OK.

變更排名的搜尋結果Change ranked search results

排名模型會計算搜尋結果的排名順序。您可以升級或降級搜尋結果中的項目,以變更此排名。例如,針對包含 "download toolbox" 的查詢,可以建立能夠辨識字詞 "download" 為動作字詞的查詢規則,並變更排名的搜尋結果,以升級您內部網路中特定下載網站的 URL。您也可以根據一些變數,例如副檔名或特定關鍵字,動態變更搜尋結果排序。以變更查詢的方式變更排名的搜尋結果之優點為,結果是經過安全性調整且可精簡。此外,若不再提供文件時,甚至不會顯示搜尋結果。The ranking model calculates a ranking order of search results. You can change this ranking by promoting or demoting items within the search results. For example, for a query that contains "download toolbox," you can create a query rule that recognizes the word "download" as an action term, and change the ranked search results to promote a URL of a particular download site on your intranet. You can also change the sorting order of the search results dynamically, based on several variables such as file name extension or specific keywords. Changing ranked search results by changing the query has the advantage that the results are security trimmed and refinable. Moreover, the search results will not appear if the document is no longer available.

透過變更查詢來變更排名的搜尋結果To change ranked search results by changing the query

  1. 在程序建立查詢規則的步驟 8 中,在 [新增查詢規則]**** 頁面上的 [動作]**** 區段中,按一下 [變更查詢以變更排名的結果]*。[建立您的查詢]* 對話方塊隨即出現。From step 8 of the procedure Create a query rule, on the Add Query Rule page, in the Actions section, click Change ranked results by changing the query. The Build Your Query dialog box appears.

  2. 在 [基本]**** 索引標籤上執行下列動作:On the BASIC tab do the following:.

    • 從 [選取查詢]**** 區段中的下拉式清單內選取結果來源,以選取要搜尋的內容。Select which content to search by selecting a result source from the drop-down list in the Select a query section.

    • 在 [查詢文字]**** 方塊中指定查詢。您可從 [關鍵字篩選]**** 下拉式清單中選取預先定義的查詢變數,然後按一下 [新增關鍵字篩選]*,將其新增到 [查詢文字]* 方塊中。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.

    • 若與某搜尋結構描述相關,請使用屬性篩選,以查詢搜尋結構描述中設為可查詢之 Managed 屬性的內容。您可以從 [屬性篩選]**** 下拉式清單中選取 Managed 屬性。按一下 [新增屬性篩選]*,將篩選新增到查詢中。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.

    • 按一下 [測試查詢]**** 來加以測試。Test the query by clicking Test query.

  3. 指定要如何排序結果區塊中的搜尋結果。搜尋結果的排序會區分大小寫。在 [排序]**** 索引標籤上、[排序依據]**** 下拉式清單中,選取 Managed 屬性,然後選取 [遞減]**** 或 [遞增]*。該清單只會包含搜尋結構描述中已設定為可排序的 Managed 屬性。您也可以按順位排序。若要新增更多排序層級,請按一下 [新增排序層級]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:

  4. 若您選擇按順位排序,也可以:If you chose to sort by rank, you can optionally:

    • 選取要使用哪個模型來排名搜尋結果 (此為選用選項)。請使用 [排名模型]**** 下拉式清單。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

  5. 在 [測試]**** 索引標籤中,預覽「內容搜尋網頁組件」所執行的最終查詢。預覽會以將動態變數取代為目前值的原始查詢範本為依據,因此其他查詢變更就可能必須以查詢規則的形式來進行。按一下 [顯示更多]**** 以顯示其他資訊。Preview the final query that will be run by the Content Search Web Part, on the TEST tab. The preview is based on the original query template where dynamic variables are substituted with current values. Other changes to the query may have to be made as part of query rules. Click Show more to display additional information.

    • [查詢範本]**** 方塊會顯示套用到查詢的查詢範本內容。The Query template box shows the content of the query template that is applied to the query.

    • [查詢範本變數]**** 區段會顯示查詢將套用的查詢變數,以及套用至目前頁面的變數值。您可輸入其他值來測試這些值在查詢方面的效果。按一下 [測試查詢]**** 按鈕預覽搜尋結果。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.

停用查詢規則Make a query rule inactive

取用 Search Service 應用程式之 Web 應用程式中的網站集合及網站會繼承在 Search Service 應用程式層級建立的查詢規則。同樣地,網站集合中的網站也會繼承在網站集合層級建立的查詢規則。若不要將繼承而來的查詢規則套用至網站,可針對網站將查詢規則設為停用。Query rules that are created at the Search service application level are inherited by site collections and sites that are in web applications that consume the Search service application. Similarly, query rules that are created at the site collection level are inherited by sites in the site collection. If you don't want a query rule to apply to a site that inherits it, you can set the query rule as inactive for the site.

停用網站的查詢規則To make a query rule inactive on a site

  1. 請確認執行此程序的使用者帳戶為網站擁有人群組的成員。Verify that the user account that performs this procedure is a member of the Owners group for the site.

  2. 在網站集合的 [設定]**** 功能表中,按一下 [網站設定]*In the site collection, in the *Settings menu, click Site Settings.

  3. 在 [網站設定]**** 頁面上,按一下 [搜尋]**** 區段中的 [查詢規則]*On the *Site Settings page, in the Search section, click Query Rules.

  4. 在「管理查詢規則」**** 頁面的 [選取結果來源]**** 功能表中,選取包含您要停用之查詢規則的結果來源。On the Manage Query Rules page, on the Select a Result Source menu, select the result source that contains the query rule that you want to make inactive.

  5. 在 [名稱]**** 欄中指向您要停用的查詢規則,按一下出現的箭頭,然後按一下 [變為已停用]*In the *Name column, point to the query rule that you want to make inactive, click the arrow that appears, and then click Make Inactive.

排名查詢規則Rank query rules

當啟用 Search Service 應用程式、網站集合或網站的多個查詢規則時,可以針對在該層級上執行的查詢觸發多個規則。根據預設,不會依照指定的順序觸發規則。您可以藉由將建立的查詢規則新增至查詢群組,以控制規則觸發的順序。若要執行此操作,請選取要新增至群組的規則,然後指定群組中的規則要觸發的順序。您也可以使群組中最低排名的查詢規則,即使受到觸發也不會被觸發。When multiple query rules are active for a Search service application, a site collection, or a site, more than one rule can fire for a query that is performed at that level. By default, the rules do not fire in a prescribed order. You can control the order in which the rules fire by adding the query rules that you create to query groups. To do this, you select rules to add to a group, and then you specify the order in which the rules in the group will fire if they are triggered. You can also prevent query rules that rank lowest in a group from firing even if they are triggered.

為網站集合排名查詢規則To rank query rules for a site collection

  1. 確認執行此程序的使用者帳戶為網站集合管理員。Verify that the user account that performs this procedure is a site collection administrator.

  2. 在網站集合的 [設定]**** 功能表中,按一下 [網站設定]*In the site collection, on the *Settings menu, click Site Settings.

  3. 在 [網站設定]**** 頁面上,按一下 [網站集合管理]**** 區段中的 [搜尋查詢規則]*On the *Site Settings page, in the Site Collection Administration section, click Search Query Rules.

  4. 在「管理查詢規則」**** 頁面的 [選取結果來源]**** 功能表中,選取包含您要加入群組之查詢規則的結果來源。On the Manage Query Rules page, on the Select a Result Source menu, select the result source that contains the query rules that you want to group.

  5. 針對您所建立且要新增至群組的每個查詢規則,指向規則,並選取核取方塊。For each query rule that you created that you want to add to a group, point to the rule and select the check box.

    注意

    您針對此網站集合建立的查詢規則會列在 [已針對此網站集合定義]**** 區段中。Query rules that you created for this site collection are listed in the Defined for this site collection section.

  6. 按一下 [順序選取規則]*Click *Order Selected Rules.

  7. 在 [順序選取規則]**** 對話方塊中,執行下列其中一項操作,然後按一下 [確定]* In the *Order Selected Rules dialog box, do either of the following, and then click OK:

    • 選取 [將規則移至具有此名稱的新群組]*,然後輸入群組名稱。Select *Move rules to new group with this name, and then type a name for the group.

    • 選取 [將規則移至現有群組]*,然後在下拉式清單中選取群組。Select *Move rules to existing group and select a group in the drop-down list.

  8. 在 [管理查詢規則]**** 頁面上,執行下列操作:On the Manage Query Rules page, do the following:

  9. 若要變更群組中規則的觸發順序,請變更規則的號碼順序。To change the order in which a rule in a group will fire if it is triggered, change the numeric order of the rule.

  10. 若要使群組中最低排名的查詢規則不會被觸發,請在要最後觸發的群組查詢規則的該列中,在 [動作]**** 欄中的 [繼續/停止]**** 下拉式清單中選取 [停止]*To prevent query rules that are ranked lowest in the group from firing, in the row for the group's query rule that should fire last, in the *Actions column, in the Continue/Stop drop-down list, select Stop.

另請參閱See also

概念Concepts

在 SharePoint Server 中規劃轉換查詢和順序結果Plan to transform queries and order results in SharePoint Server

SharePoint Server 中的搜尋結果排名概觀Overview of search result ranking in SharePoint Server

Query variables in SharePoint ServerQuery variables in SharePoint Server