private string BuildTAQuery() { string query = string.Empty; string audienceGroups = string.Empty; try { SPSite site = new SPSite(SPContext.Current.Web.Url); SPServiceContext context = SPServiceContext.GetContext(site); SPUser currentUser = SPContext.Current.Web.CurrentUser; string loginName = currentUser.ToString().Split('|')[1]; AudienceManager audMgr = new AudienceManager(context); AudienceCollection audiences = audMgr.Audiences; for (int i = 0; i < audiences.Count; i++) { if (audiences[i].AudienceName != "All site users") { if (audiences[i].IsMember(loginName)) { //audienceGroups = audienceGroups + "," + audiences[i].AudienceID; //TargetAudience is the managed property name in the search schema query += "TargetAudience:\"" + audiences[i].AudienceID + "\" OR "; } } } query = query.Substring(0, query.LastIndexOf(" OR ")); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Content Search Ext Web Part", TraceSeverity.Medium, EventSeverity.Error), TraceSeverity.Medium, "Audience Build Failed: " + ex.Message, null); } return(query); }