private static QuerySuggestionQuery[] SecurityTrimSearchSuggestions(QuerySuggestionQuery[] queries, SPWeb web, Guid sourceId, CultureInfo culture) { Dictionary <string, Query> keywordQueries = new Dictionary <string, Query>(); try { foreach (var suggestion in queries) { KeywordQuery q = new KeywordQuery(web) { QueryText = ReCleanTags.Replace(suggestion.Query, string.Empty), SourceId = sourceId, RowLimit = 1, EnableStemming = true, UserContextGroupID = web.ID.ToString(), Culture = culture, EnableQueryRules = true }; q.SelectProperties.Clear(); keywordQueries.Add(suggestion.Query, q); } SearchExecutor se = new SearchExecutor(); var results = se.ExecuteQueries(keywordQueries, true); List <QuerySuggestionQuery> securedQueries = new List <QuerySuggestionQuery>(queries); foreach (KeyValuePair <string, ResultTableCollection> result in results) { // No result tables if (result.Value.Count == 0) { RemoveResult(securedQueries, result); continue; } // All tables show empty results if (result.Value.All(resultTable => resultTable.RowCount == 0)) { RemoveResult(securedQueries, result); } } return(securedQueries.ToArray()); } finally { foreach (var query in keywordQueries) { query.Value.Dispose(); } } }