Lucene.Net.Index.IndexReader.ListCommits C# (CSharp) Method

ListCommits() public static method

Returns all commit points that exist in the Directory. Normally, because the default is KeepOnlyLastCommitDeletionPolicy , there would be only one commit point. But if you're using a custom IndexDeletionPolicy then there could be many commits. Once you have a given commit, you can open a reader on it by calling IndexReader.Open(IndexCommit,bool) There must be at least one commit in the Directory, else this method throws System.IO.IOException. Note that if a commit is in progress while this method is running, that commit may or may not be returned array.
public static ListCommits ( Directory dir ) : System.Collections.Generic.ICollection
dir Directory
return System.Collections.Generic.ICollection
		public static System.Collections.Generic.ICollection<IndexCommit> ListCommits(Directory dir)
		{
			return DirectoryReader.ListCommits(dir);
		}

Usage Example

示例#1
0
        //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();
        }
All Usage Examples Of Lucene.Net.Index.IndexReader::ListCommits