在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,可用的方法有:数据库
-GetSearchRePortc#
-GetRollUpAnalyticsItemDataide
Search analytics data 被存储在名叫AnalyticsReportingStore的数据库中,GetSearchRePort方法是经过调用名为ar_procGetTopSearchReport的存储过程实现的,GetRollupAnalyticsItemData方法 是经过调用 ar_procGetAnalyticsItemData实现的
wordpress
GetSearchReport 有如下参数: 网站
reportType -int:报告的类型,1 表明 top queriesui
tenantId - GUID:SharePoint租户的ID。若是在SharePoint Farm安装时没有具体的设置,则能够设为空的Guid
google
siteId – guid : 网站集 id.若要获取包含网站集则设为空的GUIDspa
reportDate - DateTime:报告的时间code
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/