Add and configure the Recommended Items and Popular Items Web Part in SharePoint ServerAdd and configure the Recommended Items and Popular Items Web Part in SharePoint Server

摘要:了解如何在 SharePoint Server 2013 和 SharePoint Server 2016 中新增及設定建議項目和常用項目網頁組件。Summary: Learn how to add and configure the Recommended Items and Popular Items Web Part in SharePoint Server 2013 and SharePoint Server 2016.

變更的內容搜尋網頁組件顯示範本和使用 Windows PowerShell 來啟動 SharePoint Server 中的流量分析,此系列中前一篇文章說明如何變更記錄檢視流量事件 CSWP 及如何使用若要啟動流量分析 Microsoft PowerShell。The previous article in this series, Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server, explained how to change the CSWP to log the Views usage event, and how you can use Microsoft PowerShell to start Usage analytics.

注意

[!附註] 本系列中的範例是根據內部部署的 SharePoint Server 部署。The examples in this series are based on an on-premises SharePoint Server deployment.

瀏覽到您想要新增建議項目網頁組件 (RIWP) 的頁面。在 Contoso 案例中,我們要將 RIWP 新增到我們的目錄項目頁面。以下是具體做法:Navigate to the page where you want to add the Recommended Items Web Part (RIWP). In our Contoso scenario, we want to add the RIWP to our catalog item page. Here's how you do that:

  1. 選取 [設定] 功能表-->編輯頁面Select the Settings menu --> Edit page.

  2. 在您要新增網頁組件網頁組件區域,選取 [新增網頁組件In the Web Part Zone where you want to add the Web Part, select Add a Web Part.

  3. 在 [類別] 清單中選取 [搜尋導向內容In the Categories list, select Search-Driven Content.

  4. 在 [組件] 清單中,選取 [建議項目,然後按一下 [新增]In the Parts list, select Recommended Items, and then Add.

    在 Contoso 案例中,我們會在 CSWP 下方顯示 RIWP。In our Contoso scenario, we'll show the RIWP below the CSWP.

    RIWP added

關於 recommendedfor Managed 屬性About the recommendedfor managed property

在先前的部落格文章中,我們提到了「情況分析」用來指定該如何計算個別項目間建議數的 UsageAnalyticsId Managed 屬性 (請參閱 關於 UsageAnalyticsID managed 屬性)。此計算的結果會傳送給 recommendedfor Managed 屬性。RIWP 會使用 recommendedfor Managed 屬性來查詢建議。您在設定 RIWP 時不需要知道此 Managed 屬性。但若要了解 RIWP 中查詢的運作方式,請務必留意 recommendedfor Managed 屬性。In a previous blog article we told you about the UsageAnalyticsId managed property that is used by Usage analytics to specify how recommendations between individual items should be calculated (see About the UsageAnalyticsID managed property). The result of this calculation is sent to the recommendedfor managed property. The RIWP uses the recommendedfor managed property to query for recommendations. You don't have to know about this managed property when you configure the RIWP. But, to understand how the query in the RIWP works, it's important that you keep the recommendedfor managed property in mind.

在設定 RIWP 時,您應在項目詳細資料頁面 (會產生建議) 上加以設定。不知您是否還記得,在本系列先前的文章中,我們邀請了一些同事參與「您為何應該模擬 Views 使用事件的產生」。在此點擊派對中,您的同事會按下特定項目來產生建議。在 Contoso 案例中,我們會將 RIWP 新增到項目詳細資料頁面,在此頁面上您會知道您的同事點擊後所產生的建議。When you configure the RIWP, you should configure it on an item details page where recommendations are generated. Remember the previous article in this series, when we invited some coworkers to a "Why you should simulate the generation of Views usage events." At the click party, your coworkers click specific items so recommendations are generated. In our Contoso scenario, add the RIWP to an item details page where you know recommendations are generated through the clicking of your coworkers.

設定 RIWP 的步驟如下:Here are the steps to configure the RIWP:

  1. 選取 [設定] 功能表-->編輯頁面Select the Settings menu --> Edit page.

  2. 在 RIWP,選取 [網頁組件功能表 --> 編輯網頁組件In the RIWP, select the Web Part Menu --> Edit Web Part.

    Edit WP

  3. 在 [網頁組件] 工具窗格中,選取 [變更查詢]。這會開啟一個對話方塊。In the Web Part tool pane, select Change query. This opens a dialog box.

  4. 在 [建立您的查詢] 對話方塊中,選取下列項目:In the Build Your Query dialog box, select the following:

    • 取得針對性建議項目] 區段中選取的 token URL ,然後選取您想要取得建議之 URL 值。在 Contoso 案例中,我們想要取得建議從{URL。Token.2} (數字)In the Get recommended items for section, select A token from the URL and then select from which URL value that you want to get recommendations. In our Contoso scenario, we want to get recommendations from {URL.Token.2} (number).

    • Restrict 依據應用程式] 區段中選取 [指定 URL,,然後輸入您的目錄的 URL。In the Restrict by app section, select Specify a URL, and then enter the URL of your catalog.

      TIWP query

您也許會想「好,這還算簡單,但實際上表示什麼?」要了解這點可能有點困難。接下來讓我們詳細探討。You might be thinking "OK, that was easy, but what does it actually mean?" Understanding this can be is a bit difficult. Let's take a closer look.

  • 從 URL 的權杖表示我們想要取得建議在 URL 中所使用的值。A token from the URL means that we want to obtain recommendations for a value that is used in the URL.

  • {URL。Token.2}查詢變數,表示計算從右至左的 URL 中的第二個值。例如,在 URL 中http://www.contoso.com/computers/desktops/5637145799/5637146352、 變數{URLToken.2}代表值5637145799的查詢。請記得當我們我們發佈網站連線至目錄 (請參閱階段 5: 將您的發佈網站連線至 SharePoint Server 中目錄),我們指定群組編號的值應作為 url 的最後一個值的第二個我們目錄項目頁面。這表示查詢變數{URL。Token.2}代表群組編號的值。此外,我們對應變更 UsageAnalyticsID managed 屬性的對應,讓流量分析計算會根據群組編號{URL.Token.2} is a query variable that represents the second value in the URL as counted from right to left. For example, in the URL http://www.contoso.com/computers/desktops/5637145799/5637146352 , the query variable {URLToken.2} represents the value 5637145799 . Remember when we connected our publishing site to the catalog (see Stage 5: Connect your publishing site to a catalog in SharePoint Server), we specified that the value of Group Number should be used as the second to last value in the URL of our catalog item page. That means the query variable {URL.Token.2} represents the value of Group Number . Also, we mapped Change the mapping of the UsageAnalyticsID managed property so the Usage analytics calculation would be based on Group Number .

  • 指定 URL 表示,我們想要指定從哪個網站取得建議 (在此案例中是我們的「製作」網站)。Specify a URL means that we want to specify from which site we get recommendations, in this case our Authoring site.

    但從這些設定,它不是純哪些 managed 的屬性用於在查詢中。因此,若要檢視之查詢的詳細資訊,請選取測試。網頁組件所發出的查詢會顯示在 [查詢文字方塊] 區段中。But from these settings, it is not clear which managed property is used in the query. So, to view more information about the query, select TEST. The query that is issued by the Web Part is shown in the Query text section.

    Query text

若將其分解,可得知下列項目:If we break this down, we get the following:

  • recommendedfor 是在此查詢中所使用的 Managed 屬性。recommendedfor is the managed property that is used in the query.

  • 冒號「:」表示「包含」。The colon : means "contains."

  • 5637145799是值的查詢變數 {URL。Token.2},也就是群組編號值。5637145799 is the value of the query variable {URL.Token.2}, which is a Group Number value.

  • path:"http://ib-perf-8/sites/catalog" 是「製作」網站的 URL。path:"http://ib-perf-8/sites/catalog" is the URL to our Authoring site.

  • (IsDocument:"True" OR contentclass:"STS_ListItem") 將搜尋結果的範圍縮窄到僅限文件或清單項目。(IsDocument:"True" OR contentclass:"STS_ListItem") narrows the search result down to only documents or list items.

    若我們將這些資訊加以整合,就可以了解查詢表示下列事項:If we put all this information together, we can understand that the query means the following:

    製作網站的 URL ,搜尋文件或清單項目recommendedfor managed 的屬性的值包含目前使用做為第二個值中的 URL,計算從右至左的值。From the URL of the Authoring site , search for document or list items where the value of the managed property recommendedfor contains the value that is currently used as the second value in the URL, counting from right to left.

    因此,現在我們知道查詢所代表的意義。但是我們不完全完成的設定。在 [搜尋結果預覽] 區段中,我們可以看到該會顯示在 [產品] 群組中的所有項目,例如所有SV 鍵盤 E10 (請注意其所有具有相同值的 URL 中的群組編號)。So, now we know what the query means. But we're not completely done with the configuration. In the SEARCH RESULT PREVIEW section, we can see that all items in a product group are displayed, for example all SV Keyboard E10 (notice that they all have the same value for Group Number in the URL).

    Recommended Items

    系統會顯示產品群組中的所有項目,是因為情況分析計算是在群組層級執行。請記住,我們在 Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server 中已將 UsageAnalyticsId 對應到 aws_ProductCatalogGroupNumber 。但每個產品群組我們只想要顯示一個項目。幸好,我們可以將搜尋結果分組來實現這點。All items in the product group are shown because the Usage analytics calculation is performed on the group level. Remember, in Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server, we mapped UsageAnalyticsId to aws_ProductCatalogGroupNumber . But we only want to display one item per product group. Luckily, we can do this by grouping search results.

    若要將搜尋結果分組,請執行下列動作:To group search results, do the following:

  1. 選取 [精簡器->顯示更多Select REFINERS --> Show more.

    Show More

  2. 從 [群組依據] 功能表選取 [顯示所有內容]。From the Group by menu, select Show all properties.

    Show all properties

  3. 我們想要顯示每個產品群組只有一個項目。因此,我們先選取ProductCatalogGroupNumberOWSTEXT群組編號的 managed 屬性)。我們只想要顯示每個群組的某個項目。因此我們將值保留中那里顯示的結果1We want to show only one item per product group. Therefore, we select ProductCatalogGroupNumberOWSTEXT (the managed property of Group Number ). We only want to display one item per group. So we leave the value in Show there results as 1.

    Group by Group Number

搜尋結果預覽,我們現在可以看到該只有一個項目群組會顯示每項產品。In the SEARCH RESULT PREVIEW, we can now see that only one item per product group is shown.

 ![One Item Per Groeu](../media/OTCSP_OneItemPerGroeu.png)
  1. 選取[確定]以儲存變更。Select OK to save the changes.

  2. 在 [網頁組件] 工具窗格的 [顯示] 欄位中的項目數中輸入您想要顯示在網頁組件中的項目數。In the Web Part tool pane, in the Number of items to show field, enter how many items that you want to display in the Web Part.

    Number of Items to Show

  3. 選取 [確定] 並儲存] 頁面。Select OK, and save the page.

    雖然不太好看,但現在目錄項目頁面上會顯示很好的建議。Even though it doesn't look good, good recommendations are now displayed on our catalog item page.

    Recs shown

如同您不要使用內容搜尋網頁組件 (CSWP),您會使用來控制如何內容應該顯示在 RIWP 顯示範本。階段 11: 上傳並套用至 SharePoint Server 的內容搜尋網頁組件的顯示範本說明如何上傳並套用至內容搜尋網頁組件的顯示範本。您可以執行相同的 RIWP。但 RIWP 所使用的顯示範本包含重要記錄檔的兩個流量事件的程式碼:顯示建議建議按下Just as you do with the Content Search Web Part (CSWP), you use display templates to control how content should be displayed in a RIWP. Stage 11: Upload and apply display templates to the Content Search Web Part in SharePoint Server explains how to upload and apply display templates to the Content Search Web Part. You can do the same for the RIWP. But the display template that is used by the RIWP contains important code that logs the two usage events: Recommendation Displayed and Recommendation Clicked .

簡介建議與 SharePoint Server 中的熱門項目中我們說過關於 SharePoint Server 中的三個預設流量事件。顯示建議建議按下的流量事件可用來記錄您的網站上的內容與之互動訪客具有方式的統計資料。當項目顯示為建議時,會記錄中顯示建議使用事件。當項目上按一下 [顯示為建議時,會記錄建議按下的使用事件。我們將為您示範如何檢視這些統計資料更新的文章。In An introduction to recommendations and popular items in SharePoint Server we told you about the three default usage events in SharePoint Server. The usage events Recommendation Displayed and Recommendation Clicked are used to record statistics of how visitors have interacted with the content on your website. When an item is displayed as a recommendation, a Recommendation Displayed usage event is recorded. When an item is clicked on when it is displayed as a recommendation, a Recommendation Clicked usage event is recorded. We'll show you how you can view these statistics in a later article.

變更內容搜尋網頁組件的顯示範本和使用 Windows PowerShell 啟動流量分析 SharePoint Server 中的,我們已變更記錄檢視使用事件的 CSWP 顯示範本。顯示建議建議點選流量事件的記錄是在 RIWP 中執行。RIWP 所使用的預設顯示範本是Item_RecommendationsClickLogging 。此顯示範本包含兩個函數LogRecsViewToEventStoreLogRecsClickToEventStore 。這兩個函數登建議顯示建議點選流量事件。In Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server, we changed the CSWP display template to log the Views usage event. The logging of the Recommendation Displayed and Recommendation Clicked usage events are performed in the RIWP. The default display template that is used by the RIWP is Item_RecommendationsClickLogging . This display template contains the two functions LogRecsViewToEventStore and LogRecsClickToEventStore . These two functions log the Recommendation Displayed and Recommendation Clicked usage events.

Log Recs View

Log Recs Click

變更 RIWP 顯示範本時,請複製 Item_RecommendationsClickLogging 檔案、變更複製的版本,並將其套用到您的 RIWP。如此一來,您就不需要擔心要如何以新增 CSWP 程式碼相同的方式,來新增 RIWP 程式碼。When you change your RIWP display template, you should copy the Item_RecommendationsClickLogging file, change the copied version, and apply it to your RIWP. That way, you don't have to worry about how to add code in the same manner that we did for the CSWP.

將變更的顯示範本套用到 RIWP 後,建議的項目就會妥善顯示。After applying the changed display template to the RIWP, the recommended items are displayed nicely.

Recs display template applied

您可以顯示最常用,也就是最檢視項目在目錄內將常用的項目網頁組件 (PIWP) 新增至類別頁面。請務必了解當您新增 PIWP 您目錄] 頁面上,將會自動 PIWP 顯示最檢視項目內每個類別。例如,如果訪客檢視 [照相機] 類別,PIWP 將顯示 [照相機] 類別中的最檢視項目。如果訪客檢視攝影機類別,PIWP 會顯示最檢視之項目的攝影機類別中。You can display the most popular, that is, the most viewed items within your catalog by adding a Popular Items Web Part (PIWP) to your category page. It's important to understand that when you add a PIWP to your catalog page, the PIWP will automatically show the most viewed items within each category . For example, if a visitor is viewing the Cameras category, the PIWP will show the most viewed items within the Cameras category. If a visitor is viewing the Camcorders category, the PIWP will show the most viewed items within the Camcorders category.

若要新增 PIWP,請瀏覽到您想要新增 PIWP 的頁面。在 Contoso 案例中,我們會將 PIWP 新增到我們的類別頁面。請執行下列動作:To add a PIWP, navigate to the page where you want to add the PIWP. In our Contoso scenario, we'll add a PIWP to our category page. Do the following:

  1. 選取 [設定] 功能表-->編輯頁面Select the Settings menu --> Edit page.

  2. 在您要新增網頁組件網頁組件區域,選取 [新增網頁組件In the Web Part Zone where you want to add the Web Part, select Add a Web Part.

  3. 在 [類別] 清單中選取 [搜尋導向內容In the Categories list, select Search-Driven Content.

  4. 在 [組件] 清單中,選取 [常用項目,然後按一下 [新增]In the Parts list, select Popular Items, and then Add.

在 Contoso 案例中,我們會在 CSWP 上方顯示 PIWP。In our Contoso scenario, we'll show the PIWP above the CSWP.

Popular items added

  1. 選取 [設定] 功能表-->編輯頁面Select the Settings menu --> Edit page.

  2. 在 PIWP,選取 [網頁組件功能表 --> 編輯網頁組件In the PIWP, select the Web Part Menu --> Edit Web Part.

    Edit PIWP

  3. 在 [網頁組件] 工具窗格中,選取 [變更查詢]。如此會開啟一個對話方塊。In the Web Part tool pane, select Change query. This will open a dialog box.

  4. Restrict 依據應用程式] 區段中選取 [指定 URL並輸入製作網站的 URL。In the Restrict by app section, select Specify a URL and enter the URL of your Authoring site.

  5. [依 Restrict標籤] 區段中選取 [ Restrict 由目前和子導覽字詞In the Restrict by tag section, select Restrict by current and child navigation terms.

    在 [搜尋結果預覽] 區段中未不顯示任何結果。什麼?No results are displayed in the SEARCH RESULT PREVIEW section. What's going on?

    No Popular Results 2

    如需關於 PIWP 發出查詢的詳細資訊,請選取 [測試。在 [測試] 索引標籤上,可以看到查詢文字To see more about the query that the PIWP issues, select TEST. On the TEST tab we can see the Query text.

    PIWP Query Text

查詢文字表示下列事項:The query text means the following:

  • path:"http://ib-perf-8/sites/catalog" 是「製作」網站的 URL。path:"http://ib-perf-8/sites/catalog" is the URL to our Authoring site.

  • owstaxIdMetadataAllTagsInfo 是在此查詢中所使用的 Managed 屬性。owstaxIdMetadataAllTagsInfo is the managed property that is used in the query.

  • 冒號「:」表示「包含」。The colon : means "contains."

  • 91eb9f0d-3e5a-41a8-8487-78dfe234ca7c 會將目前類別的 GUID。在此範例會將目前類別是照相機91eb9f0d-3e5a-41a8-8487-78dfe234ca7c is the GUID of the current category. In this example the current category is Cameras .

  • (IsDocument:"True" OR contentclass:"STS_ListItem") 將搜尋結果的範圍縮窄到僅限文件或清單項目。(IsDocument:"True" OR contentclass:"STS_ListItem") narrows the search result down to only documents or list items.

    若我們將這些資訊加以整合,就可以了解查詢表示下列事項:If we put this information together, we can understand that the query means the following:

    製作網站的 URL ,搜尋文件或清單項目所在的 managed 的屬性owstaxIdMetadataAllTagsInfo值包含目前導覽類別或任何目前的子項目 GUID導覽。From the URL of the Authoring site , search for document or list items where the value of the managed property owstaxIdMetadataAllTagsInfo contains the GUID of the current navigation category or any of the children of the current navigation.

    我們可以在此查詢文字中看到的其中一項重要資訊,是 PIWP 會在查詢中使用 owstaxIdMetadataAllTagsInfo Managed 屬性。您無法在 PIWP 中將查詢變更為使用其他 Managed 屬性。這表示若希望查詢在 PIWP 中能正常運作,必須將 owstaxIdMetadataAllTagsInfo Managed 屬性包含在用以驅動受管理導覽的 Managed 屬性值中 (如需詳細資訊,請參閱 階段 8: 將類別頁面和目錄項目頁面指派給 SharePoint Server 中的字詞)。在 Contoso 案例中,驅動受管理導覽的 Managed 屬性是 owstaxIdProductCatalogItemCategory 。因此,我們需要將 owstaxIdProductCatalogItemCategory 的編目屬性對應到 owstaxIdMetadataAllTagsInfo Managed 屬性。An important piece of information that we can see in the query text is that the PIWP uses the owstaxIdMetadataAllTagsInfo managed property in its query. You can't change the query in the PIWP to use another managed property. That means that for the query in the PIWP to work correctly, the owstaxIdMetadataAllTagsInfo managed property has to include the value of the managed property that we use to drive managed navigation (for more information, see Stage 8: Assign a category page and a catalog item page to a term in SharePoint Server. In our Contoso scenario, the managed property that drives managed navigation is owstaxIdProductCatalogItemCategory . So, what we have to do is to map the crawled property of owstaxIdProductCatalogItemCategory to the owstaxIdMetadataAllTagsInfo managed property.

    Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server 說明了如何將編目屬性對應到 Managed 屬性。Change the Content Search Web Part display template and use Windows PowerShell to start Usage analytics in SharePoint Server explains how to map a crawled property to a managed property.

    重要

    [!重要事項] 您需要在製作網站上進行對應。You have to do the mapping on the authoring site.

    在 Contoso 案例中,正確對應的 owstaxIdMetadataAllTagsInfo 屬性如下所示:In our Contoso scenario, the correctly mapped owstaxIdMetadataAllTagsInfo property looks as follows:

    New Mapping

    您變更屬性的對應後,必須開始完整編目,如階段 4: 設定搜尋並啟用在 SharePoint Server 中的目錄內容的編目中所述。After you've changed the mapping of the property, you have to start a full crawl, as explained in Stage 4: Set up search and enable the crawling of your catalog content in SharePoint Server.

    您無法在查詢文字中看到一件很重要的事,就是搜尋結果的排序方式。PIWP 會針對 ViewsRecent Managed 屬性,以遞減順序來排序搜尋結果。根據預設, ViewsRecent Managed 屬性會包含過去 14 天內該項目的檢視次數。本系列中稍後我們會說明如何變更此值 (例如變更為過去 7 天內)。這表示 PIWP 所發出的查詢會進行下列動作:There is one very important thing that you can't see in the query text, and that is how the search results are sorted. The PIWP sorts search results in a descending order on the ViewsRecent managed property. By default, the ViewsRecent managed property contains the number of views for an item within the last 14 days. Later in this series we'll explain how to change this, for example, to the past 7 days. This means that the query issued by the PIWP will do the following:

    製作網站的 URL中搜尋的 managed 的屬性owstaxIdMetadataAllTagsInfo值其中包含 [目前導覽] 類別中,或任何目前的子項目 GUID 的文件或清單項目導覽。排序搜尋結果以遞減順序的過去 14 天內的檢視From the URL of the authoring site , search for document or list items where the value of the managed property owstaxIdMetadataAllTagsInfo contains the GUID of the current navigation category, or any of the children of the current navigation. Sort the search results in descending order of views for the past 14 days .

    結束完整編目後,您會在網頁組件中看到搜尋結果。When the full crawl has finished, you'll see search result in the Web Part.

    Popular Items Returned

  1. 選取[確定]儲存變更,並儲存] 頁面。Select OK to save the changes, and save the page.

    Popular Items Displayed

    若要妥善顯示熱門項目,您可以套用顯示範本,就像您針 CSWP 所做的一樣。如需詳細資訊,請參閱<階段 11: 上傳並套用至 SharePoint Server 的內容搜尋網頁組件的顯示範本>。To display the popular items nicely, you can apply a display template in the same manner that you did with the CSWP. For more information, see Stage 11: Upload and apply display templates to the Content Search Web Part in SharePoint Server.

    若要檢查 PIWP 運作正常,前往 [照相機] 區段中。在此頁面上,會顯示 [照相機] 類別中的最檢視項目。To check that the PIWP is working correctly, go to the Cameras section. On this page, the most viewed items within the Cameras category are displayed.

    Popular items cameras

    當我們前往攝影機類別時,會顯示最檢視之項目的攝影機類別中。When we go to the Camcorders category, the most viewed items within the Camcorders category are displayed.

    Popular items camcorders

    PIWP 的運作方式符合預期。太好了!Our PIWP is working the way it should. Nice!

    那麼,現在您了解如何設定 RIWP 和 PIWP。當您執行這些工作時,必須以自己的帳戶登入。So now you know how to configure the RIWP and the PIWP. When you you perform these tasks, you should be logged in to your own account.

    Logged In User

在本系列中的下一篇文章,我們會說明若網站只有匿名使用者 (也就是未登入的使用者) 時,上述所有項目的運作方式。In the next article of this series, we'll explain how all this works if the website only has anonymous users, that is, users who are not logged in.

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

在具有匿名使用者在 SharePoint Server 中的網站上使用建議和常用項目Use recommendations and popular items on websites with anonymous users in SharePoint Server