/// <summary> /// runIndex /// </summary> /// <param name="thisText">The text to be indexed</param> /// <param name="ctx">context</param> /// <param name="trxName">trx if needed</param> /// <param name="tableID">id</param> /// <param name="recordID">id</param> /// <param name="CMWebProjectID">id</param> /// <param name="sourceUpdated">update date of source</param> /// <returns>true if successfully indexed</returns> public static bool RunIndex(String thisText, Ctx ctx, Trx trxName, int tableID, int recordID, int CMWebProjectID, DateTime?sourceUpdated) { if (thisText != null) { //Hashtable keyHash = indexString(thisText); System.Collections.IDictionary keyHash = IndexString(thisText); for (System.Collections.IEnumerator e = (System.Collections.IEnumerator)keyHash.Keys; e.MoveNext();) { String name = (String)e.Current; String value = (String)keyHash[name];//.get(name); MIndex thisIndex = new MIndex(ctx, 0, trxName); thisIndex.SetAD_Table_ID(tableID); if (CMWebProjectID > 0) { thisIndex.SetCM_WebProject_ID(CMWebProjectID); } thisIndex.SetExcerpt(value); thisIndex.SetKeyword(name); thisIndex.SetRecord_ID(recordID); thisIndex.SetSourceUpdated(sourceUpdated); thisIndex.Save(); } return(true); } else { return(false); } }
/// <summary> /// reIndex Document /// </summary> /// <param name="runCleanUp">clean old records</param> /// <param name="toBeIndexed">Array of Strings to be indexed</param> /// <param name="ctx">context</param> /// <param name="AD_Client_ID">id</param> /// <param name="AD_Table_ID">id</param> /// <param name="Record_ID">id</param> /// <param name="CM_WebProject_ID">webproject</param> /// <param name="lastUpdated">date of last update</param> public static void ReIndex(bool runCleanUp, String[] toBeIndexed, Ctx ctx, int AD_Client_ID, int AD_Table_ID, int Record_ID, int CM_WebProject_ID, DateTime?lastUpdated) { Trx trx = Trx.Get("ReIndex_" + AD_Table_ID + "_" + Record_ID); try { if (!runCleanUp) { MIndex.CleanUp(trx, AD_Client_ID, AD_Table_ID, Record_ID); } for (int i = 0; i < toBeIndexed.Length; i++) { MIndex.RunIndex(toBeIndexed[i], ctx, trx, AD_Table_ID, Record_ID, CM_WebProject_ID, lastUpdated); } trx.Commit(); //DataBase.DB.Commit (true, trx); } catch { try { //DataBase.DB.Rollback(true, trx); trx.Rollback(); } catch { } } }
} // afterSave public void ReIndex(bool newRecord) { String[] toBeIndexed = new String[2]; toBeIndexed[0] = this.GetName(); toBeIndexed[1] = this.GetDescription(); MIndex.ReIndex(newRecord, toBeIndexed, GetCtx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID(), GetCM_WebProject_ID(), this.GetUpdated()); }
} // afterDelete /// <summary> /// reIndex /// </summary> /// <param name="newRecord">new record</param> public void ReIndex(bool newRecord) { if (IsIndexed()) { String [] toBeIndexed = new String[8]; toBeIndexed[0] = this.GetName(); toBeIndexed[1] = this.GetDescription(); toBeIndexed[2] = this.GetRelativeURL(); toBeIndexed[3] = this.GetMeta_Author(); toBeIndexed[4] = this.GetMeta_Copyright(); toBeIndexed[5] = this.GetMeta_Description(); toBeIndexed[6] = this.GetMeta_Keywords(); toBeIndexed[7] = this.GetMeta_Publisher(); MIndex.ReIndex(newRecord, toBeIndexed, GetCtx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID(), GetCM_WebProject_ID(), this.GetUpdated()); MContainerElement[] theseElements = GetAllElements(); if (theseElements != null) { for (int i = 0; i < theseElements.Length; i++) { theseElements[i].ReIndex(false); } } } if (!IsIndexed() && !newRecord) { MIndex.CleanUp(Get_Trx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID()); } } // reIndex
protected override bool BeforeDelete() { // Clean own index MIndex.CleanUp(Get_Trx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID()); // Clean ElementIndex MContainerElement[] theseElements = GetAllElements(); if (theseElements != null) { for (int i = 0; i < theseElements.Length; i++) { theseElements[i].Delete(false); } } // StringBuilder sb = new StringBuilder("DELETE FROM AD_TreeNodeCMC ") .Append(" WHERE Node_ID=").Append(Get_ID()).Append( " AND AD_Tree_ID=").Append(GetAD_Tree_ID()); int no = DataBase.DB.ExecuteQuery(sb.ToString(), null, Get_TrxName()); if (no > 0) { log.Fine("#" + no + " - TreeType=CMC"); } else { log.Warning("#" + no + " - TreeType=CMC"); } return(no > 0); }
/// <summary> /// Set Keyword & standardize /// </summary> /// <param name="Keyword">key</param> public new void SetKeyword(String Keyword) { String kw = MIndex.StandardizeKeyword(Keyword); if (kw == null) { kw = "?"; } base.SetKeyword(kw); } // setKeyword
/// <summary> /// After Save. /// </summary> /// <param name="newRecord">new</param> /// <param name="success">success</param> /// <returns>true if inserted</returns> protected override bool AfterSave(bool newRecord, bool success) { if (!success) { return(success); } if (!newRecord) { MIndex.CleanUp(Get_TrxName(), GetAD_Client_ID(), Get_Table_ID(), Get_ID()); } ReIndex(newRecord); return(success); } // afterSave
} // afterSave /// <summary> /// reIndex /// </summary> /// <param name="newRecord">new record</param> public void ReIndex(bool newRecord) { int CMWebProjectID = 0; if (GetNewsChannel() != null) { CMWebProjectID = GetNewsChannel().GetCM_WebProject_ID(); } String [] toBeIndexed = new String[4]; toBeIndexed[0] = this.GetAuthor(); toBeIndexed[1] = this.GetDescription(); toBeIndexed[2] = this.GetTitle(); toBeIndexed[3] = this.GetContentHTML(); MIndex.ReIndex(newRecord, toBeIndexed, GetCtx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID(), CMWebProjectID, this.GetUpdated()); } // reIndex
} // afterSave /// <summary> /// reIndex /// </summary> /// <param name="newRecord">new record</param> public void ReIndex(bool newRecord) { if (GetParent().IsIndexed()) { int CMWebProjectID = 0; if (GetParent() != null) { CMWebProjectID = GetParent().GetCM_WebProject_ID(); } String [] toBeIndexed = new String[3]; toBeIndexed[0] = this.GetName(); toBeIndexed[1] = this.GetDescription(); toBeIndexed[2] = this.GetContentHTML(); MIndex.ReIndex(newRecord, toBeIndexed, GetCtx(), GetAD_Client_ID(), Get_Table_ID(), Get_ID(), CMWebProjectID, this.GetUpdated()); } if (!GetParent().IsIndexed() && !newRecord) { MIndex.CleanUp(Get_TrxName(), GetAD_Client_ID(), Get_Table_ID(), Get_ID()); } } // reIndex
private static VLogger _log = VLogger.GetVLogger(typeof(MIndex).FullName); //.class); public static MIndex[] GetResults(String query, Ctx ctx, Trx trxName) { String sql = "SELECT * FROM K_Index WHERE K_Index_ID IN (" + "SELECT MAX(K_Index_ID) FROM K_Index WHERE " + "Keyword LIKE @param GROUP BY AD_Table_ID, Record_ID)"; System.Collections.Generic.Dictionary <int, MIndex> tTable = new System.Collections.Generic.Dictionary <int, MIndex>(); SqlParameter[] param = new SqlParameter[1]; IDataReader idr = null; try { // First lookup full word //pstmt = DataBase.prepareStatement (sql, trxName); //pstmt.setString (1, query.toUpperCase ()); param[0] = new SqlParameter("@param", query.ToUpper()); idr = DataBase.DB.ExecuteReader(sql, param, trxName); while (idr.Read()) { MIndex tIndex = new MIndex(ctx, idr, trxName); tTable.Add(tIndex.Get_ID(), tIndex); } idr.Close(); // Second lookup with appended % //pstmt = DataBase.prepareStatement (sql, trxName); //pstmt.setString (1, query.toUpperCase () + "%"); param[0] = new SqlParameter("@param", query.ToUpper() + "%"); idr = DataBase.DB.ExecuteReader(sql, param, trxName); while (idr.Read()) { MIndex tIndex = new MIndex(ctx, idr, trxName); if (!tTable.ContainsKey(tIndex.Get_ID())) { tTable.Add(tIndex.Get_ID(), tIndex); } } idr.Close(); // Third lookup with prefix% and appended % //pstmt = DataBase.prepareStatement (sql, trxName); //pstmt.setString (1, "%" + query.toUpperCase () + "%"); param[0] = new SqlParameter("@param", "%" + query.ToUpper() + "%"); idr = DataBase.DB.ExecuteReader(sql, param, trxName); while (idr.Read()) { MIndex tIndex = new MIndex(ctx, idr, trxName); if (!tTable.ContainsKey(tIndex.Get_ID())) { tTable.Add(tIndex.Get_ID(), tIndex); } } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } _log.Log(Level.SEVERE, "getResults", e); } // Log the search and the number of results MIndexLog thisLog = new MIndexLog(ctx, 0, trxName); thisLog.SetIndexQuery(query); thisLog.SetIndexQueryResult(tTable.Count); thisLog.SetQuerySource(X_K_IndexLog.QUERYSOURCE_CollaborationManagement); thisLog.Save(); MIndex [] entries = new MIndex [tTable.Count]; //Enumeration E = tTable.keys (); System.Collections.IEnumerator E = tTable.Keys.GetEnumerator(); int i = 0; while (E.MoveNext()) { entries[i++] = tTable[Utility.Util.GetValueOfInt(E.Current)]; } return(entries); }