/// <summary>
 /// Adds the contents of another <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to the end of the collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> containing the objects to add to the collection. </param>
 public void AddRange(SearchCriteriaCollection value)
 {
     for (int i = 0; i <= value.Count - 1; i++)
     {
         Add((SearchCriteria)value.List[i]);
     }
 }
예제 #2
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);
        }
예제 #3
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;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the elements of the specified source collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> with which to initialize the collection.</param>
 public SearchCriteriaCollection(SearchCriteriaCollection value)
 {
     AddRange(value);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the elements of the specified source collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> with which to initialize the collection.</param>
 public SearchCriteriaCollection( SearchCriteriaCollection value )
 {
     AddRange( value );
 }
 /// <summary>
 /// Adds the contents of another <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to the end of the collection.
 /// </summary>
 /// <param name="value">A <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> containing the objects to add to the collection. </param>
 public void AddRange( SearchCriteriaCollection value )
 {
     for( int i = 0; i <= value.Count - 1; i++ )
     {
         Add( (SearchCriteria)value.List[ i ] );
     }
 }
예제 #7
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);
        }
예제 #8
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;
        }