public static void PopulateSynonyms(Dictionary <string, List <string> > synonymLookup) { SPSecurity.RunWithElevatedPrivileges( delegate { try { var ssaProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.Current); if (ssaProxy.FASTAdminProxy != null) { var fastProxy = ssaProxy.FASTAdminProxy; KeywordContext keywordContext = fastProxy.KeywordContext; SearchSettingGroupCollection searchSettingGroupCollection = keywordContext.SearchSettingGroups; DateTime currentDate = DateTime.Now; foreach (SearchSettingGroup searchSettingGroup in searchSettingGroupCollection) { foreach (Keyword keyword in searchSettingGroup.Keywords) { foreach (Synonym synonym in keyword.Synonyms) { if (synonym.StartDate < currentDate || synonym.EndDate > currentDate) { continue; } AddSynonym(keyword.Term, synonym.Term, synonymLookup); if (synonym.ExpansionType == SynonymExpansionType.TwoWay) { AddSynonym(synonym.Term, keyword.Term, synonymLookup); } } } } } } catch (SecurityException secEx) { Logger.Instance.Error("Failed to populated synonyms", secEx, DiagnosticsCategories.eCaseSearch); throw secEx; } } ); }
public static string CreateBestBetXml(List <string> queryWords, bool exactMatchOnTerms) { List <string> bestBets = new List <string>(); List <string> termDefs = new List <string>(); SPSecurity.RunWithElevatedPrivileges( delegate { var ssaProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.Current); if (ssaProxy.FASTAdminProxy != null) { var fastProxy = ssaProxy.FASTAdminProxy; KeywordContext keywordContext = fastProxy.KeywordContext; SearchSettingGroupCollection searchSettingGroupCollection = keywordContext.SearchSettingGroups; DateTime currentDate = DateTime.Now; string fullQuery = string.Join(" ", queryWords.ToArray()); foreach (SearchSettingGroup searchSettingGroup in searchSettingGroupCollection) { foreach (Keyword keyword in searchSettingGroup.Keywords) { List <string> terms = exactMatchOnTerms ? GetFullTermAndSynonymWords(keyword) : GetPartialTermAndSynonymWords(keyword); foreach (string bestBetTerms in terms) { //TODO: fullquery - check any combination with exact match on the best bet if (!_reNonChar.IsMatch(bestBetTerms)) //a-z only { Regex reBoundaryMatch = new Regex(@"\b" + bestBetTerms + @"\b"); if (!reBoundaryMatch.IsMatch(fullQuery)) { continue; } } if (!queryWords.Contains(bestBetTerms)) { continue; } string termDef = GetTermDefXml(keyword); if (!string.IsNullOrEmpty(termDef) && !termDefs.Contains(termDef)) { termDefs.Add(termDef); } foreach (BestBet bestBet in keyword.BestBets) { if (bestBet.StartDate < currentDate || bestBet.EndDate > currentDate) { continue; } string xml = BuildBestBetXml(keyword, bestBet); if (!bestBets.Contains(xml)) { bestBets.Add(xml); } } } } } } } ); return("<All_Results>" + string.Join("", termDefs.ToArray()) + "<BestBetResults>" + string.Join("", bestBets.ToArray()) + "</BestBetResults></All_Results>"); }