/// <summary> /// Create search index for the selected database. One index per site language will be created. /// </summary> /// <param name="database"></param> private void CreateIndex(string database) { if (string.IsNullOrEmpty(database)) { return; } PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database); PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex; // Check that the status has not been changed by another system before updating it if (searchIndex.Status != SearchIndexStatusType.Indexing) { searchIndex.Status = SearchIndexStatusType.WaitingCreate; db.Save(); if (PXWeb.Settings.Current.Features.General.BackgroundWorkerEnabled) { // Wake up the background worker if it is asleep BackgroundWorker.PxWebBackgroundWorker.WakeUp(); } } ReadSettings(); }
public HttpResponseMessage RebuildMenu(string database, bool languageDependent = true, string sortBy = "Title", bool buildSearchIndex = true) { var statusCode = HttpStatusCode.Created; List <DatabaseMessage> result = null; _logger.Info("RebuildMenu - started"); try { string path; path = System.Web.HttpContext.Current.Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath); path = System.IO.Path.Combine(path, database); result = AdminTool.GenerateDatabase(path, languageDependent, sortBy); // Clear all caches PXWeb.Management.PxContext.CacheController.Clear(); //Force that databases are read again PXWeb.DatabasesSettings databases = (PXWeb.DatabasesSettings)PXWeb.Settings.Current.General.Databases; databases.ResetDatabases(); if (PXWeb.Settings.Current.Features.General.SearchEnabled && buildSearchIndex) { PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(database); PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex; // Check that the status has not been changed by another system before updating it if (searchIndex.Status != SearchIndexStatusType.Indexing) { searchIndex.Status = SearchIndexStatusType.WaitingCreate; db.Save(); BackgroundWorker.PxWebBackgroundWorker.HandleSearchIndex(database); } } _logger.Info("RebuildMenu - finished without error"); } catch (Exception e) { statusCode = HttpStatusCode.InternalServerError; _logger.Error(e.Message); } return(Request.CreateResponse(statusCode, result)); }
protected void btnGenerate_Click(object sender, EventArgs e) { string path; path = Server.MapPath(Settings.Current.General.Paths.PxDatabasesPath); path = System.IO.Path.Combine(path, cboSelectDb.SelectedValue); bool langDependent = false; if (string.Compare(cboLanguageDependent.SelectedValue, "true", StringComparison.InvariantCultureIgnoreCase) == 0) { langDependent = true; } // Clear all caches PXWeb.Management.PxContext.CacheController.Clear(); grdResult.DataSource = AdminTool.GenerateDatabase(path, langDependent, cboSortOrder.SelectedValue); grdResult.DataBind(); //Force that databases are read again PXWeb.DatabasesSettings databases = (PXWeb.DatabasesSettings)PXWeb.Settings.Current.General.Databases; databases.ResetDatabases(); if (PXWeb.Settings.Current.Features.General.SearchEnabled) { if (chkCreateIndex.Checked) { PXWeb.DatabaseSettings db = (PXWeb.DatabaseSettings)PXWeb.Settings.Current.GetDatabase(cboSelectDb.SelectedValue); PXWeb.SearchIndexSettings searchIndex = (PXWeb.SearchIndexSettings)db.SearchIndex; // Check that the status has not been changed by another system before updating it if (searchIndex.Status != SearchIndexStatusType.Indexing) { searchIndex.Status = SearchIndexStatusType.WaitingCreate; db.Save(); } InfoBox.Visible = true; } } }
/// <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); }
/// <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); }