/// ----------------------------------------------------------------------------- /// <summary> /// GetSearchResults gets the search results for a passed in criteria string. /// </summary> /// <remarks> /// </remarks> /// <param name="portalId">A Id of the Portal.</param> /// <param name="criteria">The criteria string.</param> /// <returns></returns> /// ----------------------------------------------------------------------------- public override SearchResultsInfoCollection GetSearchResults(int portalId, string criteria) { bool hasExcluded = Null.NullBoolean; bool hasMandatory = Null.NullBoolean; var portal = PortalController.Instance.GetPortal(portalId); // Get the Settings for this Portal var portalSettings = new PortalSettings(portal); // We will assume that the content is in the locale of the Portal Hashtable commonWords = this.GetCommonWords(portalSettings.DefaultLanguage); // clean criteria criteria = criteria.ToLowerInvariant(); // split search criteria into words var searchWords = new SearchCriteriaCollection(criteria); var searchResults = new Dictionary <string, SearchResultsInfoCollection>(); // dicResults is a Dictionary(Of SearchItemID, Dictionary(Of TabID, SearchResultsInfo) var dicResults = new Dictionary <int, Dictionary <int, SearchResultsInfo> >(); // iterate through search criteria words foreach (SearchCriteria criterion in searchWords) { if (commonWords.ContainsKey(criterion.Criteria) == false || portalSettings.SearchIncludeCommon) { if (!searchResults.ContainsKey(criterion.Criteria)) { searchResults.Add(criterion.Criteria, SearchDataStoreController.GetSearchResults(portalId, criterion.Criteria)); } if (searchResults.ContainsKey(criterion.Criteria)) { foreach (SearchResultsInfo result in searchResults[criterion.Criteria]) { // Add results to dicResults if (!criterion.MustExclude) { if (dicResults.ContainsKey(result.SearchItemID)) { // The Dictionary exists for this SearchItemID already so look in the TabId keyed Sub-Dictionary Dictionary <int, SearchResultsInfo> dic = dicResults[result.SearchItemID]; if (dic.ContainsKey(result.TabId)) { // The sub-Dictionary contains the item already so update the relevance SearchResultsInfo searchResult = dic[result.TabId]; searchResult.Relevance += result.Relevance; } else { // Add Entry to Sub-Dictionary dic.Add(result.TabId, result); } } else { // Create new TabId keyed Dictionary var dic = new Dictionary <int, SearchResultsInfo>(); dic.Add(result.TabId, result); // Add new Dictionary to SearchResults dicResults.Add(result.SearchItemID, dic); } } } } } } foreach (SearchCriteria criterion in searchWords) { var mandatoryResults = new Dictionary <int, bool>(); var excludedResults = new Dictionary <int, bool>(); if (searchResults.ContainsKey(criterion.Criteria)) { foreach (SearchResultsInfo result in searchResults[criterion.Criteria]) { if (criterion.MustInclude) { // Add to mandatory results lookup mandatoryResults[result.SearchItemID] = true; hasMandatory = true; } else if (criterion.MustExclude) { // Add to exclude results lookup excludedResults[result.SearchItemID] = true; hasExcluded = true; } } } foreach (KeyValuePair <int, Dictionary <int, SearchResultsInfo> > kvpResults in dicResults) { // The key of this collection is the SearchItemID, Check if the value of this collection should be processed if (hasMandatory && (!mandatoryResults.ContainsKey(kvpResults.Key))) { // 1. If mandatoryResults exist then only process if in mandatoryResults Collection foreach (SearchResultsInfo result in kvpResults.Value.Values) { result.Delete = true; } } else if (hasExcluded && excludedResults.ContainsKey(kvpResults.Key)) { // 2. Do not process results in the excludedResults Collection foreach (SearchResultsInfo result in kvpResults.Value.Values) { result.Delete = true; } } } } // Process results against permissions and mandatory and excluded results var results = new SearchResultsInfoCollection(); foreach (KeyValuePair <int, Dictionary <int, SearchResultsInfo> > kvpResults in dicResults) { foreach (SearchResultsInfo result in kvpResults.Value.Values) { if (!result.Delete) { // Check If authorised to View Tab TabInfo objTab = TabController.Instance.GetTab(result.TabId, portalId, false); if (TabPermissionController.CanViewPage(objTab)) { // Check If authorised to View Module ModuleInfo objModule = ModuleController.Instance.GetModule(result.ModuleId, result.TabId, false); if (ModulePermissionController.CanViewModule(objModule)) { results.Add(result); } } } } } // Return Search Results Collection return(results); }
/// ----------------------------------------------------------------------------- /// <summary> /// GetSearchItems gets a collection of Search Items for a Module/Tab/Portal. /// </summary> /// <remarks> /// </remarks> /// <param name="portalId">A Id of the Portal.</param> /// <param name="tabId">A Id of the Tab.</param> /// <param name="moduleId">A Id of the Module.</param> /// <returns></returns> /// ----------------------------------------------------------------------------- public override SearchResultsInfoCollection GetSearchItems(int portalId, int tabId, int moduleId) { return(SearchDataStoreController.GetSearchResults(portalId, tabId, moduleId)); }