/// <summary> /// Recursively traverse the database to add all tables as Document objects into the index /// </summary> /// <param name="itm">Current node in database to add Document objects for</param> /// <param name="writer">IndexWriter object</param> /// <param name="path">Path within the database for this node</param> private void TraverseDatabase(PCAxis.Web.Core.Enums.DatabaseType dbType, PxMenuItem itm, IndexWriter writer, string path) { PCAxis.Menu.Item newItem; PCAxis.Menu.PxMenuBase db = _menuMethod(_database, itm.ID, _language, out newItem); PxMenuItem m = (PxMenuItem)newItem; if (m == null) { return; } foreach (var item in m.SubItems) { if (item is PxMenuItem) { TraverseDatabase(dbType, item as PxMenuItem, writer, path + "/" + item.ID.Selection); } else if (item is TableLink) { IndexTable(dbType, (TableLink)item, path, writer); } } }
/// <summary> /// Create index /// </summary> public bool CreateIndex() { try { using (IndexWriter writer = CreateIndexWriter(true)) { if (writer == null) { return(false); } // Set field length to max to be able to handle very large valuesets writer.SetMaxFieldLength(int.MaxValue); ItemSelection node = null; //if (_database == "ssd") //{ // //nodeId = "START__KU"; // node = new ItemSelection(); // //node.Menu = "START"; // //node.Selection = "KU"; // node.Menu = "HA0201"; // node.Selection = "HA0201B"; //} // Get database PCAxis.Menu.Item itm; PCAxis.Menu.PxMenuBase db = _menuMethod(_database, node, _language, out itm); if (db == null) { _logger.Error("Failed to access database '" + _database + "'. Creation of search index aborted."); writer.Rollback(); _logger.Error("Rollback of '" + _database + "' done"); return(false); } PCAxis.Web.Core.Enums.DatabaseType dbType; if (db is PCAxis.Menu.Implementations.XmlMenu) { dbType = DatabaseType.PX; } else { dbType = DatabaseType.CNMM; } if (db.RootItem != null) { foreach (var item in db.RootItem.SubItems) { if (item is PCAxis.Menu.PxMenuItem) { TraverseDatabase(dbType, item as PxMenuItem, writer, "/" + item.ID.Selection); } else if (item is PCAxis.Menu.TableLink) { IndexTable(dbType, (TableLink)item, "/" + item.ID.Menu, writer); } } } writer.Optimize(); } return(true); } catch (Exception e) { _logger.Error(e); throw; } }
/// <summary> /// Create instance with data /// </summary> /// <param name="parentMenu">The parent PxMenu for this item</param> /// <param name="text">Presentation text</param> /// <param name="textShort">Short presentation text</param> /// <param name="sortCode">Sort code</param> /// <param name="menu">Menu code</param> /// <param name="selection">Selection code</param> /// <param name="description">Description of the item</param> public PxMenuItem(PxMenuBase parentMenu, string text, string textShort, string sortCode, string menu, string selection, string description) : base(text, textShort, sortCode, menu, selection, description) { this.parentMenu = parentMenu; }
/// <summary> /// Update index for the tables specified in the list. /// Partial update of search index is only possible for CNMM databases. /// </summary> /// <param name="tableList">List with TableUpdate objects that represents the tables that should be updated in the index</param> public bool UpdateIndex(List <TableUpdate> tableList) { ItemSelection node = null; PCAxis.Menu.Item currentTable; string[] pathParts; string title; string menu, selection; DateTime published = DateTime.MinValue; bool doUpdate; using (IndexWriter writer = CreateIndexWriter(false)) { try { if (writer == null) { return(false); } foreach (TableUpdate table in tableList) { doUpdate = false; PXModel model = PxModelManager.Current.GetModel(DatabaseType.CNMM, _database, _language, table.Id); // Get default value for title title = model.Meta.Title; // Get table title from _menuMethod // table.Path is supposed to have the following format: path/path/path // Example: BE/BE0101/BE0101A pathParts = table.Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (pathParts.Length > 1) { menu = pathParts[pathParts.Length - 1]; selection = table.Id; node = new ItemSelection(menu, selection); PCAxis.Menu.PxMenuBase db = _menuMethod(_database, node, _language, out currentTable); if (currentTable != null) { if (currentTable is TableLink) { doUpdate = true; // Get table title from the menu method if (!string.IsNullOrEmpty(currentTable.Text)) { title = currentTable.Text; } if (((TableLink)currentTable).Published != null) { published = (DateTime)((TableLink)currentTable).Published; } } } } if (doUpdate) { UpdatePaxiomDocument(writer, _database, table.Id, table.Path, table.Id, title, published, model.Meta); _logger.Info("Search index " + _database + " - " + _language + " updated table " + table.Id); } } writer.Optimize(); } catch (Exception e) { writer.Rollback(); _logger.Error(e); throw; } } return(true); }
/// <summary> /// Create instance without data /// </summary> public PxMenuItem(PxMenuBase parentMenu) : this(parentMenu, "", "", "", "", "", "") { }