在SharePoint2010中可以通過Microsoft.Office.Server.WebAnalytics.Reporting.AnalyticsReportFunction類獲得Web 分析報告,但是在SharePoint 2013中Web Analytics Service Application被併入了Search Service Application中,所以如果像在SharePoint2010中引入Microsoft.Office.Server.WebAnalytics.dll and Microsoft.Office.Server.WebAnalytics.UI.dll兩個類庫在2013中是無法獲得Web Analytics Report的,在SharPoint 2013中需要引入Microsoft.Office.Server.Search.dll,可用的方法有:
-GetSearchRePort
-GetRollUpAnalyticsItemData
Search analytics data 被存儲在名叫AnalyticsReportingStore的數據庫中,GetSearchRePort方法是通過調用名爲ar_procGetTopSearchReport的存儲過程實現的,GetRollupAnalyticsItemData方法 是通過調用 ar_procGetAnalyticsItemData實現的
GetSearchReport 有以下參數:
reportType -int:報告的類型,1 代表 top queries
tenantId - GUID:SharePoint租戶的ID。如果在SharePoint Farm安裝時沒有具體的設置,則可以設爲空的Guid
siteId – guid : 網站集 id.若要獲取包含網站集則設爲空的GUID
reportDate - DateTime:報告的時間
bDaily - bool: true 則返回RePortDate設置的當天的結果, false 則返回RePortDate所在整個月的結果
maxRows – uint : 搜索結果的最大條數
下面的例子展示瞭如何獲得某個月的Top 搜索關鍵詞
SPSecurity.RunWithElevatedPrivileges(delegate { // You can use SPContext.Current.Site.ID if you have HttpContext using (var site = new SPSite(siteId)) { var context = SPServiceContext.GetContext(site); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var topQueries = searchProxy.GetSearchReport(1, Guid.Empty, Guid.Empty, startDate, false, maxRows); foreach (var query in topQueries) { //process top search term } } });
GetRollupAnalyticsItemData 有如下參數:
eventType – int :事件類型 e.g. 1 代表 Site Usage Reports
tenantId – guid :和GetSearchReport中參數意義一樣
siteId – guid : 網站集ID
scopeId – guid : 子網站id, 如果需要返回整個網站集下的ID則設爲Guid.Empty
下面的代碼展示瞭如何獲取 the daily and monthly usage reports of Hits and Users count:
SPSecurity.RunWithElevatedPrivileges(delegate { // You can use SPContext.Current.Site.ID if you have HttpContext using (var site = new SPSite(siteId)) { var context = SPServiceContext.GetContext(site); var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; var usageData= searchProxy.GetRollupAnalyticsItemData(1,Guid.Empty,site.ID,Guid.Empty); usageData.GetHitCountForDay(date); usageData.GetHitCountForMonth(date); } });
原文鏈接:http://radutut.wordpress.com/2013/01/27/how-to-get-search-analytics-reports-programmatically-in-sharepoint-2013/