Beispiel #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// StoreSearchItems adds the Search Item to the Data Store
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="searchItems">A Collection of SearchItems</param>
        public override void StoreSearchItems(SearchItemInfoCollection searchItems)
        {
            var indexer = new ModuleIndexer();

            var modulesDic = new Dictionary <int, string>();

            foreach (SearchItemInfo item in searchItems)
            {
                if (!modulesDic.ContainsKey(item.ModuleId))
                {
                    var module = ModuleController.Instance.GetModule(item.ModuleId, Null.NullInteger, true);
                    modulesDic.Add(item.ModuleId, module.CultureCode);

                    //Remove all indexed items for this module
                    InternalSearchController.Instance.DeleteSearchDocumentsByModule(module.PortalID, module.ModuleID, module.ModuleDefID);
                }
            }

            //Process the SearchItems by Module to reduce Database hits
            foreach (var kvp in modulesDic)
            {
                //Get the Module's SearchItems
                var moduleSearchItems = searchItems.ModuleItems(kvp.Key);

                //Convert SearchItemInfo objects to SearchDocument objects
                var searchDocuments = (from SearchItemInfo item in moduleSearchItems select indexer.ConvertSearchItemInfoToSearchDocument(item)).ToList();

                //Index
                InternalSearchController.Instance.AddSearchDocuments(searchDocuments);
            }
        }
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// StoreSearchItems adds the Search Item to the Data Store
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <param name="searchItems">A Collection of SearchItems</param>
 /// <history>
 ///		[cnurse]	11/15/2004	documented
 ///     [vnguyen]   09/07/2010  Modified: Added a date comparison for LastModifiedDate on the Tab
 ///     [vnguyen]   16/04/2013  Modified: Now uses Lucene indexing
 ///     [galatrash] 23/05/2013  Modified: moved indexing methods into the internal namespace.
 /// </history>
 /// -----------------------------------------------------------------------------
 public override void StoreSearchItems(SearchItemInfoCollection searchItems)
 {
     var moduleController = new ModuleController();
     var indexer = new ModuleIndexer();
     
     var modulesDic = new Dictionary<int, string>();
     foreach (SearchItemInfo item in searchItems)
     {                
         if (!modulesDic.ContainsKey(item.ModuleId))
         {
             var module = moduleController.GetModule(item.ModuleId);
             modulesDic.Add(item.ModuleId, module.CultureCode);
             
             //Remove all indexed items for this module
             InternalSearchController.Instance.DeleteSearchDocumentsByModule(module.PortalID, module.ModuleID, module.ModuleDefID);
         }
     }
   
     //Process the SearchItems by Module to reduce Database hits
     foreach (var kvp in modulesDic)
     {
         //Get the Module's SearchItems
         var moduleSearchItems = searchItems.ModuleItems(kvp.Key);
         
         //Convert SearchItemInfo objects to SearchDocument objects
         var searchDocuments = (from SearchItemInfo item in moduleSearchItems select indexer.ConvertSearchItemInfoToSearchDocument(item)).ToList();
         
         //Index
         InternalSearchController.Instance.AddSearchDocuments(searchDocuments);                
     }
 } 
Beispiel #3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// StoreSearchItems adds the Search Item to the Data Store
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="SearchItems">A Collection of SearchItems</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        ///     [vnguyen]   09/07/2010  Modified: Added a date comparison for LastModifiedDate on the Tab
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void StoreSearchItems(SearchItemInfoCollection SearchItems)
        {
            //For now as we don't support Localized content - set the locale to the default locale. This
            //is to avoid the error in GetDefaultLanguageByModule which artificially limits the number
            //of modules that can be indexed.  This will need to be addressed when we support localized content.
            var Modules = new Dictionary <int, string>();

            foreach (SearchItemInfo item in SearchItems)
            {
                if (!Modules.ContainsKey(item.ModuleId))
                {
                    Modules.Add(item.ModuleId, "en-US");
                }
            }

            var objTabs   = new TabController();
            var objModule = new ModuleInfo();
            var objTab    = new TabInfo();

            SearchItemInfo searchItem;
            Dictionary <string, SearchItemInfo> indexedItems;
            SearchItemInfoCollection            moduleItems;

            //Process the SearchItems by Module to reduce Database hits
            foreach (KeyValuePair <int, string> kvp in Modules)
            {
                indexedItems = SearchDataStoreController.GetSearchItems(kvp.Key);

                //Get the Module's SearchItems to compare
                moduleItems = SearchItems.ModuleItems(kvp.Key);

                //remove deleted indexed items
                var moduleItemList = moduleItems.Cast <SearchItemInfo>().ToList();
                indexedItems.Values
                .Where(i => moduleItemList.All(s => s.SearchKey != i.SearchKey))
                .ToList().ForEach(i => SearchDataStoreController.DeleteSearchItem(i.SearchItemId));

                //As we will be potentially removing items from the collection iterate backwards
                for (int iSearch = moduleItems.Count - 1; iSearch >= 0; iSearch += -1)
                {
                    searchItem = moduleItems[iSearch];

                    //Get item from Indexed collection
                    SearchItemInfo indexedItem = null;
                    if (indexedItems.TryGetValue(searchItem.SearchKey, out indexedItem))
                    {
                        //Get the tab where the search item resides -- used in date comparison
                        objModule = new ModuleController().GetModule(searchItem.ModuleId);
                        objTab    = objTabs.GetTab(searchItem.TabId, objModule.PortalID, false);

                        //Item exists so compare Dates to see if modified
                        if (indexedItem.PubDate < searchItem.PubDate || indexedItem.PubDate < objModule.LastModifiedOnDate || indexedItem.PubDate < objTab.LastModifiedOnDate)
                        {
                            try
                            {
                                if (searchItem.PubDate < objModule.LastModifiedOnDate)
                                {
                                    searchItem.PubDate = objModule.LastModifiedOnDate;
                                }
                                if (searchItem.PubDate < objTab.LastModifiedOnDate)
                                {
                                    searchItem.PubDate = objTab.LastModifiedOnDate;
                                }


                                //Content modified so update SearchItem and delete item's Words Collection
                                searchItem.SearchItemId = indexedItem.SearchItemId;
                                SearchDataStoreController.UpdateSearchItem(searchItem);
                                SearchDataStoreController.DeleteSearchItemWords(searchItem.SearchItemId);

                                //re-index the content
                                AddIndexWords(searchItem.SearchItemId, searchItem, kvp.Value);
                            }
                            catch (Exception ex)
                            {
                                //Log Exception
                                Exceptions.Exceptions.LogException(ex);
                            }
                        }

                        //Remove Items from both collections
                        indexedItems.Remove(searchItem.SearchKey);
                        SearchItems.Remove(searchItem);
                    }
                    else
                    {
                        try
                        {
                            //Item doesn't exist so Add to Index
                            int indexID = SearchDataStoreController.AddSearchItem(searchItem);
                            //index the content
                            AddIndexWords(indexID, searchItem, kvp.Value);
                        }
                        catch (Exception ex)
                        {
                            //Exception is probably a duplicate key error which is probably due to bad module data
                            Exceptions.Exceptions.LogSearchException(new SearchException(ex.Message, ex, searchItem));
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// StoreSearchItems adds the Search Item to the Data Store
        /// </summary>
        /// <param name="SearchItems">A Collection of SearchItems</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        public override void StoreSearchItems(SearchItemInfoCollection SearchItems)
        {
            int i;

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

            //For now as we don't support Localized content - set the locale to the default locale. This
            //is to avoid the error in GetDefaultLanguageByModule which artificially limits the number
            //of modules that can be indexed.  This will need to be addressed when we support localized content.
            Hashtable Modules = new Hashtable();

            for (i = 0; i <= SearchItems.Count - 1; i++)
            {
                if (!Modules.ContainsKey(SearchItems[i].ModuleId.ToString()))
                {
                    Modules.Add(SearchItems[i].ModuleId.ToString(), "en-US");
                }
            }

            //Process the SearchItems by Module to reduce Database hits
            IDictionaryEnumerator moduleEnumerator = Modules.GetEnumerator();

            while (moduleEnumerator.MoveNext())
            {
                int    ModuleId = Convert.ToInt32(moduleEnumerator.Key);
                string Language = Convert.ToString(moduleEnumerator.Value);

                //Get the Indexed Items that are in the Database for this Module
                SearchItemInfoCollection IndexedItems = GetSearchItems(ModuleId);
                //Get the Module's SearchItems to compare
                SearchItemInfoCollection ModuleItems = SearchItems.ModuleItems(ModuleId);

                //As we will be potentially removing items from the collection iterate backwards
                for (int iSearch = ModuleItems.Count - 1; iSearch >= 0; iSearch--)
                {
                    SearchItemInfo SearchItem = ModuleItems[iSearch];
                    bool           ItemFound  = false;

                    //Iterate through Indexed Items
                    foreach (SearchItemInfo IndexedItem in IndexedItems)
                    {
                        //Compare the SearchKeys
                        if (SearchItem.SearchKey == IndexedItem.SearchKey)
                        {
                            //Item exists so compare Dates to see if modified
                            if (IndexedItem.PubDate < SearchItem.PubDate)
                            {
                                try
                                {
                                    //Content modified so update SearchItem and delete item's Words Collection
                                    SearchItem.SearchItemId = IndexedItem.SearchItemId;
                                    SearchDataStoreController.UpdateSearchItem(SearchItem);
                                    SearchDataStoreController.DeleteSearchItemWords(SearchItem.SearchItemId);

                                    // re-index the content
                                    AddIndexWords(SearchItem.SearchItemId, SearchItem, Language);
                                }
                                catch (Exception ex)
                                {
                                    //Log Exception
                                    Exceptions.Exceptions.LogException(ex);
                                }
                            }

                            //Remove Items from both collections
                            IndexedItems.Remove(IndexedItem);
                            ModuleItems.Remove(SearchItem);

                            //Exit the Iteration as Match found
                            ItemFound = true;
                            break;
                        }
                    }

                    if (!ItemFound)
                    {
                        try
                        {
                            //Item doesn't exist so Add to Index
                            int IndexID = SearchDataStoreController.AddSearchItem(SearchItem);
                            // index the content
                            AddIndexWords(IndexID, SearchItem, Language);
                        }
                        catch (Exception)
                        {
                            //Log Exception
                            //LogException(ex) ** this exception has been suppressed because it fills up the event log with duplicate key errors - we still need to understand what causes it though
                        }
                    }
                }

                //As we removed the IndexedItems as we matched them the remaining items are deleted Items
                //ie they have been indexed but are no longer present
                Hashtable ht = new Hashtable();
                foreach (SearchItemInfo IndexedItem in IndexedItems)
                {
                    try
                    {
                        //dedupe
                        if (ht[IndexedItem.SearchItemId] == null)
                        {
                            SearchDataStoreController.DeleteSearchItem(IndexedItem.SearchItemId);
                            ht.Add(IndexedItem.SearchItemId, 0);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Log Exception
                        Exceptions.Exceptions.LogException(ex);
                    }
                }
            }
        }
        /// <summary>
        /// StoreSearchItems adds the Search Item to the Data Store
        /// </summary>
        /// <param name="SearchItems">A Collection of SearchItems</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        /// </history>
        public override void StoreSearchItems( SearchItemInfoCollection SearchItems )
        {
            int i;

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

            //For now as we don't support Localized content - set the locale to the default locale. This
            //is to avoid the error in GetDefaultLanguageByModule which artificially limits the number
            //of modules that can be indexed.  This will need to be addressed when we support localized content.
            Hashtable Modules = new Hashtable();
            for( i = 0; i <= SearchItems.Count - 1; i++ )
            {
                if( ! Modules.ContainsKey( SearchItems[i].ModuleId.ToString() ) )
                {
                    Modules.Add( SearchItems[i].ModuleId.ToString(), "en-US" );
                }
            }

            //Process the SearchItems by Module to reduce Database hits
            IDictionaryEnumerator moduleEnumerator = Modules.GetEnumerator();
            while( moduleEnumerator.MoveNext() )
            {
                int ModuleId = Convert.ToInt32( moduleEnumerator.Key );
                string Language = Convert.ToString( moduleEnumerator.Value );

                //Get the Indexed Items that are in the Database for this Module
                SearchItemInfoCollection IndexedItems = GetSearchItems( ModuleId );
                //Get the Module's SearchItems to compare
                SearchItemInfoCollection ModuleItems = SearchItems.ModuleItems( ModuleId );

                //As we will be potentially removing items from the collection iterate backwards
                for( int iSearch = ModuleItems.Count - 1; iSearch >= 0; iSearch-- )
                {

                    SearchItemInfo SearchItem = ModuleItems[iSearch];
                    bool ItemFound = false;

                    //Iterate through Indexed Items
                    foreach( SearchItemInfo IndexedItem in IndexedItems )
                    {
                        //Compare the SearchKeys
                        if( SearchItem.SearchKey == IndexedItem.SearchKey )
                        {
                            //Item exists so compare Dates to see if modified
                            if( IndexedItem.PubDate < SearchItem.PubDate )
                            {
                                try
                                {
                                    //Content modified so update SearchItem and delete item's Words Collection
                                    SearchItem.SearchItemId = IndexedItem.SearchItemId;
                                    SearchDataStoreController.UpdateSearchItem( SearchItem );
                                    SearchDataStoreController.DeleteSearchItemWords( SearchItem.SearchItemId );

                                    // re-index the content
                                    AddIndexWords( SearchItem.SearchItemId, SearchItem, Language );
                                }
                                catch( Exception ex )
                                {
                                    //Log Exception
                                    Exceptions.Exceptions.LogException( ex );
                                }
                            }

                            //Remove Items from both collections
                            IndexedItems.Remove( IndexedItem );
                            ModuleItems.Remove( SearchItem );

                            //Exit the Iteration as Match found
                            ItemFound = true;
                            break;
                        }
                    }

                    if( ! ItemFound )
                    {
                        try
                        {
                            //Item doesn't exist so Add to Index
                            int IndexID = SearchDataStoreController.AddSearchItem( SearchItem );
                            // index the content
                            AddIndexWords( IndexID, SearchItem, Language );
                        }
                        catch( Exception )
                        {
                            //Log Exception
                            //LogException(ex) ** this exception has been suppressed because it fills up the event log with duplicate key errors - we still need to understand what causes it though
                        }
                    }
                }

                //As we removed the IndexedItems as we matched them the remaining items are deleted Items
                //ie they have been indexed but are no longer present
                Hashtable ht = new Hashtable();
                foreach( SearchItemInfo IndexedItem in IndexedItems )
                {
                    try
                    {
                        //dedupe
                        if( ht[IndexedItem.SearchItemId] == null )
                        {
                            SearchDataStoreController.DeleteSearchItem( IndexedItem.SearchItemId );
                            ht.Add( IndexedItem.SearchItemId, 0 );
                        }
                    }
                    catch( Exception ex )
                    {
                        //Log Exception
                        Exceptions.Exceptions.LogException( ex );
                    }
                }
            }
        }
Beispiel #6
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// StoreSearchItems adds the Search Item to the Data Store
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="SearchItems">A Collection of SearchItems</param>
        /// <history>
        ///		[cnurse]	11/15/2004	documented
        ///     [vnguyen]   09/07/2010  Modified: Added a date comparison for LastModifiedDate on the Tab
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void StoreSearchItems(SearchItemInfoCollection SearchItems)
        {
            //For now as we don't support Localized content - set the locale to the default locale. This
            //is to avoid the error in GetDefaultLanguageByModule which artificially limits the number
            //of modules that can be indexed.  This will need to be addressed when we support localized content.
            var Modules = new Dictionary<int, string>();
            foreach (SearchItemInfo item in SearchItems)
            {
                if (!Modules.ContainsKey(item.ModuleId))
                {
                    Modules.Add(item.ModuleId, "en-US");
                }
            }

            var objTabs = new TabController();
            var objModule = new ModuleInfo();
            var objTab = new TabInfo();

            SearchItemInfo searchItem;
            Dictionary<string, SearchItemInfo> indexedItems;
            SearchItemInfoCollection moduleItems;

            //Process the SearchItems by Module to reduce Database hits
            foreach (KeyValuePair<int, string> kvp in Modules)
            {
                indexedItems = SearchDataStoreController.GetSearchItems(kvp.Key);

                //Get the Module's SearchItems to compare
                moduleItems = SearchItems.ModuleItems(kvp.Key);
                
                //remove deleted indexed items
                var moduleItemList = moduleItems.Cast<SearchItemInfo>().ToList();
                indexedItems.Values
                    .Where(i => moduleItemList.All(s => s.SearchKey != i.SearchKey))
                    .ToList().ForEach(i => SearchDataStoreController.DeleteSearchItem(i.SearchItemId));

                //As we will be potentially removing items from the collection iterate backwards
                for (int iSearch = moduleItems.Count - 1; iSearch >= 0; iSearch += -1)
                {
                    searchItem = moduleItems[iSearch];

                    //Get item from Indexed collection
                    SearchItemInfo indexedItem = null;
                    if (indexedItems.TryGetValue(searchItem.SearchKey, out indexedItem))
                    {
                        //Get the tab where the search item resides -- used in date comparison
                        objModule = new ModuleController().GetModule(searchItem.ModuleId);
                        objTab = objTabs.GetTab(searchItem.TabId, objModule.PortalID, false);

                        //Item exists so compare Dates to see if modified
                        if (indexedItem.PubDate < searchItem.PubDate || indexedItem.PubDate < objModule.LastModifiedOnDate || indexedItem.PubDate < objTab.LastModifiedOnDate)
                        {
                            try
                            {
                                if (searchItem.PubDate < objModule.LastModifiedOnDate)
                                {
                                    searchItem.PubDate = objModule.LastModifiedOnDate;
                                }
                                if (searchItem.PubDate < objTab.LastModifiedOnDate)
                                {
                                    searchItem.PubDate = objTab.LastModifiedOnDate;
                                }

                                
                                //Content modified so update SearchItem and delete item's Words Collection
                                searchItem.SearchItemId = indexedItem.SearchItemId;
                                SearchDataStoreController.UpdateSearchItem(searchItem);
                                SearchDataStoreController.DeleteSearchItemWords(searchItem.SearchItemId);

                                //re-index the content
                                AddIndexWords(searchItem.SearchItemId, searchItem, kvp.Value);
                            }
                            catch (Exception ex)
                            {
								//Log Exception
                                Exceptions.Exceptions.LogException(ex);
                            }
                        }
						
                        //Remove Items from both collections
                        indexedItems.Remove(searchItem.SearchKey);
                        SearchItems.Remove(searchItem);
                    }
                    else
                    {
                        try
                        {
							//Item doesn't exist so Add to Index
                            int indexID = SearchDataStoreController.AddSearchItem(searchItem);
							//index the content
                            AddIndexWords(indexID, searchItem, kvp.Value);
                        }
                        catch (Exception ex)
                        {
                            //Exception is probably a duplicate key error which is probably due to bad module data
                            Exceptions.Exceptions.LogSearchException(new SearchException(ex.Message, ex, searchItem));
                        }
                    }
                }
            }
        }