Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IndexCommit.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 using Lucene.Net.Store;
21 using Directory = Lucene.Net.Store.Directory;
22 
23 namespace Lucene.Net.Index
24 {
25 
26  /// <summary> <p/>Expert: represents a single commit into an index as seen by the
27  /// <see cref="IndexDeletionPolicy" /> or <see cref="IndexReader" />.<p/>
28  ///
29  /// <p/> Changes to the content of an index are made visible
30  /// only after the writer who made that change commits by
31  /// writing a new segments file
32  /// (<c>segments_N</c>). This point in time, when the
33  /// action of writing of a new segments file to the directory
34  /// is completed, is an index commit.<p/>
35  ///
36  /// <p/>Each index commit point has a unique segments file
37  /// associated with it. The segments file associated with a
38  /// later index commit point would have a larger N.<p/>
39  ///
40  /// <p/><b>WARNING</b>: This API is a new and experimental and
41  /// may suddenly change. <p/>
42  /// </summary>
43 
44  public abstract class IndexCommit
45  {
46  /// <summary> Get the segments file (<c>segments_N</c>) associated
47  /// with this commit point.
48  /// </summary>
49  public abstract string SegmentsFileName { get; }
50 
51  /// <summary> Returns all index files referenced by this commit point.</summary>
52  public abstract ICollection<string> FileNames { get; }
53 
54  /// <summary> Returns the <see cref="Store.Directory" /> for the index.</summary>
55  public abstract Directory Directory { get; }
56 
57  /// <summary> Delete this commit point. This only applies when using
58  /// the commit point in the context of IndexWriter's
59  /// IndexDeletionPolicy.
60  /// <p/>
61  /// Upon calling this, the writer is notified that this commit
62  /// point should be deleted.
63  /// <p/>
64  /// Decision that a commit-point should be deleted is taken by the <see cref="IndexDeletionPolicy" /> in effect
65  /// and therefore this should only be called by its <see cref="IndexDeletionPolicy.OnInit{T}(IList{T})" /> or
66  /// <see cref="IndexDeletionPolicy.OnCommit{T}(IList{T})" /> methods.
67  /// </summary>
68  public abstract void Delete();
69 
70  public abstract bool IsDeleted { get; }
71 
72  /// <summary> Returns true if this commit is an optimized index.</summary>
73  public abstract bool IsOptimized { get; }
74 
75  /// <summary> Two IndexCommits are equal if both their Directory and versions are equal.</summary>
76  public override bool Equals(System.Object other)
77  {
78  if (other is IndexCommit)
79  {
80  IndexCommit otherCommit = (IndexCommit) other;
81  return otherCommit.Directory.Equals(Directory) && otherCommit.Version == Version;
82  }
83  else
84  return false;
85  }
86 
87  public override int GetHashCode()
88  {
89  return (int)(Directory.GetHashCode() + Version);
90  }
91 
92  /// <summary>Returns the version for this IndexCommit. This is the
93  /// same value that <see cref="IndexReader.Version" /> would
94  /// return if it were opened on this commit.
95  /// </summary>
96  public abstract long Version { get; }
97 
98  /// <summary>Returns the generation (the _N in segments_N) for this
99  /// IndexCommit
100  /// </summary>
101  public abstract long Generation { get; }
102 
103  /// <summary>Convenience method that returns the last modified time
104  /// of the segments_N file corresponding to this index
105  /// commit, equivalent to
106  /// getDirectory().fileModified(getSegmentsFileName()).
107  /// </summary>
108  public virtual long Timestamp
109  {
110  get { return Directory.FileModified(SegmentsFileName); }
111  }
112 
113  /// <summary>Returns userData, previously passed to
114  /// <see cref="IndexWriter.Commit(System.Collections.Generic.IDictionary{string, string})" />
115  /// for this commit. IDictionary is String -> String.
116  /// </summary>
117  public abstract IDictionary<string, string> UserData { get; }
118  }
119 }