Example #1
0
        /// <summary>
        /// Selects single node from passed XmlNode and returns corresponding SearchIndexStatusType, if the node is not found the given defaultvalue is returned
        /// </summary>
        /// <param name="xpath">Expression to select node containing setting value</param>
        /// <param name="selectionNode">Node to apply xpath expression on</param>
        /// <param name="defaultValue">Value to return if node is not found or not possible to parse as a SearchIndexStatusType</param>
        public static SearchIndexStatusType GetSettingValue(string xpath, XmlNode selectionNode, SearchIndexStatusType defaultValue)
        {
            SearchIndexStatusType returnValue = defaultValue;
            XmlNode node = null;

            if (selectionNode != null)
            {
                node = selectionNode.SelectSingleNode(xpath);
            }
            if (node != null)
            {
                switch (node.InnerText)
                {
                case "Indexed":
                    returnValue = SearchIndexStatusType.Indexed;
                    break;

                case "Indexing":
                    returnValue = SearchIndexStatusType.Indexing;
                    break;

                case "NotIndexed":
                    returnValue = SearchIndexStatusType.NotIndexed;
                    break;

                case "WaitingCreate":
                    returnValue = SearchIndexStatusType.WaitingCreate;
                    break;

                case "WaitingUpdate":
                    returnValue = SearchIndexStatusType.WaitingUpdate;
                    break;

                default:
                    returnValue = SearchIndexStatusType.NotIndexed;
                    break;
                }
            }
            return(returnValue);
        }
Example #2
0
        /// <summary>
        /// Update search index
        /// </summary>
        /// <param name="database"></param>
        private static void UpdateSearchIndex(string database)
        {
            _activity = "Updating search index for the " + database + " database";

            bool success = true;

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;
            DateTime dateFrom;

            // Get start values. If something goes wrong we may need to restore these values
            SearchIndexStatusType startStatus = searchIndex.Status;
            string startUpdated = searchIndex.IndexUpdated;

            if (PxDate.IsPxDate(searchIndex.IndexUpdated))
            {
                dateFrom = PxDate.PxDateStringToDateTime(searchIndex.IndexUpdated);
            }
            else
            {
                dateFrom = DateTime.Now;
            }

            try
            {
                searchIndex.Status = SearchIndexStatusType.Indexing;
                db.Save();

                foreach (LanguageSettings lang in PXWeb.Settings.Current.General.Language.SiteLanguages)
                {
                    List <PCAxis.Search.TableUpdate> lst = searchIndex.UpdateMethod.GetUpdatedTables(dateFrom, "ssd_extern_test", lang.Name);

                    if (lst.Count > 0)
                    {
                        if (SearchManager.Current.UpdateIndex(database, lang.Name, lst))
                        {
                            _logger.Info("Successfully updated the " + database + " - " + lang.Name + " search index");
                        }
                        else
                        {
                            _logger.Error("Failed to update the " + database + " - " + lang.Name + " search index");
                            success = false;
                            return;
                        }
                    }
                }

                if (success)
                {
                    searchIndex.Status       = SearchIndexStatusType.Indexed;
                    searchIndex.IndexUpdated = DateTime.Now.ToString(PXConstant.PXDATEFORMAT);
                    _logger.Info("Search index was successfully updated for the '" + database + "' database");
                }
                else
                {
                    // Restore values...
                    searchIndex.Status       = startStatus;
                    searchIndex.IndexUpdated = startUpdated;
                    _logger.Error("Failed to update search index for the '" + database + "' database");
                }

                db.Save();
            }
            catch (Exception ex)
            {
                _logger.Error("Error when updating the search index for the '" + database + "' database : " + ex.Message);

                // Restore values...
                searchIndex.Status       = startStatus;
                searchIndex.IndexUpdated = startUpdated;
                db.Save();
            }

            // Force reload of database settings
            db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
        }
Example #3
0
        /// <summary>
        /// Create new search index
        /// </summary>
        /// <param name="database"></param>
        private static void CreateSearchIndex(string database)
        {
            _activity = "Creating search index for the " + database + " database";

            bool success = true;

            PXWeb.DatabaseSettings    db          = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
            PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex;

            // Get start values. If something goes wrong we may need to restore these values
            SearchIndexStatusType startStatus = searchIndex.Status;
            string startUpdated = searchIndex.IndexUpdated;

            searchIndex.Status = SearchIndexStatusType.Indexing;
            db.Save();

            try
            {
                foreach (LanguageSettings lang in PXWeb.Settings.Current.General.Language.SiteLanguages)
                {
                    DatabaseInfo dbi = PXWeb.Settings.Current.General.Databases.GetDatabase(database);
                    if (dbi.HasLanguage(lang.Name))
                    {
                        if (SearchManager.Current.CreateIndex(database, lang.Name))
                        {
                            _logger.Info("Successfully created the " + database + " - " + lang.Name + " search index");
                        }
                        else
                        {
                            _logger.Error("Failed to create the " + database + " - " + lang.Name + " search index");
                            //success = false;
                            //return;
                        }
                    }
                }

                if (success)
                {
                    searchIndex.Status       = SearchIndexStatusType.Indexed;
                    searchIndex.IndexUpdated = DateTime.Now.ToString(PXConstant.PXDATEFORMAT);
                    _logger.Info("Search index was successfully created for the '" + database + "' database");
                }
                else
                {
                    // Restore values...
                    searchIndex.Status       = startStatus;
                    searchIndex.IndexUpdated = startUpdated;
                    _logger.Error("Failed to create search index for the '" + database + "' database");
                }

                db.Save();
            }
            catch (Exception ex)
            {
                _logger.Error("Error when creating search index for the '" + database + "' database : " + ex.Message);
                _logger.Error("Details", ex);

                // Restore values...
                searchIndex.Status       = startStatus;
                searchIndex.IndexUpdated = startUpdated;
                db.Save();
            }

            // Force reload of database settings
            db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database);
        }