Esempio n. 1
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));
                        }
                    }
                }
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }