/// <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 criteria string with which to initialize the collection</param>
        public SearchCriteriaCollection( string value )
        {
            // split search criteria into words
            string[] Words = value.Split( ' ' );            
            string word;
            // Add all criteria without modifiers
            foreach( string tempLoopVar_word in Words )
            {
                word = tempLoopVar_word;
                SearchCriteria criterion = new SearchCriteria();

                if( ( ! word.StartsWith( "+" ) ) && ( ! word.StartsWith( "-" ) ) )
                {
                    criterion.MustInclude = false;
                    criterion.MustExclude = false;
                    criterion.Criteria = word;
                    Add( criterion );
                }
            }
            // Add all mandatory criteria
            foreach( string tempLoopVar_word in Words )
            {
                word = tempLoopVar_word;
                SearchCriteria criterion = new SearchCriteria();

                if( word.StartsWith( "+" ) )
                {
                    criterion.MustInclude = true;
                    criterion.MustExclude = false;
                    criterion.Criteria = word.Remove( 0, 1 );
                    Add( criterion );
                }
            }
            // Add all excluded criteria
            foreach( string tempLoopVar_word in Words )
            {
                word = tempLoopVar_word;
                SearchCriteria criterion = new SearchCriteria();

                if( word.StartsWith( "-" ) )
                {
                    criterion.MustInclude = false;
                    criterion.MustExclude = true;
                    criterion.Criteria = word.Remove( 0, 1 );
                    Add( criterion );
                }
            }
        }
        } //Contains

        /// <summary>
        /// Copies the elements of the specified <see cref="SearchCriteria">SearchCriteria</see> array to the end of the collection.
        /// </summary>
        /// <param name="value">An array of type <see cref="SearchCriteria">SearchCriteria</see> containing the objects to add to the collection.</param>
        public void AddRange( SearchCriteria[] value )
        {
            for( int i = 0; i <= value.Length - 1; i++ )
            {
                Add( value[ i ] );
            }
        }
        } //Remove

        /// <summary>
        /// Gets a value indicating whether the collection contains the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>.
        /// </summary>
        /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to search for in the collection.</param>
        /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
        public bool Contains( SearchCriteria value )
        {
            // If value is not of type SearchCriteria, this will return false.
            return List.Contains( value );
        } //Contains
        } //Insert

        /// <summary>
        /// Remove the specified object of type <see cref="SearchCriteria">SearchCriteria</see> from the collection.
        /// </summary>
        /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to remove to the collection.</param>
        public void Remove( SearchCriteria value )
        {
            List.Remove( value );
        } //Remove
        } //IndexOf

        /// <summary>
        /// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the collection at the designated index.
        /// </summary>
        /// <param name="index">An Integer to indicate the location to add the object to the collection.</param>
        /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
        public void Insert( int index, SearchCriteria value )
        {
            List.Insert( index, value );
        } //Insert
        } //Add

        /// <summary>
        /// Gets the index in the collection of the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>, if it exists in the collection.
        /// </summary>
        /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to locate in the collection.</param>
        /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
        public int IndexOf( SearchCriteria value )
        {
            return List.IndexOf( value );
        } //IndexOf
 /// <summary>
 /// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the end of the collection.
 /// </summary>
 /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
 public int Add(SearchCriteria value)
 {
     return(List.Add(value));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> class containing the specified array of <see cref="SearchCriteria">SearchCriteria</see> objects.
 /// </summary>
 /// <param name="value">An array of <see cref="SearchCriteria">SearchCriteria</see> objects with which to initialize the collection. </param>
 public SearchCriteriaCollection( SearchCriteria[] value )
 {
     AddRange( value );
 }
 /// <summary>
 /// Gets a value indicating whether the collection contains the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>.
 /// </summary>
 /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to search for in the collection.</param>
 /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
 public bool Contains(SearchCriteria value)
 {
     return List.Contains(value);
 }
Exemple #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);
        }
 /// <summary>
 /// Gets a value indicating whether the collection contains the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>.
 /// </summary>
 /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to search for in the collection.</param>
 /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
 public bool Contains(SearchCriteria value)
 {
     return(List.Contains(value));
 }
 /// <summary>
 /// Remove the specified object of type <see cref="SearchCriteria">SearchCriteria</see> from the collection.
 /// </summary>
 /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to remove to the collection.</param>
 public void Remove(SearchCriteria value)
 {
     List.Remove(value);
 }
 /// <summary>
 /// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the collection at the designated index.
 /// </summary>
 /// <param name="index">An <see cref="System.Int32">Integer</see> to indicate the location to add the object to the collection.</param>
 /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
 public void Insert(int index, SearchCriteria value)
 {
     List.Insert(index, value);
 }
 /// <summary>
 /// Gets the index in the collection of the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>, if it exists in the collection.
 /// </summary>
 /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to locate in the collection.</param>
 /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns>
 public int IndexOf(SearchCriteria value)
 {
     return(List.IndexOf(value));
 }
 /// <summary>
 /// Copies the collection objects to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param>
 /// <param name="index">The index of the array at which to begin inserting.</param>
 public void CopyTo( SearchCriteria[] array, int index )
 {
     List.CopyTo( array, index );
 }
        /// <summary>
        /// Creates a one-dimensional <see cref="T:System.Array">Array</see> instance containing the collection items.
        /// </summary>
        /// <returns>Array of type SearchCriteria</returns>
        public SearchCriteria[] ToArray()
        {
            SearchCriteria[] arr = new SearchCriteria[Count - 1 + 1];            
            CopyTo( arr, 0 );

            return arr;
        }
 /// <summary>
 /// Creates a one-dimensional <see cref="T:System.Array">Array</see> instance containing the collection items.
 /// </summary>
 /// <returns>Array of type SearchCriteria</returns>
 public SearchCriteria[] ToArray()
 {
     var arr = new SearchCriteria[Count];
     CopyTo(arr, 0);
     return arr;
 }
 /// <summary>
 /// Add an element of the specified <see cref="SearchCriteria">SearchCriteria</see> to the end of the collection.
 /// </summary>
 /// <param name="value">An object of type <see cref="SearchCriteria">SearchCriteria</see> to add to the collection.</param>
 public int Add( SearchCriteria value )
 {
     return List.Add( value );
 } //Add
Exemple #19
0
        } //Remove

        /// <summary>
        /// Gets a value indicating whether the collection contains the specified <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see>.
        /// </summary>
        /// <param name="value">The <see cref="SearchCriteriaCollection">SearchCriteriaCollection</see> to search for in the collection.</param>
        /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns>
        public bool Contains(SearchCriteria value)
        {
            // If value is not of type SearchCriteria, this will return false.
            return(List.Contains(value));
        } //Contains