//Rolls back index to a chosen ID private void RollBackLast(int id) { // System.out.println("Attempting to rollback to "+id); System.String ids = "-" + id; IndexCommit last = null; System.Collections.ICollection commits = IndexReader.ListCommits(dir); for (System.Collections.IEnumerator iterator = commits.GetEnumerator(); iterator.MoveNext();) { IndexCommit commit = (IndexCommit)iterator.Current; System.Collections.Generic.IDictionary <string, string> ud = commit.GetUserData(); if (ud.Count > 0) { if (((System.String)ud["index"]).EndsWith(ids)) { last = commit; } } } if (last == null) { throw new System.SystemException("Couldn't find commit point " + id); } IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), new RollbackDeletionPolicy(this, id), MaxFieldLength.UNLIMITED, last); System.Collections.Generic.IDictionary <string, string> data = new System.Collections.Generic.Dictionary <string, string>(); data["index"] = "Rolled back to 1-" + id; w.Commit(data); w.Close(); }
public override IDictionary <string, string> GetUserData() { return(cp.GetUserData()); }
public virtual void OnInit(System.Collections.IList commits) { for (System.Collections.IEnumerator iterator = commits.GetEnumerator(); iterator.MoveNext();) { IndexCommit commit = (IndexCommit)iterator.Current; System.Collections.Generic.IDictionary <string, string> userData = commit.GetUserData(); if (userData.Count > 0) { // Label for a commit point is "Records 1-30" // This code reads the last id ("30" in this example) and deletes it // if it is after the desired rollback point System.String x = (System.String)userData["index"]; System.String lastVal = x.Substring(x.LastIndexOf("-") + 1); int last = System.Int32.Parse(lastVal); if (last > rollbackPoint) { /* * System.out.print("\tRolling back commit point:" + * " UserData="+commit.getUserData() +") ("+(commits.size()-1)+" commit points left) files="); * Collection files = commit.getFileNames(); * for (Iterator iterator2 = files.iterator(); iterator2.hasNext();) { * System.out.print(" "+iterator2.next()); * } * System.out.println(); */ commit.Delete(); } } } }
public override System.Collections.Generic.IDictionary <string, string> GetUserData() { return(cp.GetUserData()); }