public override void FilterArticles(SearchResultsInfoCollection data)
        {
            Debug.Assert(data != null, "data must not be null");

            // some conditions that we don't need to bother
            if (data.Count == 0)
            {
                return;
            }

            IDictionary viewableIds = DataProvider.Instance().GetViewableArticleIds(PermissionType.View.GetId());

            var al = new ArrayList();
            foreach (SearchResultsInfo result in data)
            {
                int articleId = Utility.GetArticleId(result);
                if (viewableIds.Contains(articleId) == false)
                {
                    // remove this row from the results
                    al.Add(result);
                }
            }

            // remove all the rows that I'm not allowed to see
            foreach (SearchResultsInfo result in al)
            {
                data.Remove(result);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the contents of another <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> to the end of the collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> containing the objects to add to the collection. </param>
 public void AddRange(SearchResultsInfoCollection value)
 {
     for (int i = 0; i <= value.Count - 1; i++)
     {
         Add((SearchResultsInfo)value.List[i]);
     }
 }
        public static SearchResultsInfoCollection CleanSearchList(SearchResultsInfoCollection data)
        {
            //get rid of the duplicates
            //some conditions that we don't need to bother
            if (data == null || data.Count == 0) return data;

            IDictionary d = new Hashtable();

            var al = new ArrayList();
            foreach (SearchResultsInfo result in data)
            {
                //IDictionary listOfIds = GetSearchArticleIds(data);
                int articleId = Utility.GetArticleId(result);

                if (d.Contains(articleId))
                {
                    //remove this row from the results
                    al.Add(result);
                }
                else
                {
                    d.Add(articleId, null);
                }
            }

            //remove all the rows that I'm not allowed to see
            foreach (SearchResultsInfo result in al)
            {
                data.Remove(result);
            }
            return data;
        }
 public static SearchResultsInfoCollection GetSearchResults(int PortalId, int TabId, int ModuleId)
 {
     var empty = new SearchResultsInfoCollection();
     return empty;
 }
 public static SearchResultsInfoCollection GetSearchResults(int PortalID, string Word)
 {
     var empty = new SearchResultsInfoCollection();
     return empty;
 }
        public static SearchResultsInfoCollection GetSearchResults(int PortalId, int TabId, int ModuleId)
        {
            var empty = new SearchResultsInfoCollection();

            return(empty);
        }
        public static SearchResultsInfoCollection GetSearchResults(int PortalID, string Word)
        {
            var empty = new SearchResultsInfoCollection();

            return(empty);
        }
Ejemplo n.º 8
0
 /// <Summary>
 /// Initializes a new instance of the SearchResultsInfoCollection class containing the elements of the specified source collection.
 /// </Summary>
 /// <Param name="value">
 /// A SearchResultsInfoCollection with which to initialize the collection.
 /// </Param>
 public SearchResultsInfoCollection(SearchResultsInfoCollection value)
 {
     this.AddRange(value);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> class containing the elements of the specified source collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> with which to initialize the collection.</param>
 public SearchResultsInfoCollection(SearchResultsInfoCollection value)
 {
     AddRange(value);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// GetSearchResults gets the search results for a passed in criteria string
        /// </summary>
        /// <param name="PortalID">A Id of the Portal</param>
        /// <param name="Criteria">The criteria string</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        public override SearchResultsInfoCollection GetSearchResults( int PortalID, string Criteria )
        {
            //We will assume that the content is in the locale of the Portal
            PortalController objPortalController = new PortalController();
            PortalInfo objPortal = objPortalController.GetPortal( PortalID );
            string locale = objPortal.DefaultLanguage;
            Hashtable CommonWords = GetCommonWords( locale );
            string setting = null;

            //Get the default Search Settings
            _defaultSettings = Globals.HostSettings;

            //Get the Settings for this Portal
            ModuleController objModuleController = new ModuleController();
            ModuleInfo objModule = objModuleController.GetModuleByDefinition( -1, "Search Admin" );
            if( objModule != null )
            {
                _settings = PortalSettings.GetModuleSettings( objModule.ModuleID );
            }
            setting = GetSetting( "SearchIncludeCommon" );
            if( setting == "Y" )
            {
                includeCommon = true;
            }

            // clean criteria
            Criteria = Criteria.ToLower();

            // split search criteria into words
            SearchCriteriaCollection SearchWords = new SearchCriteriaCollection( Criteria );
            Hashtable SearchResults = new Hashtable();

            // iterate through search criteria words
            SearchCriteria Criterion = null;
            foreach( SearchCriteria CriterionWithinLoop in SearchWords )
            {
                Criterion = CriterionWithinLoop;
                if( CommonWords.ContainsKey( CriterionWithinLoop.Criteria ) == false || includeCommon )
                {
                    SearchResultsInfoCollection ResultsCollection = SearchDataStoreController.GetSearchResults( PortalID, Criterion.Criteria );
                    if( CriterionWithinLoop.MustExclude == false )
                    {
                        // Add all these to the results
                        foreach( SearchResultsInfo Result in ResultsCollection )
                        {
                            if( SearchResults.ContainsKey( Result.SearchItemID ) )
                            {
                                ( (SearchResultsInfo)( SearchResults[Result.SearchItemID] ) ).Relevance += Result.Relevance;
                            }
                            else
                            {
                                SearchResults.Add( Result.SearchItemID, Result );
                            }
                        }
                    }
                }
            }

            // Validate MustInclude and MustExclude
            foreach( SearchCriteria CriterionWithinLoop in SearchWords )
            {
                Criterion = CriterionWithinLoop;
                SearchResultsInfoCollection ResultsCollection = SearchDataStoreController.GetSearchResults( PortalID, Criterion.Criteria );
                if( CriterionWithinLoop.MustInclude )
                {
                    // We need to remove items which do not include this term
                    Hashtable MandatoryResults = new Hashtable();
                    foreach( SearchResultsInfo Result in ResultsCollection )
                    {
                        MandatoryResults.Add( Result.SearchItemID, 0 );
                    }
                    foreach( SearchResultsInfo Result in SearchResults.Values )
                    {
                        if( MandatoryResults.ContainsKey( Result.SearchItemID ) == false )
                        {
                            Result.Delete = true;
                        }
                    }
                }
                if( CriterionWithinLoop.MustExclude )
                {
                    // We need to remove items which do include this term
                    Hashtable ExcludedResults = new Hashtable();
                    foreach( SearchResultsInfo Result in ResultsCollection )
                    {
                        ExcludedResults.Add( Result.SearchItemID, 0 );
                    }
                    foreach( SearchResultsInfo Result in SearchResults.Values )
                    {
                        if( ExcludedResults.ContainsKey( Result.SearchItemID ) == true )
                        {
                            Result.Delete = true;
                        }
                    }
                }
            }

            //Only include results we have permission to see
            SearchResultsInfoCollection Results = new SearchResultsInfoCollection();
            TabController objTabController = new TabController();
            Hashtable hashTabsAllowed = new Hashtable();
            foreach( SearchResultsInfo SearchResult in SearchResults.Values )
            {
                if( !SearchResult.Delete )
                {
                    //Check If authorised to View Tab
                    Hashtable hashModulesAllowed = null;
                    object tabAllowed = hashTabsAllowed[SearchResult.TabId];
                    if( tabAllowed == null )
                    {
                        TabInfo objTab = objTabController.GetTab( SearchResult.TabId, PortalID, false );
                        if( PortalSecurity.IsInRoles( objTab.AuthorizedRoles ) )
                        {
                            hashModulesAllowed = new Hashtable();
                            tabAllowed = hashModulesAllowed;
                        }
                        else
                        {
                            tabAllowed = 0;
                            hashModulesAllowed = null;
                        }
                        hashTabsAllowed.Add( SearchResult.TabId, tabAllowed );
                    }
                    else
                    {
                        if( tabAllowed is Hashtable )
                        {
                            hashModulesAllowed = (Hashtable)tabAllowed;
                        }
                        else
                        {
                            hashModulesAllowed = null;
                        }
                    }

                    if( hashModulesAllowed != null )
                    {
                        bool addResult = false;
                        if( !( hashModulesAllowed.ContainsKey( SearchResult.ModuleId ) ) )
                        {
                            //Now check if authorized to view module
                            objModule = objModuleController.GetModule( SearchResult.ModuleId, SearchResult.TabId, false );
                            addResult = ( objModule.IsDeleted == false && PortalSecurity.IsInRoles( objModule.AuthorizedViewRoles ) );
                            hashModulesAllowed.Add( SearchResult.ModuleId, addResult );
                        }
                        else
                        {
                            addResult = Convert.ToBoolean( hashModulesAllowed[SearchResult.ModuleId] );
                        }

                        if( addResult )
                        {
                            Results.Add( SearchResult );
                        }
                    }
                }
            }

            //Return Search Results Collection
            return Results;
        }
        private void BindData()
        {
            object o;
            var results = new SearchResultsInfoCollection();
            if (ddlCategoryList.SelectedIndex == 0)
            {
                o = Settings["csCategoryId"];
                if (o != null)
                {
                    int categoryOption;
                    if (int.TryParse(o.ToString(), out categoryOption))
                    {
                        results = Search(categoryOption, txtCategorySearch.Text.Trim());
                    }
                }
            }
            else
            {
                results = Search(Convert.ToInt32(ddlCategoryList.SelectedValue, CultureInfo.InvariantCulture), txtCategorySearch.Text.Trim());
            }

            var dt = new DataTable {Locale = CultureInfo.InvariantCulture};
            //DataColumn dc = new DataColumn("TabId");
            dt.Columns.Add(new DataColumn("TabId", typeof(int)));
            dt.Columns.Add(new DataColumn("Guid", typeof(string)));
            dt.Columns.Add(new DataColumn("Title", typeof(string)));
            dt.Columns.Add(new DataColumn("Relevance", typeof(int)));
            dt.Columns.Add(new DataColumn("Description", typeof(string)));
            dt.Columns.Add(new DataColumn("PubDate", typeof(DateTime)));

            //Get the maximum items to display
            int maxItems;
            o = Settings["csMaxResults"];
            if (o == null || !int.TryParse(o.ToString(), out maxItems))
            {
                maxItems = results.Count;
            }

            if (results.Count < maxItems || maxItems < 1)
            {
                maxItems = results.Count;
            }

            int itemsPage = 10;
            o = Settings["csPerPage"];
            if (o != null)
            {
                //itemsPage = Convert.ToInt32(Settings["perpage"]);
                if (!int.TryParse(o.ToString(), out itemsPage))
                {
                    itemsPage = 10;
                }
            }

            int titleLength = 0;
            o = Settings["csTitleLength"];
            if (o != null)
            {
                if (!int.TryParse(o.ToString(), out titleLength))
                {
                    titleLength = 10;
                }
            }

            int descLength = 0;
            o = Settings["csDescriptionLength"];
            if (o != null)
            {
                if (!int.TryParse(o.ToString(), out descLength))
                {
                    descLength = 10;
                }
            }

            for (int i = 0; i < maxItems; i++)
            {
                SearchResultsInfo resultItem = results[i];
                DataRow dr = dt.NewRow();
                dr["TabId"] = resultItem.TabId;
                dr["Guid"] = resultItem.Guid;
                if (titleLength > 0 && titleLength < resultItem.Title.Length)
                {
                    dr["Title"] = resultItem.Title.Substring(0, titleLength);
                }
                else
                {
                    dr["Title"] = resultItem.Title;
                }
                dr["Relevance"] = resultItem.Relevance;
                if (descLength > 0 && descLength < resultItem.Description.Length)
                {
                    dr["Description"] = resultItem.Description.Substring(0, descLength);
                }
                else
                {
                    dr["Description"] = resultItem.Description;
                }

                dr["PubDate"] = resultItem.PubDate;

                dt.Rows.Add(dr);
            }

            using (var dv = new DataView(dt))
            {
                dv.Sort = "Relevance DESC";
                if (itemsPage < 1)
                {
                    dgResults.AllowPaging = false;
                    dgResults.PagerStyle.Visible = false;
                }
                else
                {
                    dgResults.PageSize = itemsPage;
                    dgResults.PagerStyle.Visible = results.Count >= dgResults.PageSize;
                }
                dgResults.DataSource = dv;
                dgResults.DataBind();

                dgResults.Visible = results.Count != 0;
                lblNoResults.Visible = results.Count == 0;
            }
        }
Ejemplo n.º 12
0
 public abstract void FilterArticles(SearchResultsInfoCollection data);
        public override void FilterArticles(SearchResultsInfoCollection data)
        {
            Debug.Assert(data != null, "data must not be null");

            // does nothing
        }
Ejemplo n.º 14
0
        /// <summary>
        /// GetSearchResults gets the search results for a passed in criteria string
        /// </summary>
        /// <param name="PortalID">A Id of the Portal</param>
        /// <param name="Criteria">The criteria string</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        public override SearchResultsInfoCollection GetSearchResults(int PortalID, string Criteria)
        {
            //We will assume that the content is in the locale of the Portal
            PortalController objPortalController = new PortalController();
            PortalInfo       objPortal           = objPortalController.GetPortal(PortalID);
            string           locale      = objPortal.DefaultLanguage;
            Hashtable        CommonWords = GetCommonWords(locale);
            string           setting     = null;

            //Get the default Search Settings
            _defaultSettings = Globals.HostSettings;

            //Get the Settings for this Portal
            ModuleController objModuleController = new ModuleController();
            ModuleInfo       objModule           = objModuleController.GetModuleByDefinition(-1, "Search Admin");

            if (objModule != null)
            {
                _settings = PortalSettings.GetModuleSettings(objModule.ModuleID);
            }
            setting = GetSetting("SearchIncludeCommon");
            if (setting == "Y")
            {
                includeCommon = true;
            }

            // clean criteria
            Criteria = Criteria.ToLower();

            // split search criteria into words
            SearchCriteriaCollection SearchWords = new SearchCriteriaCollection(Criteria);
            Hashtable SearchResults = new Hashtable();

            // iterate through search criteria words
            SearchCriteria Criterion = null;

            foreach (SearchCriteria CriterionWithinLoop in SearchWords)
            {
                Criterion = CriterionWithinLoop;
                if (CommonWords.ContainsKey(CriterionWithinLoop.Criteria) == false || includeCommon)
                {
                    SearchResultsInfoCollection ResultsCollection = SearchDataStoreController.GetSearchResults(PortalID, Criterion.Criteria);
                    if (CriterionWithinLoop.MustExclude == false)
                    {
                        // Add all these to the results
                        foreach (SearchResultsInfo Result in ResultsCollection)
                        {
                            if (SearchResults.ContainsKey(Result.SearchItemID))
                            {
                                ((SearchResultsInfo)(SearchResults[Result.SearchItemID])).Relevance += Result.Relevance;
                            }
                            else
                            {
                                SearchResults.Add(Result.SearchItemID, Result);
                            }
                        }
                    }
                }
            }

            // Validate MustInclude and MustExclude
            foreach (SearchCriteria CriterionWithinLoop in SearchWords)
            {
                Criterion = CriterionWithinLoop;
                SearchResultsInfoCollection ResultsCollection = SearchDataStoreController.GetSearchResults(PortalID, Criterion.Criteria);
                if (CriterionWithinLoop.MustInclude)
                {
                    // We need to remove items which do not include this term
                    Hashtable MandatoryResults = new Hashtable();
                    foreach (SearchResultsInfo Result in ResultsCollection)
                    {
                        MandatoryResults.Add(Result.SearchItemID, 0);
                    }
                    foreach (SearchResultsInfo Result in SearchResults.Values)
                    {
                        if (MandatoryResults.ContainsKey(Result.SearchItemID) == false)
                        {
                            Result.Delete = true;
                        }
                    }
                }
                if (CriterionWithinLoop.MustExclude)
                {
                    // We need to remove items which do include this term
                    Hashtable ExcludedResults = new Hashtable();
                    foreach (SearchResultsInfo Result in ResultsCollection)
                    {
                        ExcludedResults.Add(Result.SearchItemID, 0);
                    }
                    foreach (SearchResultsInfo Result in SearchResults.Values)
                    {
                        if (ExcludedResults.ContainsKey(Result.SearchItemID) == true)
                        {
                            Result.Delete = true;
                        }
                    }
                }
            }

            //Only include results we have permission to see
            SearchResultsInfoCollection Results = new SearchResultsInfoCollection();
            TabController objTabController      = new TabController();
            Hashtable     hashTabsAllowed       = new Hashtable();

            foreach (SearchResultsInfo SearchResult in SearchResults.Values)
            {
                if (!SearchResult.Delete)
                {
                    //Check If authorised to View Tab
                    Hashtable hashModulesAllowed = null;
                    object    tabAllowed         = hashTabsAllowed[SearchResult.TabId];
                    if (tabAllowed == null)
                    {
                        TabInfo objTab = objTabController.GetTab(SearchResult.TabId, PortalID, false);
                        if (PortalSecurity.IsInRoles(objTab.AuthorizedRoles))
                        {
                            hashModulesAllowed = new Hashtable();
                            tabAllowed         = hashModulesAllowed;
                        }
                        else
                        {
                            tabAllowed         = 0;
                            hashModulesAllowed = null;
                        }
                        hashTabsAllowed.Add(SearchResult.TabId, tabAllowed);
                    }
                    else
                    {
                        if (tabAllowed is Hashtable)
                        {
                            hashModulesAllowed = (Hashtable)tabAllowed;
                        }
                        else
                        {
                            hashModulesAllowed = null;
                        }
                    }

                    if (hashModulesAllowed != null)
                    {
                        bool addResult = false;
                        if (!(hashModulesAllowed.ContainsKey(SearchResult.ModuleId)))
                        {
                            //Now check if authorized to view module
                            objModule = objModuleController.GetModule(SearchResult.ModuleId, SearchResult.TabId, false);
                            addResult = (objModule.IsDeleted == false && PortalSecurity.IsInRoles(objModule.AuthorizedViewRoles));
                            hashModulesAllowed.Add(SearchResult.ModuleId, addResult);
                        }
                        else
                        {
                            addResult = Convert.ToBoolean(hashModulesAllowed[SearchResult.ModuleId]);
                        }

                        if (addResult)
                        {
                            Results.Add(SearchResult);
                        }
                    }
                }
            }

            //Return Search Results Collection
            return(Results);
        }
Ejemplo n.º 15
0
        /// -----------------------------------------------------------------------------
        /// <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>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public override SearchResultsInfoCollection GetSearchResults(int portalId, string criteria)
        {
            bool hasExcluded = Null.NullBoolean;
            bool hasMandatory = Null.NullBoolean;

            var objPortalController = new PortalController();
            PortalInfo objPortal = objPortalController.GetPortal(portalId);

            //Get the Settings for this Portal
            var portalSettings = new PortalSettings(objPortal);

            //We will assume that the content is in the locale of the Portal
            Hashtable commonWords = GetCommonWords(portalSettings.DefaultLanguage);

            //clean criteria
            criteria = criteria.ToLower();

            //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();
            var objTabController = new TabController();
            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 = objTabController.GetTab(result.TabId, portalId, false);
                        if (TabPermissionController.CanViewPage(objTab))
                        {
							//Check If authorised to View Module
                            ModuleInfo objModule = new ModuleController().GetModule(result.ModuleId, result.TabId, false);
                            if (ModulePermissionController.CanViewModule(objModule))
                            {
                                results.Add(result);
                            }
                        }
                    }
                }
            }
			
            //Return Search Results Collection
            return results;
        }
Ejemplo n.º 16
0
        /// -----------------------------------------------------------------------------
        /// <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>
        /// -----------------------------------------------------------------------------
        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 = GetCommonWords(portalSettings.DefaultLanguage);

            //clean criteria
            criteria = criteria.ToLower();

            //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>
 /// Adds the contents of another <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> to the end of the collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchResultsInfoCollection">SearchResultsInfoCollection</see> containing the objects to add to the collection. </param>
 public void AddRange(SearchResultsInfoCollection value)
 {
     for (int i = 0; i <= value.Count - 1; i++)
     {
         Add((SearchResultsInfo) value.List[i]);
     }
 }